Message history
Unity Chat SDK lets you fetch historical messages from one channel using the GetMessageHistory()
method.
Due to current PubNub API limitations, you cannot filter the results by type, so you'll get all messages that happened on a given channel in a given timeframe.
Method signature
This method takes the following parameters:
channel.GetMessageHistory(
string startTimeToken,
string endTimeToken,
int count
)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
startTimetoken | string | Yes | n/a | Timetoken delimiting the start of a time slice (exclusive) to pull messages from. For details, refer to the Fetch History section. |
endTimetoken | string | Yes | n/a | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the Fetch History section. |
count | int | Yes | 25 | Number of historical messages to return for the channel in a single call. Since each call returns all attached message reactions by default, the maximum number of returned messages is 25 . For more details, refer to the description of the IncludeMessageActions parameter in the Unity SDK docs. |
Output
This method returns a List<Message>
object sent within the given timeframe.
By default, each call returns all message reactions and metadata attached to the retrieved messages.
Basic usage
From the support
channel, fetch 10
historical messages older than the timetoken 15343325214676133
.
// reference the "channel" object
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
// invoke the method on the "channel" object
channel.GetMessageHistory(startTimetoken: "15343325214676133", count: 10);