Message Actions API for Python SDK

Message actions let a PubNub client for Python add or remove metadata on published messages, such as receipts and reactions. A client that subscribes to a channel receives message action events through an event listener. A client also fetches past message actions from Message Persistence, either separately or together with the original messages.

For the concepts behind message actions, see Message actions.

Request execution and return values

You can decide whether to perform the Python SDK operations synchronously or asynchronously.

  • .sync() returns an Envelope object, which has two fields: Envelope.result, whose type differs for each API, and Envelope.status of type PnStatus.

    1pubnub.publish() \
    2 .channel("myChannel") \
    3 .message("Hello from PubNub Python SDK") \
    4 .sync()
  • .pn_async(callback) returns None and passes the values of Envelope.result and Envelope.status to a callback you must define beforehand.

    1def my_callback_function(result, status):
    2 print(f'TT: {result.timetoken}, status: {status.category.name}')
    3
    4pubnub.publish() \
    5 .channel("myChannel") \
    6 .message("Hello from PubNub Python SDK") \
    7 .pn_async(my_callback_function)

Add message action​

add_message_action() adds an action to a published message through a PubNub client for Python and returns the added action.

required
channel required#
Type: str
Default: no default
The ID of the channel that stores the target message. An empty value is invalid. An empty value fails validation with the message Channel missing.
message_action required#
Type: PNMessageAction
Default: no default
The message action to add, a PNMessageAction object with the type, value and message_timetoken attributes set. A missing object fails validation with the message Message action is missing.
property of message_action: type required#
Type: str
Default: no default
The type of the message action, a string that names the kind of metadata, such as reaction or receipt. An empty value is invalid. An empty value fails validation with the message Message action type is missing.
property of message_action: value required#
Type: str
Default: no default
The value of the message action, a string that carries the metadata, such as smiley_face or read. An empty value is invalid. An empty value fails validation with the message Message action value is missing.
property of message_action: message_timetoken required#
Type: int or str
Default: no default
The timetoken of the published message to add the action to. A missing value fails validation with the message Message timetoken is missing.

Returns​

The method returns an Envelope. Its result property is a PNAddMessageActionResult that holds the added message action, and its status property is a PNStatus.

result#
Type: PNAddMessageActionResult
The added message action.
property of result: type#
Type: str
The type that the request set.
property of result: value#
Type: str
The value that the request set.
property of result: uuid#
Type: str
The User ID of the client that added the action.
property of result: action_timetoken#
Type: str
The timetoken at which PubNub stored the action. Pass it to remove_message_action() to remove the action.
property of result: message_timetoken#
Type: str
The timetoken of the message that has the action.
status#
Type: PNStatus
The operation status.

PNMessageAction​

A PNMessageAction object describes one message action. You build one to add an action, and the SDK returns a list of them when you get message actions.

AttributeTypeDescription
typestrThe kind of metadata, such as reaction or receipt.
valuestrThe metadata itself, such as smiley_face or read.
message_timetokenint or strThe timetoken of the message that has the action.
uuidstrThe User ID of the client that added the action. Set on objects that the SDK returns.
action_timetokenstrThe timetoken at which PubNub stored the action. Set on objects that the SDK returns.

Create an object from a dictionary that holds the camelCase keys of the REST API response.

Syntax

1pubnub.add_message_action() \
2 .channel(channel: str) \
3 .message_action(message_action: PNMessageAction) \
4 .sync() -> PNAddMessageActionResultEnvelope

Remove message action​

remove_message_action() removes an action from a published message through a PubNub client for Python.

required
channel required#
Type: str
Default: no default
The ID of the channel that stores the message with the action. An empty value is invalid. An empty value fails validation with the message Channel missing.
message_timetoken required#
Type: int
Default: no default
The timetoken of the published message that has the action. A missing value fails validation with the message Message timetoken is missing.
action_timetoken required#
Type: int
Default: no default
The timetoken of the message action to remove. The add operation returns this timetoken when it stores the action. A missing value fails validation with the message Message action timetoken is missing.

Returns​

The method returns an Envelope.

result#
Type: dict
An empty dictionary.
status#
Type: PNStatus
The operation status.

Syntax

1pubnub.remove_message_action() \
2 .channel(channel: str) \
3 .message_timetoken(message_timetoken: int) \
4 .action_timetoken(action_timetoken: int) \
5 .sync() -> Envelope

Get message actions​

get_message_actions() gets the stored message actions of a channel through a PubNub client for Python, within an optional range of action timetokens.

The response lists message actions in ascending order of their action timetokens, oldest first. PubNub can return fewer message actions than the requested range holds when the request reaches an internal limit. To fetch the rest, send another request with adjusted start and end values. The Python result exposes only the actions list and no more value.

required
channel required#
Type: str
Default: no default
The ID of the channel to get message actions for. An empty value is invalid. An empty value fails validation with the message Channel missing.
start#
Type: str
Default: no default
The newer boundary of the range, as an action timetoken. The range is exclusive, so the response includes only actions with a lower timetoken. When you set both start and end, start must be the higher value.
end#
Type: str
Default: no default
The older boundary of the range, as an action timetoken. The range is inclusive, so the response includes actions with a timetoken equal to or higher than end. The SDK sends end together with start.
limit#
Type: str
Default: "100"
The number of message actions to return in one response. The SDK takes the limit as a string, for example "50", and sends it only when it differs from the default.

Returns​

The method returns an Envelope. Its result property is a PNGetMessageActionsResult.

result#
Type: PNGetMessageActionsResult
The result of the request.
property of result: actions#
Type: list of PNMessageAction
The message actions in the range.
status#
Type: PNStatus
The operation status.

Syntax

1pubnub.get_message_actions() \
2 .channel(channel: str) \
3 .start(start: str) \
4 .end(end: str) \
5 .limit(limit: str) \
6 .sync() -> PNGetMessageActionsResultEnvelope

Was this page useful?

Last updated on