Message Actions API for Java SDK
Breaking changes in v9.0.0
PubNub Java SDK version 9.0.0 unifies the codebases for Java and Kotlin 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 Java SDK.
For more details about what has changed, refer to Java/Kotlin SDK migration guide.
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.
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
This method requires that Message Persistence is enabled for your key in the Admin Portal.
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 Java SDK:
this.pubnub.addMessageAction()
.channel(String)
.messageAction(PNMessageAction);
Parameter | Description |
---|---|
channel *Type: String | Specifies channel name to publish message actions to. |
messageAction *Type: PNMessageAction | The message action object containing the message action's type , value and the publish timetoken of the original message . |
async *Type: Consumer<Result> | Consumer of a Result of type PNAddMessageActionResult . |
Basic Usage
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
Returns
The addMessageAction()
operation returns a PNAddMessageActionResult
which contains the following operations:
Method | Description |
---|---|
getType() Type: String | Message action's type. |
getValue() Type: String | Message action's value. |
getUuid() Type: String | Publisher of the message action. |
getActionTimetoken() Type: Long | Timestamp when the message action was created. |
getMessageTimetoken() Type: Long | Timestamp when the actual message was created the message action belongs to. |
PNMessageAction
Method | Description |
---|---|
setType() Type: String | Message action's type. |
setValue() Type: String | Message action's value. |
setMessageTimetoken() Type: Long | Timestamp of the actual message was created the message action belongs to. |
Remove Message Action
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Remove a previously 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 Java SDK:
this.pubnub.removeMessageAction()
.channel(String)
.messageTimetoken(Long)
.actionTimetoken(Long);
Parameter | Description |
---|---|
channel *Type: String | Specifies channel name to publish message actions to. |
messageTimetoken *Type: Long | Publish timetoken of the original message |
actionTimetoken *Type: Long | Publish timetoken of the message action to be removed. |
async *Type: Consumer<Result> | Consumer of a Result of type PNRemoveMessageActionResult . |
Basic Usage
Returns
The removeMessageAction()
operation returns a no actionable data.
Get Message Actions
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Get a list of message actions in a channel
. Returns a list of actions sorted by the action's timetoken in ascending order.
Truncated response
Number of message actions in the response may be truncated when internal limits are hit. If the response is truncated, a more
property will be returned with additional parameters. Send iterative calls to Message Persistence adjusting the parameters to fetch more message actions.
Method(s)
To Get Message Actions you can use the following method(s) in the Java SDK:
this.pubnub.getMessageActions()
.channel(String)
.start(Long)
.end(Long)
.limit(Integer);
Parameter | Description |
---|---|
channel *Type: String Default: n/a | The channel name. |
start Type: Long Default: n/a | Message Action timetoken denoting the start of the range requested (return values will be less than start ). |
end Type: Long Default: n/a | Message Action timetoken denoting the end of the range requested (return values will be greater than or equal to end ). |
limit Type: Integer Default: 100 | Specifies the number of actions to return in response. Default/Maximum is 100 . |
async *Type: Consumer<Result> Default: n/a | Consumer of a Result of type PNGetMessageActionsResult . |
Basic Usage
Returns
The getMessageActions()
operation returns a list of PNGetMessageActionsResult
objects, each containing the following operations:
Method | Description |
---|---|
getType() Type: String | Message action's type. |
getValue() Type: String | Message action's value. |
getUuid() Type: String | Publisher of the message action. |
getActionTimetoken() Type: Long | Timestamp when the message action was created. |
getMessageTimetoken() Type: Long | Timestamp when the actual message was created the message action belongs to. |
Other Examples
Fetch Messages with paging