Message Actions API for Go SDK
Use message actions to add or remove metadata on published messages. Common uses include receipts and reactions. Clients subscribe to a channel to receive message action events. Clients can also fetch past message actions from Message Persistence, either on demand or when fetching original messages.
Reactions
"Message Reactions" is a specific application of the Message Actions API for emoji or social reactions.
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
Enable Message Persistence for your key in the Admin Portal as described in the support article.
Add an action to a published message. The response includes the added action.
Method(s)
Use this Go method:
pn.AddMessageAction().
Channel(string).
MessageTimetoken(string).
Action(pubnub.MessageAction).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | Channel name to add the message action to. |
MessageTimetoken *Type: string | Timetoken of the target message. |
Action *Type: pubnub.MessageAction | Message action payload: ActionType (type) and ActionValue (value). |
Sample code
Reference code
package main
import (
"fmt"
"log"
pubnub "github.com/pubnub/go/v7"
)
func main() {
// Configure the PubNub instance with demo keys
config := pubnub.NewConfigWithUserId("myUniqueUserId")
config.SubscribeKey = "demo"
config.PublishKey = "demo"
show all 45 linesReturns
The AddMessageAction()
operation returns a PNAddMessageActionsResponse
:
Property Name | Type | Description |
---|---|---|
Data | PNMessageActionsResponse | See PNMessageActionsResponse. |
PNMessageActionsResponse
Property Name | Type | Description |
---|---|---|
ActionType | string | Message action type. |
ActionValue | string | Message action value. |
ActionTimetoken | string | Timetoken when the action was added. |
MessageTimetoken | string | Timetoken of the target message. |
Remove message action
Requires Message Persistence
Enable Message Persistence for your key in the Admin Portal as described in the support article.
Remove a previously added action from a published message. The response is empty.
Method(s)
Use this Go method:
pn.RemoveMessageAction().
Channel(string).
MessageTimetoken(string).
ActionTimetoken(string).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | Channel name to remove the message action from. |
MessageTimetoken *Type: string | Timetoken of the target message. |
ActionTimetoken *Type: string | Timetoken of the message action to remove. |
Sample code
res, status, err := pn.RemoveMessageAction()
.Channel("my-channel")
.MessageTimetoken("15698453963258802")
.ActionTimetoken("15698453963258812")
.Execute()
Returns
The RemoveMessageAction()
operation returns a PNRemoveMessageActionsResponse
:
Property Name | Type | Description |
---|---|---|
Data | interface | Empty object. |
Get message actions
Requires Message Persistence
Enable Message Persistence for your key in the Admin Portal as described in the support article.
Get a list of message actions in a channel. The response sorts actions by the action 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)
Use this Go method:
pn.GetMessageActions().
Channel(string).
Start(string).
End(string).
Limit(int).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | Channel name to list message actions for. |
Start Type: string | Message action timetoken for the start of the range (exclusive). |
End Type: string | Message action timetoken for the end of the range (inclusive). |
Limit Type: int | Number of actions to return. |
Sample code
res, status, err := pn.GetMessageActions()
.Channel("my-channel")
.Start("15698453963258812")
.End("15698453963258811")
.Execute()
Returns
The GetMessageActions()
operation returns a PNGetMessageActionsResponse
:
Property Name | Type | Description |
---|---|---|
Data | []PNMessageActionsResponse | See PNMessageActionsResponse. |
More | PNGetMessageActionsMore | See PNGetMessageActionsMore. |
PNGetMessageActionsMore
Property Name | Type | Description |
---|---|---|
URL | string | URL of the next set of results. |
Start | string | Start parameter for the next set of results. |
End | string | End parameter for the next set of results. |
Limit | int | Limit for the next set of results. |