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)
icon

Usage in Blueprints and C++

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 (without End), you will receive messages that are older than the Start timetoken
  • if you specify only the End parameter (without Start), you will receive messages from that End timetoken and newer
  • if you specify values for both Start and End parameters, you will retrieve messages between those timetokens (inclusive of the End 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)

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
FOnPubnubResponse OnFetchHistoryResponse;
OnFetchHistoryResponse.BindDynamic(this, &AMyActor::OnFetchHistoryResponse);

// Create settings for fetching history
FPubnubFetchHistorySettings FetchHistorySettings;
show all 20 lines
Truncated 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

{
"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 lines

Message 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)

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
Last updated on