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.
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.
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 the support article.
Add an action to a published message. The response includes the added action.
Method(s)
Use this Java method:
this.pubnub.addMessageAction()
.channel(String)
.messageAction(PNMessageAction);
Parameter | Description |
---|---|
channel *Type: String | Channel name to add the message action to. |
messageAction *Type: PNMessageAction | Message action payload (type, value, message timetoken). |
async *Type: Consumer<Result> | Callback of type PNAddMessageActionResult . |
Sample code
Reference code
Returns
The addMessageAction()
operation returns a PNAddMessageActionResult
:
Method | Description |
---|---|
getType() Type: String | Message action type. |
getValue() Type: String | Message action 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 message was created that the action belongs to. |
PNMessageAction
Method | Description |
---|---|
setType() Type: String | Message action type. |
setValue() Type: String | Message action value. |
setMessageTimetoken() 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 the support article.
Remove a previously added action from a published message. The response is empty.
Method(s)
Use this Java method:
this.pubnub.removeMessageAction()
.channel(String)
.messageTimetoken(Long)
.actionTimetoken(Long);
Parameter | Description |
---|---|
channel *Type: String | Channel name to remove the message action from. |
messageTimetoken *Type: Long | Timetoken of the target message. |
actionTimetoken *Type: Long | Timetoken of the message action to remove. |
async *Type: Consumer<Result> | Callback of type PNRemoveMessageActionResult . |
Sample code
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 the support article.
Get a list of message actions in a channel. The response sorts actions by the action timetoken in ascending order.
Truncated response
The number of message actions in the response may be truncated when internal limits are hit. If the response is truncated, a more
property is returned with additional parameters. Send iterative calls to Message Persistence, adjusting the parameters to fetch more message actions.
Method(s)
Use this Java method:
this.pubnub.getMessageActions()
.channel(String)
.start(Long)
.end(Long)
.limit(Integer);
Parameter | Description |
---|---|
channel *Type: String Default: n/a | Channel name to list message actions for. |
start Type: Long Default: n/a | Message action timetoken for the start of the range (exclusive). |
end Type: Long Default: n/a | Message action timetoken for the end of the range (inclusive). |
limit Type: Integer Default: 100 | Maximum number of actions to return. Default/Maximum is 100 . |
async *Type: Consumer<Result> Default: n/a | Callback of type PNGetMessageActionsResult . |
Sample code
Returns
The getMessageActions()
operation returns a list of PNGetMessageActionsResult
objects:
Method | Description |
---|---|
getType() Type: String | Message action type. |
getValue() Type: String | Message action 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 message was created that the action belongs to. |
Other examples
Fetch messages with paging