Message Actions API for Unity 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 actions events on that channel. They can also fetch past message actions from Message Persistence independently or when they fetch original messages.

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 on a published message. Returns PNAddMessageActionResult in the response.

Method(s)

To Add a Message Action you can use the following method(s) in the Unity SDK:

pubnub.AddMessageAction()
.Channel(string)
.MessageTimetoken(long)
.Action(PNMessageAction)
.Execute(System.Action<PNAddMessageActionResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Specifies channel name to publish message actions to.
MessageTimetoken *
Type: long
Timestamp when the actual message was created the message actions belongs to.
Action *Specify the action you want to publish of type PNMessageAction.
Execute *
Type: System.Action
System.Action of type PNAddMessageActionResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNAddMessageActionResult>>.

PNMessageAction

* required
ParameterDescription
Type *
Type: string
Message actions's type.
Value *
Type: string
Message actions's value.

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.

using PubnubApi;
using PubnubApi.Unity;
using UnityEngine;

public class AddMessageActionExample : MonoBehaviour {
// Reference to a pubnub manager previously setup in Unity Editor
// For more details, see https://www.pubnub.com/docs/sdks/unity#configure-pubnub
[SerializeField] private PNManagerBehaviour pubnubManager;

// An editor-serialized string for the channel ID
[SerializeField] private string channelId = "my_channel";

// An editor-serialized timetoken for the message
[SerializeField] private long messageTimetoken = 5610547826969050;

show all 34 lines

Returns

The AddMessageAction() operation returns a PNAddMessageActionResult which contains the following properties:

Property NameTypeDescription
MessageTimetoken
long
Timetoken of the message to be associated with Message Action.
ActionTimetoken
long
Timetoken of the Message Action that will be associated with the message.
Action
PNMessageAction
Message Action payload.
 → Type
string
Type of the Message Action.
 → Value
string
Value of the Message Action.
Uuid
string
UUID associated with the Message Action.
{
"MessageTimetoken":15610547826969050,
"ActionTimetoken":15610547826970050,
"Action":{
"type":"reaction",
"value":"smiley_face"
},
"Uuid":"user-456"
}

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 on a published message. Returns an empty response.

Method(s)

To Remove a Message Action you can use the following method(s) in the Unity SDK:

pubnub.RemoveMessageAction()
.Channel(string)
.MessageTimetoken(long)
.ActionTimetoken(long)
.Uuid(string)
.Execute(System.Action<PNRemoveMessageActionResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Specifies channel name to publish message actions to.
MessageTimetoken *
Type: long
Publish timetoken of the original message
ActionTimetoken *
Type: long
Publish timetoken of the message action to be removed.
Uuid *
Type: string
UUID of the message.
Execute *
Type: System.Action
System.Action of type PNRemoveMessageActionResult.
ExecuteAsync
Type: None
Returns Task<PNResult<PNRemoveMessageActionResult>>.

Basic Usage

pubnub.RemoveMessageAction()
.Channel("my_channel")
.MessageTimetoken(15701761818730000)
.ActionTimetoken(15701775691010000)
.Uuid("mytestuuid")
.Execute(new PNRemoveMessageActionResult((result, status) =>
{
//empty result of type PNRemoveMessageActionResult.
}));

Returns

The RemoveMessageAction() operation returns a no actionable data.

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)

To Get Message Actions you can use the following method(s) in the Unity SDK:

pubnub.GetMessageActions()
.Channel(string)
.Start(long)
.End(long)
.Limit(int)
.Execute(System.Action<PNGetMessageActionsResult, PNStatus>)
* required
ParameterDescription
Channel *
Type: string
Default:
n/a
The channel name.
Start
Type: long
Default:
n/a
Message Action timetoken denoting the start of the range requested (return values will be greater than or equal to start).
End
Type: long
Default:
n/a
Message Action timetoken denoting the end of the range requested (return values will be less than end).
Limit
Type: int
Default:
100
Specifies the number of actions to return in response. Default/Maximum is 100.
Execute *
Type: System.Action
Default:
n/a
System.Action of type PNGetMessageActionsResult.
ExecuteAsync
Type: None
Default:
n/a
Returns Task<PNResult<PNGetMessageActionsResult>>.

Basic Usage

pubnub.GetMessageActions()
.Channel("my_channel")
.Execute(new PNGetMessageActionsResult((result, status) =>
{
//result is of type PNGetMessageActionsResult.
}));

Returns

The GetMessageActions() operations returns PNGetMessageActionsResult which contains the following properties :

Property NameTypeDescription
Message Actions
List<PNMessageActionItem>
List of Message Actions
More
MoreInfo
Pagination information.

The PNMessageActionItem has the following properties:

Property NameTypeDescription
 →  MessageTimetoken
long
Timetoken associated with the message.
 →  Action
PNMessageAction
Message Action payload.
 →  →  Type
string
Type of the Message Action.
 →  →  Value
string
Value of the Message Action.
 →  Uuid
string
UUID associated with the action.
 →  ActionTimetoken
long
Timetoken associated with the action.

The More has following properties:

Property NameTypeDescription
 →  →  Start
long
Timetoken denoting the start of the requested range.
 →  →  End
long
Timetoken denoting the end of the requested range.
 →  →  Limit
int
Number of Message Actions returned in response.
{
"MessageActions":
[{
"MessageTimetoken":15610547826969050,
"Action":{
"type":"reaction",
"value":"smiley_face"
},
"Uuid":"pn-5903a053-592c-4a1e-8bfd-81d92c962968",
"ActionTimetoken":15717253483027900
}],
"More": {
"Start": 15610547826970050,
"End": 15645905639093361,
"Limit": 2
show all 17 lines
Last updated on