Message Actions API for Go 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.
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 the added action in the response.
Method(s)
To Add a Message Action you can use the following method(s) in the Go SDK:
pn.AddMessageAction().
Channel(string).
MessageTimetoken(string).
Action(pubnub.MessageAction).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | The channel name. |
MessageTimetoken *Type: string | The publish timetoken of a parent message. |
Action *Type: pubnub.MessageAction | Message Action Details :-ActionType : What feature this action represents -- max 15 characters. ActionValue : Details about the action -- max 40 characters. |
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.
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
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | PNMessageActionsResponse | Details of type PNMessageActionsResponse are here |
PNMessageActionsResponse
Property Name | Type | Description |
---|---|---|
ActionType | string | What feature this action represents. |
ActionValue | string | Details about the action. |
ActionTimetoken | string | The timetoken when the action was added. |
MessageTimetoken | string | The timetoken of the parent message. |
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 Go SDK:
pn.RemoveMessageAction().
Channel(string).
MessageTimetoken(string).
ActionTimetoken(string).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | The channel name. |
MessageTimetoken *Type: string | The publish timetoken of a parent message. |
ActionTimetoken *Type: string | The publish timetoken of the action. |
Basic Usage
res, status, err := pn.RemoveMessageAction()
.Channel("my-channel")
.MessageTimetoken("15698453963258802")
.ActionTimetoken("15698453963258812")
.Execute()
Returns
The RemoveMessageAction()
operation returns a PNRemoveMessageActionsResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | interface | Returns an empty interface. |
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 Go SDK:
pn.GetMessageActions().
Channel(string).
Start(string).
End(string).
Limit(int).
Execute()
Parameter | Description |
---|---|
Channel *Type: string | The channel name. |
Start Type: string | Action timetoken denoting the start of the range requested (return values will be less than start). |
End Type: string | Action timetoken denoting the end of the range requested (return values will be greater than or equal to end). |
Limit Type: int | Number of actions to return in response.. |
Basic Usage
res, status, err := pn.GetMessageActions()
.Channel("my-channel")
.Start("15698453963258812")
.End("15698453963258811")
.Execute()
Returns
The GetMessageActions()
operation returns a PNGetMessageActionsResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | []PNMessageActionsResponse | Details of type PNMessageActionsResponse are here |
More | PNGetMessageActionsMore | Details of type PNGetMessageActionsMore are here |
PNGetMessageActionsMore
Property Name | Type | Description |
---|---|---|
URL | string | The URL of the next set of results. |
Start | string | The start param for the next set of results. |
End | string | The end param for the next set of results. |
Limit | int | The limit for the next set of results. |