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. Please ensure that the service is enabled before use. 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
Parameter | Type | Description |
---|---|---|
targetId | string | Chatroom conversation ID |
timestamp | number | The timestamp of the starting message |
order | RCIMIWTimeOrder | Pull order 0: Descending, 1: Ascending |
count | number | The number of messages to retrieve, count must be greater than 0 and less than or equal to 50. |
callback | IRCIMIWGetChatRoomMessagesCallback | Callback for the API call result. |
Return Value
Return Value | Description |
---|---|
number | The 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);