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

Load messages by timestamp or message ID

Using the getMessagesByTimestamp() method or the getMessagesByMessageId() method, you can retrieve a set number of previous and next messages on a specified timestamp or message ID in a channel.

The following code shows several types of parameters that you can configure to customize a message query by using MessageListParams. Under the MessageListParams object, you can assign values to properties such as prevResultSize, messageTypeFilter, and customTypesFilter. To retrieve messages in a channel, you need to pass the MessageListParams object as an argument to the parameter in the getMessagesByTimestamp() method. The table below shows a list of parameters in MessageListParams.

const params: MessageListParams = {
    prevResultSize: PREV_RESULT_SIZE,
    nextResultSize: NEXT_RESULT_SIZE,
    isInclusive: INCLUSIVE,
    reverse: REVERSE,
    replyType: REPLY_TYPE,
    includeThreadInfo: INCLUDE_THREAD_INFO,
    includeParentMessageInfo: INCLUDE_PARENT_MESSAGE_INFO,
        messageTypeFilter = MESSAGE_TYPE_FILTER;
        customTypesFilter = CUSTOM_TYPES_FILTER;
};

List of properties

Property nameTypeDescription

prevResultSize

int

Specifies the number of messages to retrieve that were sent before the specified timestamp.

nextResultSize

int

Specifies the number of messages to retrieve that were sent after the specified timestamp.

isInclusive

boolean

Determines whether to include the messages with the matching timestamp in the results. (Default: false)

reverse

boolean

Determines whether to sort the retrieved messages in reverse order. If false, the results are in ascending order. (Default: false)

replyType

string

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.

includeThreadInfo

boolean

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

includeParentMessageInfo

boolean

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

messageTypeFilter

MessageTypeFilter

Specifies the message type to filter the messages with the corresponding type. Acceptable values are BaseChannel.MessageTypeFilter.ALL, BaseChannel.MessageTypeFilter.USER, BaseChannel.MessageTypeFilter.FILE, and BaseChannel.MessageTypeFilter.ADMIN, or you can leave the value empty. If left empty, all message types are returned.

customTypesFilter

string

Filters messages to return only messages with the specified custom types.

includeReplies

boolean

(Deprecated) Determines whether replies are included in the results.

includeParentMessageText

boolean

(Deprecated) Determines whether to include the parent message text in the results when the messages are replies in a thread. If the type of the parent message is UserMessage, the value is a message property. If it is FileMessage, the value is the name of the uploaded file.

To retrieve a set number of previous and next messages on a specified timestamp, use the getMessagesByTimestamp() method and specify the TIMESTAMP argument in Unix milliseconds to determine the time that will serve as a reference point of a retrieval.

const messages = await channel.getMessagesByTimestamp(TIMESTAMP, params);

To retrieve a set number of previous and next messages on a specified message ID, use the getMessagesByMessageId() method and specify the MESSAGE_ID argument to determine the unique ID that will serve as a reference point of a retrieval.

const messages = await channel.getMessagesByMessageId(MESSAGE_ID, params);