JavaScriptWebWebNode.jsPhoneGapReactTitaniumVueJavaScript V4 Message Actions API Reference for Realtime Apps

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 PubNub Storage independently or when they fetch original messages.


Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

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

To Add a Message Action you can use the following method(s) in the JavaScript V4 SDK:

  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelStringYesName of channel which stores the message for which action should be added.
    messageTimetokenStringYesTimetoken of message for which action should be added.
    actionHashYesMessage action information.
    action.typeStringYesWhat feature this message action represents.
    action.valueStringYesValue which should be stored along with message action.
    callbackFunctionOptionalExecutes on a successful / unsuccessful add message action.
pubnub.addMessageAction(
    {
        channel: 'channel1'
        messageTimetoken: '15610547826970040',
        action: {
            type: 'reaction',
            value: 'smiley_face',
        },
    },
    function(status, response) {

    }
);
// Example of status
{
    "error": false,
    "operation": "PNAddMessageActionOperation",
    "statusCode": 200
}

// Example of response
{
    "data": {
        "type": "reaction",
        "value": "smiley_face",
        "uuid": "user-456",
        "actionTimetoken": "15610547826970050",
        "messageTimetoken": "15610547826969050"
    }
}

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Remove a peviously added action on a published message. Returns an empty response.

To Remove a Message Action you can use the following method(s) in the JavaScript V4 SDK:

  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelStringYesName of channel which store message for which action should be removed.
    messageTimetokenStringYesTimetoken of message for which action should be removed.
    actionTimetokenStringYesAction addition timetoken.
    callbackFunctionOptionalExecutes on a successful / unsuccessful remove message action.
pubnub.removeMessageAction(
    {
        channel: 'channel1'
        messageTimetoken: '15610547826970040',
        actionTimetoken: '15610547826970040',
    },
    function(status, response) {

    }
);
// Example of status
{
    "error": false,
    "operation": "PNRemoveMessageActionOperation",
    "statusCode": 200
}

// Example of response
{
    "data": {}
}

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Get a list of message actions in a channel. Returns a list of actions in the response.

To Get Message Actions you can use the following method(s) in the JavaScript V4 SDK:

  1. ParameterTypeRequiredDescription
    Operation ArgumentsHashYesA hash of arguments.
    channelStringYesName of channel from which list of messages actions should be retrieved.
    startStringOptionalMessage action timetoken denoting the start of the range requested.
    Return values will be less than start.
    endStringOptionalMessage action timetoken denoting the end of the range requested.
    Return values will be greater than or equal to end.
    limitNumberOptionalNumber of message actions to return in response.
    callbackFunctionOptionalExecutes on a successful / unsuccessful fetch message actions.
pubnub.getMessageActions(
    {
        channel: 'channel1',
        start: '15610547826970040',
        end: '15610547826970040',
        limit: 100,
    },
    function(status, response) {

    }
);
// Example of status
{
    "error": false,
    "operation": "PNGetMessageActionsOperation",
    "statusCode": 200
}

// Example of response
{
    "data": [
        {
            "type": "reaction",
            "value": "smiley_face",
            "uuid": "user-456",
            "actionTimetoken": "15610547826970050",
            "messageTimetoken": "15610547826969050"
        }
    ],
    "start": "15646822873784630",
    "end": "15645905639093361",
}