PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

tornado

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support
  • Reconnection Policies

Message Actions API for PubNub Python-Tornado SDK

Python version support

Python SDK versions 5.0.0 and higher no longer support Python v2.7 and the Twisted and Tornado frameworks. If you require support for any of these, use SDK version 4.8.1.

Note that PubNub will stop supporting versions of Python lower than 3.7 by the end of 2021.

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.

Add Message Action

Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

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 Python-Tornado SDK:

  1. pubnub.add_message_action()\  .channel(String channel)\  .message_action(PNMessageAction message_action)\  .pn_async(Function message_action_callback)
    
    ParameterTypeRequiredDescription
    channelStringYesThe channel name to which to add the message action
    message_actionPNMessageActionYesMessage action information
    message_action.typeStringYesWhat feature this message action represents
    message_action.valueStringYesValue to be stored along with the message action
    message_action.message_timetokenIntegerYesTimetoken of the message to which to add the action
    message_action_callbackFunctionYesHandles returned data for successful and unsuccessful add message action operations. Details on the callback are here

Basic Usage

msg_action = PNMessageAction()
msg_action.type = "reaction"
msg_action.value = "smiley_face"
msg_action.message_timetoken = str(int(time.time()))

pubnub.add_message_action()\
  .channel("chats.room1")\
  .message_action(msg_action)\
  .pn_async(message_action_callback)

Returns

# Example of status
{
  'affected_channels': None,
  'affected_channels_groups': None,
  'affected_groups': None,
  'auth_key': None,
  'category': 2,
  'client_response': None,
  'error': None,
  'error_data': None,
  'operation': 42,
  'origin': 'ps.pndsn.com',
  'status_code': 200,
  'tls_enabled': True,
  'uuid': 'my_uuid'
}

# Example of envelope
{
  'action_timetoken': '15956343330507960',
  'message_timetoken': '1595634332',
  'type': 'reaction',
  'uuid': 'my_uuid',
  'value': 'smiley_face'
}

Remove Message Action

Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

Remove a peviously 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 JavaScript SDK:

  1. pubnub.remove_message_action()\  .channel(String channel)\  .action_timetoken(Integer action_timetoken)\  .message_timetoken(Integer message_timetoken)\  .pn_async(message_action_callback)
    
    ParameterTypeRequiredDescription
    channelStringYesThe channel name from which to remove the message action
    action_timetokenIntegerYesTimetoken of the message action to be removed
    message_timetokenIntegerYesTimetoken of the message from which to remove the action
    message_action_callbackFunctionYesHandles returned data for successful and unsuccessful remove message action operations. Details on the callback are here

Basic Usage

pubnub.remove_message_action()\
  .channel("chats.room1")\
  .action_timetoken(15956346328442840)\
  .message_timetoken(1595634632)\
  .pn_async(message_action_callback)

Returns

# Example of status
{
  'affected_channels': None,
  'affected_channels_groups': None,
  'affected_groups': None,
  'auth_key': None,
  'category': 2,
  'client_response': None,
  'error': None,
  'error_data': None,
  'operation': 44,
  'origin': 'ps.pndsn.com',
  'status_code': 200,
  'tls_enabled': True,
  'uuid': 'my_uuid'
}

# Example of envelope in case of success (empty object)
{}

Get Message Actions

Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-

Description

Get a list of message actions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

Method(s)

To Get Message Actions you can use the following method(s) in the Python-Tornado SDK:

  1. pubnub.get_message_actions()\  .channel(String channel)\  .start(String start)\  .end(String end)\  .limit(Integer limit)\  .pn_async(message_action_callback)
    
    ParameterTypeRequiredDescription
    channelStringYesThe channel name for which to retrieve the list of message actions
    startStringNoMessage action timetoken denoting the start of the range requested. Return values will be less than start. If not specified, defaults to the current time.
    endStringNoMessage action timetoken denoting the end of the range requested. Return values will be greater than or equal to end. If start is specified, end must be less than or equal to start.
    limitIntegerNoMaximum number of message actions to return in the response. If the number of results exceeds this limit, the results will include a more token. Refer to the REST API documentation for details.
    message_action_callbackFunctionYesHandles returned data for successful and unsuccessful retrieve message action operations. Details on the callback are here

Basic Usage

# Retrieve all reactions on a single message

pubnub.get_message_actions()\
  .channel("chats.room1")\
  .start("15956342921084731")\
  .end("15956342921084730")\
  .limit(50)\
  .pn_async(message_action_callback)

Returns

# Example of status
{
  'affected_channels': None,
  'affected_channels_groups': None,
  'affected_groups': None,
  'auth_key': None,
  'category': 2,
  'client_response': None,
  'error': None,
  'error_data': None,
  'operation': 43,
  'origin': 'ps.pndsn.com',
  'status_code': 200,
  'tls_enabled': True,
  'uuid': 'my_uuid'
}

# Example of envelope
{
  'actions': [
    {
      'actionTimetoken': '15956373593404068',
      'messageTimetoken': '15956342921084730',
      'type': 'reaction',
      'uuid': 'my_uuid',
      'value': 'smiley_face'
    }
  ]
}
← Mobile PushMiscellaneous →
  • Add Message Action
    • Description
    • Method(s)
    • Basic Usage
    • Returns
  • Remove Message Action
    • Description
    • Method(s)
    • Basic Usage
    • Returns
  • Get Message Actions
    • Description
    • Method(s)
    • Basic Usage
    • Returns
© PubNub Inc. - Privacy Policy