Skip to main content

Retrieve Chatroom Message History

Enable Service

To use getChatroomHistoryMessages, you need to enable the Cloud Storage for Chatroom Messages service. Please ensure the service is activated before use. Once enabled, chatroom history messages will be stored in the cloud by default for 2 months.

Retrieve Chatroom History Messages

Retrieve chatroom history messages stored on the server.

const chatRoomId = "chatroom ID";
const timestamp = 0;
const count = 10
const order = 1
RongIMLib.getChatroomHistoryMessages(chatRoomId, {
timestamp: timestamp,
count: count,
order: order
}).then(res => {
// Successfully retrieved chatroom history messages
if (res.code === 0){
console.log(res.code, res.data)
} else {
console.log(res.code, res.msg)
}
}).catch(error => {
console.log(error)
})

ParameterTypeDescription
targetIdstringChatroom ID
timestampnumberTimestamp for retrieval. 0 means fetching from the latest time, unit: milliseconds.
countnumberNumber of messages to retrieve, range 1 - 20
ordernumberRetrieval order, default is 0. 0 means ascending: retrieve messages sent before the given sentTime; 1 means descending: retrieve messages sent after the given sentTime