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 action events on that channel. They can also fetch past message actions from Message Persistence independently or when they fetch original messages.

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 action, 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
)
ParameterTypeRequiredDefaultDescription
channelStringYesName of channel which stores the message for which action should be added.
typeStringYesWhat feature this message action represents. Maximum 15 characters.
valueStringYesValue to be added with message action type.
message_timetokenIntegerYesTimetoken of message to which action should be added.
http_syncBooleanOptionalfalseIf set to true, this method is executed synchronously and returns an array of envelopes (even if there's only one envelope).
callbackLambda accepting one parameterOptionalThe 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 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 Ruby SDK:

remove_message_action(
channel: channel,
message_timetoken: message_timetoken,
action_timetoken: action_timetoken,
http_sync: http_sync,
callback: callback
)
ParameterTypeRequiredDefaultDescription
channelStringYesName of channel which store message for which action should be removed.
message_timetokenIntegerYesTimetoken of message to which action should be removed.
action_timetokenIntegerYesMessage action addition timetoken.
http_syncBooleanOptionalfalseIf set to true, this method is executed synchronously and returns an array of envelopes (even if there's only one envelope).
callbackLambda accepting one parameterOptionalThe 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 actions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

Method(s)

To get message actions, 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
)
ParameterTypeRequiredDefaultDescription
channelStringYesName of channel from which list of message actions should be retrieved.
startIntegerOptionalReturn values will be less than start.
endIntegerOptionalReturn values will be greater than or equal to end.
limitIntegerOptionalNumber of messages actions to return in response.
http_syncBooleanOptionalfalseIf set to true, this method is executed synchronously and returns an array of envelopes (even if there's only one envelope).
callbackLambda accepting one parameterOptionalThe 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
Last updated on