/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

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 of a specific timestamp or a message ID in a channel.

The following code shows several types of parameters that you can configure to customize a message query by using SbMessageListParams. Under the SbMessageListParams object, you can assign values to properties such as PreviousResultSize, MessageTypeFilter, and CustomTypes.

SbMessageListParams messageListParams = new SbMessageListParams();
messageListParams.IsInclusive = true;
messageListParams.PreviousResultSize = 10;
messageListParams.NextResultSize = 10;

channel.GetMessagesByTimestamp(TIMESTAMP, messageListParams, (inMessages, inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }
    // A list of previous and next messages of a specified timestamp is successfully retrieved.
});

SbMessageListParams

Copy link

This table only contains properties shown in the code above. See the API reference for a complete list of properties.

Property nameTypeDescription

IsInclusive

bool

Determines whether to include messages sent exactly on the specified timestamp or have the matching message ID.

PreviousResultSize

int

Specifies the number of messages to retrieve, which are sent previously before a specified timestamp. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the earliest message.

NextResultSize

int

Specifies the number of messages to retrieve, which are sent later after a specified timestamp. Note that the actual number of results may be larger than the set value when there are multiple messages with the same timestamp as the latest message.


By timestamp

Copy link

To retrieve messages in a channel, you need to pass the SbMessageListParams object as an argument to the parameter in the GetMessagesByTimestamp() method.

SbMessageListParams messageListParams = new SbMessageListParams();

channel.GetMessagesByTimestamp(TIMESTAMP, messageListParams, (inMessages, inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }
});

List of parameters

Copy link
Parameter nameTypeDescription

inTimestamp

long

Specifies the unique ID of the message to be the reference point of a retrieval.

inParams

SbMessageListParams

Contains a set of parameters you can use when retrieving messages.


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 and SbMessageListParams object.

SbMessageListParams messageListParams = new SbMessageListParams();

channel.GetMessagesByMessageId(MESSAGE_ID, messageListParams, (inMessages, inError) =>
{
    if (inError != null)
    {
        return; // Handle error.
    }

    // A list of previous and next messages of a specified MESSAGE_ID is successfully retrieved.
});

List of parameters

Copy link
Parameter nameTypeDescription

inMessageId

long

Specifies the unique ID of the message to be the reference point of a retrieval.

inParams

SbMessageListParams

Contains a set of parameters you can use when retrieving messages.