Message Reactions allow users to send back an emoji reaction (for example, a thumbs up or a smiley face) or a custom reaction on a message that they received. These reactions are typically visible to all users in the chat room and displayed with the original message.
There are two main types of message reactions:
- Emoji reactions to a message, such as thumbs up or smiley face
- Custom reactions to attach state information to a message, such as completed, reviewed, or approved
Adding a reaction to a message
addMessageAction() to add a reaction to a message in a channel. You can use the method to add an emoji reaction to a message or to add any custom reaction as long as it's a string.
You need to provide your own emoji library; this isn't included in the PubNub SDKs.
Receiving reaction events
When you add a reaction, an event is published to all users in the channel so they can instantly show the reaction on the message. Your application should be set up with the message actions listener to receive these events.
Fetching reactions from storage
getMessageActions() to fetch reactions in a channel from storage using start and end timestamps. Use this method when the user returns to the application, to fetch new reactions that were added after a certain timestamp.
Getting messages with reactions
includeMessageActions flag (or
fetchActions in Swift) with the
fetchMessages() method to fetch past messages in a channel along with reactions that were added to those messages.
To fetch the 25 most recent messages in a channel, fetch messages with neither the
start nor the
end parameter. If there are more than 25 messages to be fetched, you can iterate through the message history by adjusting the
end timetokens to page through the full set of results.
Start and end parameters
Messages are always returned in chronological order — from oldest to newest — within the timetoken range you request.
If you specify only the
start parameter (without
end), you will receive messages older than the start timetoken value.
If you specify only the
end parameter (without
start), you will receive messages from the last (most recent) message going back to that timetoken value.
Specify values for both
end to retrieve messages between those timetokens (inclusive of the end value).
Removing a reaction from a message
removeMessageAction() to remove a reaction from a message. A reaction can only be removed by the user who added the reaction.