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.

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 a action to a published message.

Method(s)

Basic Usage

Reference code

This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

MyGameMode.h

// NOTE: This example requires correct PubnubSDK configuration in plugins settings and adding "PubnubLibrary" to PublicDependencyModuleNames in your build.cs
// More info in the documentation: https://www.pubnub.com/docs/sdks/unreal/api-reference/configuration

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MyGameMode.generated.h"

/**
*
*/
UCLASS()
//Replace MYPROJECT with name of your project
class MYPROJECT_API AMyGameMode : public AGameModeBase
show all 24 lines

MyGameMode.cpp

#include "MyGameMode.h"
#include "PubnubSubsystem.h"
#include "Kismet/GameplayStatics.h"

void AMyGameMode::AddMessageReactionExample()
{
// Get PubnubSubsystem from the game instance
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();

// Ensure user ID is set
PubnubSubsystem->SetUserID("my_user_id");

FString Channel = "randomChannel";
FString MessageTimeToken = "5610547826969050";
show all 30 lines

Returns

This method returns the FOnAddMessageActionsResponse struct.

FOnAddMessageActionsResponse

FieldTypeDescription
MessageActionTimetoken
FString
Timetoken indicating when the message action was added.

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. Returns an empty response.

Method(s)

Basic Usage

#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();

FString Channel = "randomChannel";
FString MessageTimeToken = "5610547826969050";
FString MessageTimeToken = "15610547826970050";

// Add the message action
PubnubSubsystem->RemoveMessageAction(Channel, MessageTimeToken, ActionTimeToken);

Returns

This method doesn't have any return value.

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. Returns a list of actions sorted by the action's timetoken in ascending order.

Truncated response

Number of message actions 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 Message Persistence adjusting the parameters to fetch more message actions.

Method(s)

Basic Usage

#include "Kismet/GameplayStatics.h"
#include "PubnubSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubSubsystem* PubnubSubsystem = GameInstance->GetSubsystem<UPubnubSubsystem>();

// Create a pubnub response delegate
// you MUST implement your own callback function to handle the response
FOnGetMessageActionsResponse OnGetMessageActionsResponse;
OnGetMessageActionsResponse.BindDynamic(this, &AMyActor::OnGetMessageActionsResponse);

FString Channel = "randomChannel";
FString Start = "";
FString End = "";

show all 17 lines

Returns

This method returns the FOnGetMessageActionsResponse struct.

FOnGetMessageActionsResponse


FieldTypeDescription
Status
int
HTTP code of the result of the operation.
MessageActions
TArray<FPubnubMessageActionData>&
An array of FPubnubMessageActionData structs which are the message actions sent on a given channel.

JSON Response

{
"status": 200,
"data": [{
"messageTimetoken": "17198286823798098",
"type": "reaction",
"uuid": "User1",
"value": "happy",
"actionTimetoken": "17198286996058878"
}]
}

History with Message Actions

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

Last updated on