Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Version 4
Home
/
Chat
/
JavaScript
/
Message

Load messages by timestamp or message ID

Copy link

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
};

MessageListParams

Copy link
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 messages sent exactly on the specified timestamp or have the matching message ID. (Default: false)

reverse

boolean

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)

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.


By timestamp

Copy link

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

By Message ID

Copy link

To retrieve a set number of previous and next messages of a specific message ID in a channel, use the getMessagesByMessageId() method.

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