Add a Reaction
CalladdReaction() with a message ID and an emoji string.
- TypeScript
- JavaScript
Remove a Reaction
CallremoveReaction() with the same message ID and emoji.
- TypeScript
- JavaScript
addReaction() and removeReaction() return a BaseMessage object with the updated reactions.
Read Reaction Data from a Message
AnyBaseMessage exposes reaction data through two methods:
Get All Reactions
UsegetReactions() to retrieve the list of reactions on a message. Returns an array of ReactionCount objects, or an empty array if no one has reacted.
- TypeScript
- JavaScript
Check if the Logged-in User Has Reacted
CallgetReactedByMe() on any ReactionCount object to check whether the logged-in user has reacted with that particular emoji. Returns true if they have, false otherwise.
- TypeScript
- JavaScript
Fetch Reactions for a Message
To get the full list of who reacted with what on a specific message, useReactionRequestBuilder. You can paginate through results with fetchNext() and fetchPrevious() (max 100 per request).
| Builder Method | Description |
|---|---|
setMessageId(value) | The message ID to fetch reactions for. Required. |
setReaction(value) | Filter to a specific emoji (e.g., "😊"). When set, only reactions matching this emoji are returned. |
setLimit(value) | Number of reactions to fetch per request. Max 100. |
Fetch Next
- TypeScript
- JavaScript
fetchNext() method returns an array of Reaction objects representing individual user reactions on the message.
Fetch Previous The fetchPrevious() method fetches the previous set of reactions for the message.
- TypeScript
- JavaScript
Fetch Previous
- TypeScript
- JavaScript
Real-Time Reaction Events
Register aMessageListener to receive reaction events as they happen. This is how you keep your UI in sync when other users add or remove reactions.
- TypeScript
- JavaScript
ReactionEvent object.
Remove the Listener
- TypeScript
- JavaScript
Update a Message with Reaction Info
When you receive a real-time reaction event, you’ll want to update the corresponding message object so your UI reflects the change.updateMessageWithReactionInfo() does this — it takes the BaseMessage instance, the MessageReaction event data, and the action type, then returns the updated message.
- TypeScript
- JavaScript
getReactions() method returns an array of ReactionCount objects, each containing the reaction emoji, the total count of users who reacted with it, and whether the logged-in user used that reaction.
Check if Logged-in User has Reacted on Message
To check if the logged-in user has reacted on a particular message or not, You can use thegetReactedByMe() method on any ReactionCount object instance. This method will return a boolean value, true if the logged-in user has reacted on that message, otherwise false.
- TypeScript
- JavaScript
getReactedByMe() method on a ReactionCount object returns a boolean — true if the logged-in user has reacted with that specific emoji, false otherwise.
Update Message With Reaction Info
When a user adds or removes a reaction, you will receive a real-time event. Once you receive the real time event you would want to update the message with the latest reaction information. To do so you can use theupdateMessageWithReactionInfo() method.
The updateMessageWithReactionInfo() method provides a seamless way to update the reactions on a message instance (BaseMessage) in real-time. This method ensures that when a reaction is added or removed from a message, the BaseMessage object’s getReactions() property reflects this change immediately.
When you receive a real-time reaction event (MessageReaction), call the updateMessageWithReactionInfo() method, passing the BaseMessage instance (message), event data (MessageReaction) and reaction event action type (CometChat.REACTION_ACTION.REACTION_ADDED or CometChat.REACTION_ACTION.REACTION_REMOVED) that corresponds to the message being reacted to.
- TypeScript
- JavaScript
BaseMessage object
After calling this method, use modifiedBaseMessage.getReactions() to get the latest reactions and refresh your UI.
| Parameter | Type | Description |
|---|---|---|
message | BaseMessage | The message object to update |
messageReaction | MessageReaction | The reaction event received from the listener |
action | REACTION_ACTION | CometChat.REACTION_ACTION.REACTION_ADDED or CometChat.REACTION_ACTION.REACTION_REMOVED |
Next Steps
Send Messages
Send text, media, and custom messages to users and groups
Receive Messages
Listen for incoming messages in real-time and fetch missed messages
Mentions
Mention specific users in messages
Threaded Messages
Organize conversations with message threads