Style One | |
Style Two | |
addMessageReaction
API to add an emoji to a message. After a successful addition, the information of the user who performed the operation will be stored under the emoji.removeMessageReaction
API to delete an already added emoji. After successful deletion, the information of the user who performed the operation will no longer be stored under the emoji.getMessageReactions
API to batch pull the emoji list of multiple messages, where each emoji includes the total number of users currently using it and the profiles of the first N (default 10) users.getAllUserListOfMessageReaction
API to paginate and pull the full list of user profiles for users of a message emoji.TencentCloudChat.EVENT.MESSAGE_REACTIONS_UPDATE
event to detect changes in the user information of emoji users. This event will carry the latest user information of the emoji (including the total number of users and the profiles of the first N users).chat.addMessageReaction(message, reactionID);
Attribute | Meaning | Description |
message | Message object | The message must be sent successfully. |
reactionID | Message reaction ID | In emoji reaction scenarios, the reactionID is the emoji ID. |
Promise
let promise = chat.addMessageReaction(message, 'smile');promise.then(function(imResponse) {// Message reaction was added successfully.}).catch(function(imError) {// Failed to add message reaction.console.warn('addMessageReaction error:', imError);});
chat.removeMessageReaction(message, reactionID);
Attribute | Meaning | Description |
message | Message object | The message must be sent successfully. |
reactionID | Message reaction ID | In emoji reaction scenarios, the reactionID is the emoji ID. |
Promise
let promise = chat.removeMessageReaction(message, 'smile');promise.then(function(imResponse) {// Message reaction was deleted successfully.}).catch(function(imError) {// Failed to delete message reaction.console.warn('removeMessageReaction error:', imError);});
chat.getMessageReactions(options);
Attribute | Meaning | Description |
messageList | Message list | Messages must belong to the same session and must be sent successfully. |
maxUserCountPerReaction | The maximum number of user profiles returned for each reaction | The value range is from 0 to 10. Each reaction returns the profiles of up to the first 10 users only. For more user profiles, you can call the getAllUserListOfMessageReaction API as needed for paginated pulling. |
Promise
let promise = chat.getMessageReactions({messageList: [message1, message2],maxUserCountPerReaction: 10,});promise.then(function(imResponse) {// Batch pulling succeeded.const resultList = imResponse.data;resultList.forEach((item) => {const { messageID, reactionList } = item;// The information returned by reactionList is as follows:// reactionID - Message reaction ID// totalUserCount - Total number of users who reacted with the same reactionID// partialUserList - A partial list of users with the same reactionID, including user's userID, nick, and avatar information});}).catch(function(imError) {// Batch pulling failed.console.warn('getMessageReactions error:', imError);});
chat.getAllUserListOfMessageReaction(options);
Attribute | Meaning | Description |
message | Message object | The message must be sent successfully. |
reactionID | Message reaction ID | In emoji reaction scenarios, the reactionID is the emoji ID. |
nextSeq | Paginated pulling cursor | For the first time, pass 0, and then for later pages, pass the nextSeq returned by succ. |
count | Maximum number of items that can be pulled in a single page | Supports up to 100. |
Promise
let promise = chat.getAllUserListOfMessageReaction({message: message,reactionID: 'smile',nextSeq: 0,count: 100,});promise.then(function(imResponse) {// Obtained successfully.const { userList, nextSeq, isCompleted } = imResponse.data;// userList - User information list, including user's userID, nick, and avatar information// nextSeq - This field must be passed in for the next page.// isCompleted - Indicates whether all user information has been pulled. When isCompleted is true, nextSeq is 0.}).catch(function(imError) {// Failed to obtain.console.warn('getAllUserListOfMessageReaction error:', imError);});
let onMessageReactionsUpdated = function(event) {const { messageID, reactionList } = event.data;// messageID - Message ID// reactionList - Message reaction update listreactionList.forEach((item) => {const { reactionID, totalUserCount, partialUserList } = item;// reactionID - Message reaction ID// totalUserCount - Total number of users who reacted with the same reactionID// partialUserList - A partial list of users with the same reactionID});};chat.on(TencentCloudChat.EVENT.MESSAGE_REACTIONS_UPDATED, onMessageReactionsUpdated);
Was this page helpful?