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.
Method signature
- Blueprint
- C++ / Input parameters
1Channel->GetHistory(
2 int Limit,
3 FString Start,
4 FString End
5);
| Parameter | Description |
|---|---|
StartType: FStringDefault: n/a | Timetoken delimiting the start of a time slice (exclusive) to pull messages from. For details, refer to the Fetch History section. |
EndType: FStringDefault: n/a | Timetoken delimiting the end of a time slice (inclusive) to pull messages from. For details, refer to the Fetch History section. |
LimitType: intDefault: 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. |
Output
| Parameter | Description |
|---|---|
TArray<UPubnubMessage*> | Array listing the requested number of historical Message objects. |
By default, each call returns all message reactions and metadata attached to the retrieved messages.
Sample code
From the support channel, fetch 10 historical messages older than the timetoken 15343325214676133.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11// Define parameters for the GetHistory method
12int Limit = 10;
13FString StartTimetoken = "15343325214676133";
14FString EndTimetoken; // Empty FString means no end timetoken will be used
15
show all 17 lines