Skip to main content

Retrieve Chatroom History Messages

Enable the Service​

To use the Retrieve Chatroom Remote History feature, you need to enable the Cloud Storage for Chatroom Messages service. To enable this service, please submit a ticket. Once enabled, chatroom history messages are stored in the cloud, with a default retention period of 2 months.

Retrieve Chatroom Remote History​

When you exit a chatroom, local chatroom history messages are cleared. If you need to retrieve previous history messages when rejoining the chatroom, you can call this API.

Method​


getChatRoomMessages(
targetId: string,
timestamp: number,
order: RCIMIWTimeOrder,
count: number,
callback: IRCIMIWGetChatRoomMessagesCallback
): Promise<number>;

Parameter Description​

ParameterTypeDescription
targetIdstringChatroom conversation ID
timestampnumberThe timestamp of the starting message
orderRCIMIWTimeOrderPull order 0: Descending, 1: Ascending
countnumberThe number of messages to retrieve, count must be greater than 0 and less than or equal to 50.
callbackIRCIMIWGetChatRoomMessagesCallbackCallback for the API call result.

Return Value​

Return ValueDescription
numberThe status code of the current API operation. 0 indicates a successful call, and specific results need to be implemented in the callback. Non-zero values indicate a failed API call operation, and the callback will not be triggered. For detailed errors, refer to the error codes.

Code Example​


const callback = {
onSuccess: (t: Array<RCIMIWMessage>) => {
//...
},
onError: (code: number) => {
//...
},
};
let code = await engine.getChatRoomMessages(targetId, timestamp, order, count, callback);