Message Reactions API for PubNub Ruby SDK
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 reaction events on that channel. They can also fetch past message reactions from Message Persistence independently or when they fetch original messages.
Terminology
All message reactions in code are collectively called message reactions in the docs and the term applies both to reacting to a message (through emojis) and acting on a message (by deleting it).
Add Message Reaction
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Add an action on a published message
. Returns the added action in the response.
Method(s)
To add a message reaction, you can use the following method(s) in the Ruby SDK:
add_message_action(
channel: channel,
type: type,
value: value,
message_timetoken: message_timetoken,
http_sync: http_sync,
callback: callback
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Name of channel which stores the message for which action should be added. | |
type | String | Yes | What feature this message reaction represents. Maximum 15 characters. | |
value | String | Yes | Value to be added with message reaction type. | |
message_timetoken | Integer | Yes | Timetoken of message to which reaction should be added. | |
http_sync | Boolean | Optional | false | If set to true , this method is executed synchronously and returns an array of envelopes (even if there's only one envelope ). |
callback | Lambda accepting one parameter | Optional | The callback that's called for each envelope. For async methods, a Future is returned. To retrieve the value of the envelope object, you have to call the value method (the thread is locked until the value is returned). |
Basic Usage
pubnub.add_message_action(
channel: 'chat',
type: 'emotion',
value: 'smile',
message_timetoken: 16701562382648731
) do |envelope|
puts envelope
end
Response
#<Pubnub::Envelope
@result = {
:data => {
:type => "emotion",
:value => "smile",
:uuid => "sender-uuid",
:action_timetoken => 16701656660127890,
:message_timetoken => 16701562382648731
}
},
@status = {
:code => 200
}
>
Remove Message Reaction
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Remove a previously added reaction on a published message
. Returns an empty response.
Method(s)
To remove a message reaction, you can use the following method(s) in the Ruby SDK:
remove_message_action(
channel: channel,
message_timetoken: message_timetoken,
action_timetoken: action_timetoken,
http_sync: http_sync,
callback: callback
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Name of channel which store message for which reaction should be removed. | |
message_timetoken | Integer | Yes | Timetoken of message to which reaction should be removed. | |
action_timetoken | Integer | Yes | Message reaction addition timetoken. | |
http_sync | Boolean | Optional | false | If set to true , this method is executed synchronously and returns an array of envelopes (even if there's only one envelope ). |
callback | Lambda accepting one parameter | Optional | The callback that's called for each envelope. For async methods, a Future is returned. To retrieve the value of the envelope object, you have to call the value method (the thread is locked until the value is returned). |
Basic Usage
pubnub.add_message_action(
channel: 'chat',
message_timetoken: 16701562382648731,
action_timetoken: 16701656660127890
) do |envelope|
puts envelope
end
Response
#<Pubnub::Envelope
@status = {
:code => 200,
:category => :ack,
:error => false,
}
>
Get Message Reactions
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Get a list of message reactions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.
Method(s)
To get message reactions, you can use the following method(s) in the Ruby SDK:
get_message_actions(
channel: channel,
start: start,
end: end,
limit: limit,
http_sync: http_sync,
callback: callback
)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
channel | String | Yes | Name of channel from which list of message reactions should be retrieved. | |
start | Integer | Optional | Return values will be less than start. | |
end | Integer | Optional | Return values will be greater than or equal to end. | |
limit | Integer | Optional | Number of messages actions to return in response. | |
http_sync | Boolean | Optional | false | If set to true , this method is executed synchronously and returns an array of envelopes (even if there's only one envelope ). |
callback | Lambda accepting one parameter | Optional | The callback that's called for each envelope. For async methods, a Future is returned. To retrieve the value of the envelope object, you have to call the value method (the thread is locked until the value is returned). |
Basic Usage
pubnub.get_message_actions(
channel: 'chat',
start: 16701562382648731,
end: 16701562382348728
) do |envelope|
puts envelope
end
Response
#<Pubnub::Envelope
@result = {
:data => {
:message_actions => [
{
:type => "emotion_type_2",
:uuid => "sender-uuid-1",
:value => "surprised",
:message_timetoken => 16703307481706612,
:action_timetoken => 16703307649086202,
},
{
:type => "emotion_type_3",
:uuid => "sender-uuid-2",
:value => "lol",
show all 37 lines