Message Persistence API for Unreal SDK
Message Persistence gives you real-time access to the history of messages published to PubNub. Each message is timestamped to the nearest 10 nanoseconds and stored across multiple availability zones in several geographic locations. You can encrypt stored messages with AES-256 so they are not readable on PubNub’s network. For details, see Message Persistence.
You control how long messages are stored through your account’s retention policy. Options include: 1 day, 7 days, 30 days, 3 months, 6 months, 1 year, or Unlimited.
You can retrieve the following:
- Messages
- Message reactions
- Files (using the File Sharing API)
Fetch history
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
This function fetches historical messages from one or multiple channels. The IncludeMessageActions
flag also allows you to fetch message actions 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 receive messages older than theStart
timetoken. - If you specify only the
End
parameter (withoutStart
), you receive messages from thatEnd
timetoken and newer. - If you specify both
Start
andEnd
, you receive messages between those timetokens (inclusive ofEnd
).
Returns up to 100 messages on a single channel, or 25 per channel on up to 500 channels. To page, iteratively update the Start
timetoken.
Method(s)
PubnubSubsystem->FetchHistory(
FString Channel,
FOnFetchHistoryResponse OnFetchHistoryResponse,
FPubnubFetchHistorySettings FetchHistorySettings = FPubnubFetchHistorySettings()
);
Parameter | Description |
---|---|
Channel *Type: FString | The channel to get the historical messages of. |
OnFetchHistoryResponse *Type: FOnFetchHistoryResponse | The delegate for the operation's result. You can also use a native callback of the type FOnFetchHistoryResponseNative to handle the result using a lambda. |
FetchHistorySettings | Struct defining history configuration. |
FPubnubFetchHistorySettings
Parameter | Description |
---|---|
MaxPerChannel Type: int | 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 Type: bool | Setting to true will traverse the time line in reverse starting with the oldest message first. Default is false . |
Start Type: FString | timetoken delimiting the start of time slice (exclusive) to pull messages from. |
End Type: FString | timetoken delimiting the end of time slice (inclusive) to pull messages from. |
IncludeMeta Type: bool | Whether meta (passed when Publishing the message) should be included in response or not. |
IncludeMessageType Type: bool | Pass true to receive the message type with each history message. Default is false . |
IncludeUserID Type: bool | Pass true to receive the publisher uuid with each history message. Default is false . |
IncludeMessageActions Type: bool | 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 . |
IncludeCustomMessageType Type: bool | Indicates whether to retrieve messages with the custom message type. For more information, refer to Retrieving Messages. |
Sample code
Reference code
ACTION REQUIRED
before running the code.Truncated response
If truncated, a more
property will be returned with additional parameters. Make iterative calls adjusting parameters.
Returns
This function is void, but the delegate returns the FOnFetchHistoryResponse
struct.
FOnFetchHistoryResponse
Field | Type | Description |
---|---|---|
Result | FPubnubOperationResult | The result of the operation. |
Messages | TArray<FPubnubHistoryMessageData>& | An array of FPubnubHistoryMessageData structs which are the historical messages you wanted to fetch. |
FOnFetchHistoryResponseNative
Field | Type | Description |
---|---|---|
Result | const FPubnubOperationResult& | The result of the operation. |
Messages | const TArray<FPubnubHistoryMessageData>& | An array of FPubnubHistoryMessageData structs which are the historical messages you wanted to fetch. |
FPubnubHistoryMessageData
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. |
CustomMessageType | FString | The custom message type associated with the message. |
MessageActions | TArray<FPubnubMessageActionData> | An array of FPubnubMessageActionData structs which are message actions that were added to the historical messages. |
FPubnubMessageActionData
Field | Type | Description |
---|---|---|
Type | FString | Message action type. |
Value | FString | Message action value. |
UserID | FString | User ID of the user who added the action. |
ActionTimetoken | FString | timetoken indicating when the message action was added. |
MessageTimetoken | FString | timetoken indicating when the message the action was added to had been sent. |
Other examples
Reference code
ACTION REQUIRED
before running the code.Fetch history for a specific time window
You can add a time window to the request:
Actor.h
Actor.cpp
Fetch history with all additional parameters
You can add additional parameters to the request:
Actor.h
Actor.cpp
Fetch history with lambda
You can use a lambda function to handle the response:
Actor.h
Actor.cpp
Delete messages from history
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Removes the messages from the history of a specific channel.
Required setting
Enable Delete-From-History in key settings and initialize with a secret key.
Method(s)
PubnubSubsystem->DeleteMessages(
FString Channel,
FOnDeleteMessagesResponse OnDeleteMessagesResponse,
FPubnubDeleteMessagesSettings DeleteMessagesSettings = FPubnubDeleteMessagesSettings()
);
Parameter | Description |
---|---|
Channel *Type: FString | The channel to get the historical messages of. |
OnDeleteMessagesResponse * | The delegate for the operation's result. You can also use a native callback of the type FOnDeleteMessagesResponseNative to handle the result using a lambda. |
DeleteMessagesSettings | Struct defining delete messages configuration. |
FPubnubDeleteMessagesSettings
Parameter | Description |
---|---|
Start Type: FString | timetoken delimiting the start of time slice (inclusive) to delete messages from. |
End Type: FString | timetoken delimiting the end of time slice (exclusive) to delete messages from. |
Sample code
Reference code
ACTION REQUIRED
before running the code.Returns
This function is void, but the delegate returns the FOnDeleteMessagesResponse
struct.
FOnDeleteMessagesResponse
Field | Type | Description |
---|---|---|
Result | FPubnubOperationResult | The result of the operation. |
FOnDeleteMessagesResponseNative
Field | Type | Description |
---|---|---|
Result | const FPubnubOperationResult& | The result of the operation. |
Other examples
Reference code
ACTION REQUIRED
before running the code.Delete specific message from history
To delete a specific message, pass the publish timetoken
(received from a successful publish) in the End
parameter and timetoken - 1
in the Start
parameter. For example, if 15526611838554310
is the publish timetoken, pass 15526611838554309
in Start
and 15526611838554310
in End
.
Actor.h
Actor.cpp
Delete messages with result struct
You can use the result struct to handle the response:
Actor.h
Actor.cpp
Delete messages with lambda
You can use a lambda function to handle the response:
Actor.h
Actor.cpp
Message counts
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
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)
PubnubSubsystem->MessageCounts(
FString Channel,
FString Timetoken,
FOnMessageCountsResponse OnMessageCountsResponse
);
Parameter | Description |
---|---|
Channel *Type: FString | The channel to get the message counts of. |
timetoken *Type: FString | The timetoken to fetch the message counts from. |
OnMessageCountsResponse *Type: FOnMessageCountsResponse | The delegate for the operation's result. You can also use a native callback of the type FOnMessageCountsResponseNative to handle the result using a lambda. |
Sample code
Reference code
ACTION REQUIRED
before running the code.Returns
This function is void, but the delegate returns the FOnMessageCountsResponse
struct.
FOnMessageCountsResponse
Field | Type | Description |
---|---|---|
Result | FPubnubOperationResult | The result of the operation. |
MessageCounts | int | The number of messages published on one or more channels since a given time. |
FOnMessageCountsResponseNative
Field | Type | Description |
---|---|---|
Result | const FPubnubOperationResult& | The result of the operation. |
MessageCounts | int | The number of messages published on one or more channels since a given time. |
Other examples
Reference code
ACTION REQUIRED
before running the code.Message counts with lambda
You can use a lambda function to handle the response:
Actor.h
Actor.cpp