Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Load previous messages

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();

List of properties

Property nameTypeDescription



Specifies the number of results returned per call. Acceptable values are 1 to 100, inclusive. The recommended value for this property is 20.



Determines whether to sort the retrieved messages in reverse order. If set to true, messages are retunred from the most recent to the oldest. (Default: false)



Determines whether to include the thread information of the messages in the results when the results contain parent messages. (Default: false)



Specifies the type of message to include in the results.
- NONE (default): unthreaded messages and only the parent messages of threaded messages.
- ALL: threaded and unthreaded messages.
- ONLY_REPLY_TO_CHANNEL: unthreaded messages, parent messages of threaded messages, and replies that were sent to the channel by setting the reply_to_channel property to true.



Determines whether to include the thread information of the messages in the result. (Default: false)



Determines whether to include the information of the parent messages in the result. (Default: false)

The limit property indicates how many messages should be included in a returned list. A query instance itself does the pagination of a result set according to the value of the limit property and internally manages a token to retrieve the next page in the result set.

Each time the load() method is called, the instance retrieves a set number of messages in the next page and then updates the value of the token to complete the current call and prepare the next call.

If you create a new query instance and call the load() method, a set number of the most recently sent messages are retrieved because its token has nothing to do with the previously created instance. So we recommend that you create a single query instance and store it as a member variable for traversing through the entire message history.

Before calling the load() method again, you must receive a success callback from the server.

The following table shows all the supported parameters you can use as filters for PreviousMessageListQuery to search for messages you want to retrieve. You can use any parameters in a similar fashion with the sample code above.

List of parameters

Parameter nameTypeDescription



Messages with the specified message type. Specifying the messageTypeFilter option with a message type enables this filter. Acceptable values are ADMIN, FILE, ALL, and USER.



Messages with the specified custom message type. Specifying the customTypesFilter option with a custom message type enables this filter.



Messages that are sent by the specified users. Specifying the senderUserIdsFilter option with an array of user IDs enables this filter.