Message Reactions API for PubNub 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 reactions events on that channel. They can also fetch past message reactionss from Message Persistence independently or when they fetch original messages.
Terminology
All message reactions in code are collectively called message reactions in the docs and the term applies both to reacting to a message (through emojis) and acting on a message (by deleting it).
Add Message Reaction
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.
Add an action on a published message
. Returns PNAddMessageActionResult
in the response.
Method(s)
To Add a Message Reaction you can use the following method(s) in the Unity SDK:
pubnub.AddMessageAction()
.Channel(string)
.MessageTimetoken(long)
.Action(PNMessageAction)
.Execute(System.Action<PNAddMessageActionResult, PNStatus>)
Parameter | Type | Required | Description |
---|---|---|---|
Channel | string | Yes | Specifies channel name to publish message reactions to. |
MessageTimetoken | long | Yes | Timestamp when the actual message was created the message reactions belongs to. |
Action | PNMessageAction | Yes | Specify the action you want to publish of type PNMessageAction . |
Execute | System.Action | Yes | System.Action of type PNAddMessageActionResult . |
ExecuteAsync | None | Optional | Returns Task<PNResult<PNAddMessageActionResult>> . |
PNMessageAction
Parameter | Type | Required | Description |
---|---|---|---|
Type | string | Yes | Message reactions's type . |
Value | string | Yes | Message reactions's value . |
Basic Usage
pubnub.AddMessageAction()
.Channel("my_channel")
.MessageTimetoken(5610547826969050)
.Action(new PNMessageAction { Type = "reaction", Value = "smiley_face" })
.Execute(new PNAddMessageActionResult((result, status) =>
{
//result is of type PNAddMessageActionResult.
}));
Returns
The AddMessageAction()
operation returns a PNAddMessageActionResult
which contains the following properties:
Property Name | Type | Description |
---|---|---|
MessageTimetoken | long | Timetoken of the message to be associated with Message Reaction. |
ActionTimetoken | long | Timetoken of the Message Reaction that will be associated with the message. |
Action | PNMessageAction | Message Reaction payload. |
→ Type | string | Type of the Message Reaction. |
→ Value | string | Value of the Message Reaction. |
Uuid | string | UUID associated with the Message Reaction. |
{
"MessageTimetoken":15610547826969050,
"ActionTimetoken":15610547826970050,
"Action":{
"type":"reaction",
"value":"smiley_face"
},
"Uuid":"user-456"
}
Remove Message Reaction
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.
Remove a previously added action on a published message
. Returns an empty response.
Method(s)
To Remove a Message Reaction 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>)
Parameter | Type | Required | Description |
---|---|---|---|
Channel | string | Yes | Specifies channel name to publish message reactions to. |
MessageTimetoken | long | Yes | Publish timetoken of the original message |
ActionTimetoken | long | Yes | Publish timetoken of the message reaction to be removed. |
Uuid | string | Yes | UUID of the message . |
Execute | System.Action | Yes | System.Action of type PNRemoveMessageActionResult . |
ExecuteAsync | None | Optional | 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 Reactions
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.
Get a list of message reactions in a channel
. Returns a list of actions sorted by the action's timetoken in ascending order.
Truncated response
Number of message reactions 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 reactions.
Method(s)
To Get Message Reactions 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>)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Channel | string | Yes | The channel name. | |
Start | long | Optional | Message Reaction timetoken denoting the start of the range requested (return values will be greater than or equal to start ). | |
End | long | Optional | Message Reaction timetoken denoting the end of the range requested (return values will be less than end ). | |
Limit | int | Optional | 100 | Specifies the number of actions to return in response. Default/Maximum is 100 . |
Execute | System.Action | Yes | System.Action of type PNGetMessageActionsResult . | |
ExecuteAsync | None | Optional | 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 Name | Type | Description |
---|---|---|
Message Reactions | List<PNMessageActionItem> | List of Message Reactions |
More | MoreInfo | Pagination information. |
The PNMessageActionItem
has the following properties:
Property Name | Type | Description |
---|---|---|
→ MessageTimetoken | long | Timetoken associated with the message. |
→ Action | PNMessageAction | Message Reaction payload. |
→ → Type | string | Type of the Message Reaction. |
→ → Value | string | Value of the Message Reaction. |
→ Uuid | string | UUID associated with the reaction. |
→ ActionTimetoken | long | Timetoken associated with the reaction. |
The More
has following properties:
Property Name | Type | Description |
---|---|---|
→ → 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 Reactions 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