Message Actions

Message actions add lightweight metadata to messages without changing the content. Use them for:

An action is a string. Actions reference a message by a timetoken. Use your own emoji library; PubNub SDKs do not include one.

Parameter names vary by SDK. Examples: messageTimetoken, message_timetoken.

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 actions

Add an action to a message. The response includes the added action.

pubnub.addMessageAction(
{
channel: 'chats.room1',
messageTimetoken: '15610547826970040',
action: {
type: 'reaction',
value: 'smiley_face',
}
},
function(status, response) {
console.log(status, response);
}
);

Receive message actions

To receive a message action, listen for the event type messageAction and subscribe to the channel where the action is added. Subscribe the same way you do for other events.

Remove message actions

Remove an action from a message. The response is empty.

pubnub.removeMessageAction(
{
channel: 'chats.room1',
messageTimetoken: '15610547826970040',
actionTimetoken: '15610547826970075',
},
function(status, response) {

});

Retrieve actions

Use the History with Actions API to get messages with their actions. You can also get only actions for a time window. This helps you catch up after the app was offline. The API returns actions sorted by action timetoken, oldest first.

Offline message actions

You can add actions to any message, even ones published before your app went offline.

pubnub.getMessageActions(
{
channel: 'chats.room1',
start: '15610547826970041',
end: '15610547826970040',
limit: 100,
},
function(status, response) {
console.log(status, response);
}
);

Delete messages

Enable Delete-From-History requests in the Admin Portal. In this example, the start and end timetoken values differ by 1 (last digit). This deletes the message at the end timetoken.

pubnub.deleteMessages(
{
channels: 'chats.room1',
start: "15526611838554309",
end: "15526611838554310",
},
function (status, response) {
console.log(status, response);
}
);

Bulk message delete

You can delete multiple messages or all messages in a channel.

ParametersBehavior
start & end
Delete messages between those timetokens (only one message at the end timetoken if values differ by 1)
start only
Delete all messages before (not at) that timetoken
end only
Delete all messages after (and at) that timetoken
none
Delete all messages
No undo option

Deletions are permanent. Verify the timetoken range before sending the request.

Last updated on