Message Actions API for Kotlin SDK

Breaking changes in v9.0.0

PubNub Kotlin SDK version 9.0.0 unifies the codebases for Kotlin and Java SDKs, introduces a new way of instantiating the PubNub client, and changes asynchronous API callbacks and emitted status events. These changes can impact applications built with previous versions (< 9.0.0 ) of the Kotlin SDK.

For more details about what has changed, refer to Java/Kotlin SDK migration guide.

Use message actions to add or remove metadata on published messages. Common uses include receipts and reactions. Clients subscribe to a channel to receive message action events. Clients can also fetch past message actions from Message Persistence, either on demand or when fetching original messages.

Request execution

Most PubNub Kotlin SDK method invocations return an Endpoint object, which allows you to decide whether to perform the operation synchronously or asynchronously.

You must invoke the .sync() or .async() method on the Endpoint to execute the request, or the operation will not be performed.

1val channel = pubnub.channel("channelName")
2
3channel.publish("This SDK rules!").async { result ->
4 result.onFailure { exception ->
5 // Handle error
6 }.onSuccess { value ->
7 // Handle successful method result
8 }
9}
Reactions

"Message Reactions" is a specific application of the Message Actions API for emoji or social reactions.

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 action​

Requires Message Persistence

Enable Message Persistence for your key in the Admin Portal as described in Enable the features your app calls.

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

Method(s)​

Use this Kotlin method:

1pubnub.addMessageAction(
2 channel: String,
3 messageAction: PNMessageAction
4).async { result -> }
required
channel required#
Type: String
Channel name to add the message action to.
messageAction required#
Type: PNMessageAction
Message action payload (type, value, message timetoken).

Sample code​

1

Returns​

The addMessageAction() operation returns a PNAddMessageActionResult:

type#
Type: String
Message action type.
value#
Type: String
Message action value.
uuid#
Type: String
Publisher of the message action.
actionTimetoken#
Type: String
Timestamp when the message action was created.
messageTimetoken#
Type: Long
Timestamp when the message was created that the action belongs to.

PNMessageAction​

type#
Type: String
Message action type.
value#
Type: String
Message action value.
messageTimetoken#
Type: Long
Timetoken of the target message.

Remove message action​

Requires Message Persistence

Enable Message Persistence for your key in the Admin Portal as described in Enable the features your app calls.

Remove a previously added action from a published message. The response is empty.

Method(s)​

Use this Kotlin method:

1pubnub.removeMessageAction(
2 channel: String,
3 messageTimetoken: Long,
4 actionTimetoken: Long
5).async { result -> }
required
channel required#
Type: String
Channel name to remove the message action from.
messageTimetoken required#
Type: Long
Timetoken of the target message.
actionTimetoken required#
Type: Long
Timetoken of the message action to remove.

Sample code​

1

Returns​

The removeMessageAction() operation returns no actionable data.

Get message actions​

Requires Message Persistence

Enable Message Persistence for your key in the Admin Portal as described in Enable the features your app calls.

Get a list of message actions in a channel. The response sorts actions by the action timetoken in ascending order.

How to use the start and end parameters

PubNub retrieves messages by searching backward through time (newest to oldest). Because of this, the parameter names are the reverse of their intuitive meaning:

  • start is the newer boundary (higher timetoken value) - search begins here, exclusive
  • end is the older boundary (lower timetoken value) - search stops here, inclusive

When you provide both parameters, start must be a higher timetoken than end.

9:00 AM10:00 AM11:00 AM11:59 AM

Results are always returned in oldest-first order.

Method(s)​

Use this Kotlin method:

1pubnub.getMessageActions(
2 channel: String,
3 page: PNBoundedPage
4)
required
channel required#
Type: String
Channel name to list message actions for.
page#
Type: PNBoundedPage
Paging object. Set limit to specify the number of actions to return (default/maximum is 100). Set start to the newer boundary (exclusive) and end to the older boundary (inclusive). start must be a higher timetoken than end when both are provided.

Sample code​

1

Returns​

The getMessageActions() operation returns a list of PNGetMessageActionsResult? objects:

type#
Type: String
Message action type.
value#
Type: String
Message action value.
uuid#
Type: String
Publisher of the message action.
actionTimetoken#
Type: String
Timestamp when the message action was created.
messageTimetoken#
Type: Long
Timestamp when the message was created that the action belongs to.
page#
Type: PNBoundedPage
If present, more data is available. Pass it to another getMessageActions call to retrieve remaining data.

Other examples​

Fetch messages with paging​

1

Was this page useful?

Last updated on