Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Version 4

Load previous messages

Copy link

The load() method of a PreviousMessageListQuery instance returns a list of BaseMessage objects. Using this method, you can retrieve previous messages in a specific channel. If you want to include the replies of the target messages in the results, change the value of properties in the PreviousMessageListQuery instance.

For group channels, you can decide whether a user can see messages sent prior to the user joining the channel. To allow new users to view the message history of the group channels they joined, you can turn on Chat history by going to Settings > Chat > Channels > Group channels on Sendbird Dashboard. If this option is turned off, new users can't see messages sent prior to joining the group channel. The table below shows a list of parameters in PreviousMessageListQuery.

const params: PreviousMessageListQueryParams = {
    limit: LIMIT,
    reverse: REVERSE,
    messageTypeFilter: MESSAGE_TYPE_FILTER,
    replyType: REPLY_TYPE,
    includeThreadInfo: INCLUDE_THREAD_INFO,
    includeParentMessageInfo: INCLUDE_PARENT_MESSAGE_INFO,
const query: PreviousMessageListQuery = channel.createPreviousMessageListQuery(params);

const messages = await query.load();