Message Actions API for Unreal SDK

Add or remove actions on published messages to build features like receipts, reactions, or to associate custom metadata to messages. Clients can subscribe to a channel to receive message action events on that channel. They can also fetch past message actions from Message Persistence independently or when they fetch original messages.

Reactions

"Message Reactions" is a specific application of the Message Actions API for emoji or social reactions.

icon

Usage in Blueprints and C++

Message Actions vs. Message Reactions

Message Actions is the flexible, low-level API for adding any metadata to messages (read receipts, delivery confirmations, custom data), while Message Reactions specifically refers to using Message Actions for emoji/social reactions.

In PubNub Core and Chat SDKs, the same underlying Message Actions API is referred to as Message Reactions when used for emoji reactions - it's the same functionality, just different terminology depending on the use case.

Add message action

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal.

Add an action to a published message.

Method(s)

PubnubSubsystem->AddMessageAction(
FString Channel,
FString MessageTimeToken,
FString ActionType,
FString Value,
FOnAddMessageActionsResponse OnAddMessageActionResponse
);
* required
ParameterDescription
Channel *
Type: FString
Channel to publish the message action to.
MessageTimeToken *
Type: FString
Timetoken of the published message to apply the action to.
ActionType *
Type: FString
Message action type.
Value *
Type: FString
Message action value.
OnAddMessageActionResponse *Delegate for the operation result.

You can also use a native callback of the type FOnAddMessageActionsResponseNative to handle the result using a lambda.

Sample code

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Actor.h



Actor.cpp



Returns

This function is void, but the delegate returns the FOnAddMessageActionsResponse struct.

FOnAddMessageActionsResponse

FieldTypeDescription
Result
FPubnubOperationResult
Result of the operation.
MessageActionData
FPubnubMessageActionData
Message action data.

FOnAddMessageActionsResponseNative

FieldTypeDescription
Result
const FPubnubOperationResult&
Result of the operation.
MessageActionData
const FPubnubMessageActionData&
Message action data.

FPubnubMessageActionData

FieldTypeDescription
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
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Add a message action with lambda

You can use a lambda function to handle the response:

Actor.h



Actor.cpp



Add a message action with result struct

You can use the result struct to handle the response:

Actor.h



Actor.cpp



Remove message action

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal.

Remove a previously added action from a published message. The response is empty.

Method(s)

PubnubSubsystem->RemoveMessageAction(
FString Channel,
FString MessageTimeToken,
FString ActionTimeToken,
FOnRemoveMessageActionResponse OnRemoveMessageActionResponse
);
* required
ParameterDescription
Channel *
Type: FString
Channel the message action was published to.
MessageTimeToken *
Type: FString
Timetoken of the published message to delete the action of.
ActionTimeToken *
Type: FString
Timetoken of the published action to delete.
OnRemoveMessageActionResponse *Delegate for the operation result.

You can also use a native callback of the type FOnRemoveMessageActionResponseNative to handle the result using a lambda.

FOnRemoveMessageActionResponse

FieldTypeDescription
Result
FPubnubOperationResult
Result of the operation.

FOnRemoveMessageActionResponseNative

FieldTypeDescription
Result
const FPubnubOperationResult&
Result of the operation.

Sample code

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Actor.h



Actor.cpp



Returns

This method doesn't have any return value.

Other examples

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Remove a message action with lambda

You can use a lambda function to handle the response:

Actor.h



Actor.cpp



Remove a message action with result struct

You can use the result struct to handle the response:

Actor.h



Actor.cpp



Get message actions

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal.

Get a list of message actions in a channel. The response sorts actions by the action's timetoken in ascending order.

Truncated response

The number of message actions in the response may be truncated when internal limits are hit. If the response is truncated, a more property is returned with additional parameters. Send iterative calls to Message Persistence, adjusting the parameters to fetch more message actions.

Method(s)

PubnubSubsystem->GetMessageActions(
FString Channel,
FOnGetMessageActionsResponse OnGetMessageActionsResponse,
FString Start = "",
FString End = "",
int Limit = 0
);
* required
ParameterDescription
Channel *
Type: FString
Channel the message action was published to.
OnGetMessageActionsResponse *Delegate for the operation result.

You can also use a native callback of the type FOnGetMessageActionsResponseNative to handle the result using a lambda.
Start
Type: FString
Previously returned cursor bookmark for fetching the next page. Use "" to avoid paginating with a start bookmark.
End
Type: FString
Previously returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter. Use "" to avoid paginating with an end bookmark.
Limit
Type: int
Number of objects to return in the response. Default is 100.

Sample code

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Actor.h



Actor.cpp



Returns

This function is void, but the delegate returns the FOnGetMessageActionsResponse struct.

FOnGetMessageActionsResponse

FieldTypeDescription
Result
FPubnubOperationResult
Result of the operation.
MessageActions
TArray<FPubnubMessageActionData>&
Array of FPubnubMessageActionData structs for the actions sent on a given channel.

FOnGetMessageActionsResponseNative

FieldTypeDescription
Result
const FPubnubOperationResult&
Result of the operation.
MessageActions
const TArray<FPubnubMessageActionData>&
Array of FPubnubMessageActionData structs for the actions sent on a given channel.

FPubnubMessageActionData

FieldTypeDescription
Type
FString
Message action type.
Value
FString
Message action value.
UserID
FString
User identifier of the user who added the action.
ActionTimetoken
FString
Timetoken indicating when the message action was added.
MessageTimetoken
FString
Timetoken indicating when the message, to which the action was added, had been sent.

Other examples

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

Get message actions with lambda

You can use a lambda function to handle the response:

Actor.h



Actor.cpp



Get message actions from a channel with a specific time window and limit

You can add a time window and limit to the request:

Actor.h



Actor.cpp



History with message reactions

You can choose to return message actions when fetching historical messages. Refer to Fetch History for more details.

Complete example

Reference code
Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code.

ASample_MessageActionsFull.h


ASample_MessageActionsFull.cpp


Last updated on