Message history
PubNub APIs let you effectively fetch historical messages from direct, group, or public conversations.
While App Context API lets you manage metadata and relationships between users and channels, enabling efficient tracking of which channels are associated with a given user, Message Persistence API lets you retrieve messages from those channels. Together, these APIs enable you to gather all conversations involving a user and easily fetch specific message histories for any interactions between users.
Use GetHistory() to fetch past messages from a channel.
API limitation
Results cannot be filtered by message type. All messages within the specified timeframe are returned.
Asynchronous and synchronous method execution
Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.
-
Asynchronous methods (
Asyncsuffix) returnvoidand take an optional delegate parameter that fires when the operation completes.1Channel->GetHistoryAsync(StartTimetoken, EndTimetoken, OnGetHistoryResponseDelegate);You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the
Nativesuffix (for example,FOnPubnubChatGetHistoryResponseNative). -
Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.
1FPubnubChatGetHistoryResult Result = Channel->GetHistory(StartTimetoken, EndTimetoken);
Method signature
- C++ / Input parameters
- Blueprint
1Channel->GetHistory(
2 FString StartTimetoken,
3 FString EndTimetoken,
4 int Count = 25
5);
Input parameters
| Parameter | Description |
|---|---|
StartTimetoken *Type: FStringDefault: n/a | Timetoken delimiting the start of a time slice (exclusive) to pull messages from. For details, refer to the Fetch History section. |
EndTimetoken *Type: FStringDefault: n/a | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the Fetch History section. |
CountType: intDefault: 25 | Number of historical messages to return for the channel in a single call. Default is 25. Since each call returns all attached message reactions by default, it is recommended to keep this value low; the server supports up to 100 messages per request. |
Output
| Field | Type | Description |
|---|---|---|
Result | FPubnubChatOperationResult | Operation result with Error and ErrorMessage. |
Messages | TArray<UPubnubChatMessage*> | Array listing the requested number of historical Message objects. |
IsMore | bool | Indicates if more messages exist beyond the returned range. |
By default, each call returns all message reactions and metadata attached to the retrieved messages.
Sample code
Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.
Retrieve message history for a channel asynchronously.