Message Persistence API for PubNub Unreal SDK
Message Persistence provides real-time access to the history of all messages published to PubNub. Each published message is timestamped to the nearest 10 nanoseconds and is stored across multiple availability zones in several geographical locations. Stored messages can be encrypted with AES-256 message encryption, ensuring that they are not readable while stored on PubNub's network. For more information, refer to Message Persistence.
Messages can be stored for a configurable duration or forever, as controlled by the retention policy that is configured on your account. The following options are available: 1 day, 7 days, 30 days, 3 months, 6 months, 1 year, or Unlimited.
You can retrieve the following:
- Messages
- Message actions
- File Sharing (using File Sharing API)
Fetch History
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function fetches historical messages from one or multiple channels. The IncludeMessageActions
flag also allows you to fetch message reactions along with the messages.
It's possible to control how messages are returned and in what order.
- if you specify only the
Start
parameter (withoutEnd
), you will receive messages that are older than theStart
timetoken - if you specify only the
End
parameter (withoutStart
), you will receive messages from thatEnd
timetoken and newer - if you specify values for both
Start
andEnd
parameters, you will retrieve messages between those timetokens (inclusive of theEnd
value)
You will receive a maximum of 100 messages for a single channel or 25 messages for multiple channels (up to 500). If more messages meet the timetoken criteria, make iterative calls while adjusting the start
timetoken to fetch the entire list of messages from Message Persistence.
Method(s)
- Blueprint
- C++
Response variants
You can also call the FetchHistory_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
Response variants
You can also call the FetchHistory_JSON()
variant of this method to get an FOnPubnubResponse
which contains pure JSON.
PubnubSubsystem->FetchHistory(
FString ChannelName,
FOnFetchHistoryResponse OnFetchHistoryResponse,
FPubnubFetchHistorySettings FetchHistorySettings = FPubnubFetchHistorySettings()
);
Parameter | Type | Required | Description |
---|---|---|---|
ChannelName | FString | Yes | The channel to get the historical messages of. |
OnFetchHistoryResponse | FOnFetchHistoryResponse | Yes | The callback function used to handle the result. |
FetchHistorySettings | FPubnubFetchHistorySettings | Optional | Struct defining history configuration. |
FPubnubFetchHistorySettings
Parameter | Type | Required | Description |
---|---|---|---|
MaxPerChannel | int | Optional | Specifies the number of historical messages to return. Default and maximum is 100 for a single channel, 25 for multiple channels, and 25 if IncludeMessageActions is true . |
Reverse | bool | Optional | Setting to true will traverse the time line in reverse starting with the oldest message first. Default is false . |
Start | FString | Optional | Timetoken delimiting the start of time slice (exclusive) to pull messages from. |
End | FString | Optional | Timetoken delimiting the end of time slice (inclusive) to pull messages from. |
IncludeMeta | bool | Optional | Whether meta (passed when Publishing the message) should be included in response or not. |
IncludeMessageType | bool | Optional | Pass true to receive the message type with each history message. Default is false . |
IncludeUUID | bool | Optional | Pass true to receive the publisher uuid with each history message. Default is false . |
IncludeMessageActions | bool | Optional | The flag denoting to retrieve history messages with message actions. If true , the method is limited to one channel and 25 messages only. Default is false . |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString ChannelName = "randomChannel";
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnFetchHistoryResponse OnFetchHistoryResponse;
OnFetchHistoryResponse.BindDynamic(this, &AMyActor::OnFetchHistoryResponse);
// Create settings for fetching history
FPubnubFetchHistorySettings FetchHistorySettings;
show all 20 linesTruncated response
If you fetch messages with messages actions, the number of messages in the response may be truncated when internal limits are hit. If the response is truncated, a more
property will be returned with additional parameters. Send iterative calls to history adjusting the parameters to fetch more messages.
Returns
This method returns the FOnFetchHistoryResponse
struct.
FOnFetchHistoryResponse
Field | Type | Description |
---|---|---|
Error | bool | Whether the operation resulted in an error. |
Status | int | HTTP code of the result of the operation. |
ErrorMessage | FString | Detailed information about the error. |
Messages | TArray<FPubnubMessageData>& | An array of FPubnubMessageData structs which are the historical messages you wanted to fetch. |
FPubnubMessageData
Field | Type | Description |
---|---|---|
Message | FString | The message text. |
UserID | FString | User ID of the user who sent the message. |
Timetoken | FString | Timetoken indicating when the message was sent. |
Meta | FString | Additional information. |
MessageType | FString | Type of the message. Refer to Message types for more information. |
MessageActions | TArray<FPubnubMessageActionData> | An array of FPubnubMessageActionData structs which are message reactions that were added to the historical messages. |
FPubnubMessageActionData
Field | Type | Description |
---|---|---|
Type | FString | Message reaction type. |
Value | FString | Message reaction value. |
UserID | FString | User ID of the user who added the reaction. |
ActionTimetoken | FString | Timetoken indicating when the message reaction was added. |
MessageTimetoken | FString | Timetoken indicating when the message the reaction was added to had been sent. |
JSON response
{
"status": 200,
"error": false,
"error_message": "",
"channels": {
"myChannel": [
{
"message": {
"text": "This is a realtime message_1!"
},
"timetoken": "17181114089437121"
},
{
"message": {
"text": "This is a realtime message_2!"
show all 33 linesMessage Counts
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Returns the number of messages published on one or more channels since a given time. The count returned is the number of messages in history with a Timetoken
value greater than or equal to than the passed value in the Timetoken
parameter.
Unlimited message retention
For keys with unlimited message retention enabled, this method considers only messages published in the last 30 days.
Method(s)
- Blueprint
- C++
PubnubSubsystem->MessageCounts(
FString ChannelName,
FString Timetoken,
FOnPubnubResponse OnMessageCountsResponse)
Parameter | Type | Required | Description |
---|---|---|---|
ChannelName | FString | Yes | The channel to get the message counts of. |
Timetoken | FString | Yes | The timetoken to fetch the message counts from. |
OnMessageCountsResponse | FOnPubnubResponse | Yes | The callback function used to handle the result. |
Basic Usage
#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();
FString ChannelName = "randomChannel";
FDateTime TimeStamp = FDateTime::Now();
// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnPubnubResponse OnMessageCountsResponse;
OnMessageCountsResponse.BindDynamic(this, &AMyActor::OnMessageCountsResponse);
PubnubSubsystem->MessageCounts(ChannelName, TimeStamp, OnMessageCountsResponse);
Returns
This method returns an integer that represents the number of messages published on one or more channels since a given time.
5