Message Reactions API for Go SDK

Add or remove reactions 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 reaction events on that channel. They can also fetch past message reactions 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.

Add an action on a published message. Returns the added action in the response.

Method(s)

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

pn.AddMessageAction().
Channel(string).
MessageTimetoken(string).
Action(pubnub.MessageAction).
Execute()
* required
ParameterDescription
Channel *
Type: string
The channel name.
MessageTimetoken *
Type: string
The publish timetoken of a parent message.
Action *
Type: pubnub.MessageAction
Message Reaction 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 lines

Returns

The AddMessageAction() operation returns a PNAddMessageActionsResponse which contains the following parameters:

Property NameTypeDescription
Data
PNMessageActionsResponse
Details of type PNMessageActionsResponse are here

PNMessageActionsResponse

Property NameTypeDescription
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 Reaction

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 Reaction you can use the following method(s) in the Go SDK:

pn.RemoveMessageAction().
Channel(string).
MessageTimetoken(string).
ActionTimetoken(string).
Execute()
* required
ParameterDescription
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 NameTypeDescription
Data
interface
Returns an empty interface.

Get Message Reactions

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal.

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 Go SDK:

pn.GetMessageActions().
Channel(string).
Start(string).
End(string).
Limit(int).
Execute()
* required
ParameterDescription
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 NameTypeDescription
Data
[]PNMessageActionsResponse
Details of type PNMessageActionsResponse are here
More
PNGetMessageActionsMore
Details of type PNGetMessageActionsMore are here

PNGetMessageActionsMore

Property NameTypeDescription
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.
Last updated on