logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Respond to messages with emoticons


Overview

An emoticon response to a message indicates how a user responds to a message. The emoticon response feature is usually used to respond to a message in a private chat or group chat by adding an emoticon response to or removing an emoticon response from the message. Further, the emoticon response feature can be used in scenarios such as group voting and group voting result confirmation.

Note

The preceding figure shows merely a UI example of an emoticon response. ZEGO Instant Messaging (ZIM) SDK does not provide aesthetics resources for emoticon responses. You must add aesthetics resources as needed.

Procedure

ZIM SDK allows you to respond to a specific message in a private chat or group chat. The procedure is described in the following figure, in which a client B responds to a message from a client A by adding an emoticon response to or removing an emoticon response from the message.

  1. The client A and the client B each create a ZIM instance and register the messageReactionsChanged callback of the ZIMEventHandler class to listen to emoticon response changes.
  2. The client A and the client B log in to ZIM SDK.
  3. The client A sends a private-chat message to the client B, and the client B adds an emoticon response to the message.
    1. The client B calls the addMessageReaction operation and set the reactionType and message parameters to specify the message to which an emoticon response is added.
    2. The client B obtains the addition result by invoking the ZIMMessageReactionAddedCallback callback.
    3. The client A receives a notification about an emoticon response change by invoking the messageReactionsChanged callback.
  4. The client B removes the preceding emoticon response.
    1. The client B calls the deleteMessageReaction operation and set the reactionType and message parameters to specify the message whose emoticon response is to be removed.
    2. The client B obtains the removal result by invoking the ZIMMessageReactionDeletedCallback callback.
    3. The client A receives a notification about an emoticon response change by invoking the messageReactionsChanged callback.

1. Listen to an emoticon response change

After a user creates a ZIM instance, the user must register the messageReactionsChanged callback of the ZIMEventHandler class to listen to emoticon response changes. This way, when other users add emoticon responses to or remove emoticon responses from a specific message, the user that registers the onMessageReactionsChanged callback can obtain relevant emoticon response information, such as the types of the emoticon responses and the number of users who add emoticon responses or remove emoticon responses. In general, this callback can return information about a maximum of five users. For more user information details, see the "Query details of emoticon responses" section of the Respond to messages with emoticons topic.

Untitled
// Received message with emoticons callback.
- (void)zim:(ZIM *)zim messageReactionsChanged:(NSArray<ZIMMessageReaction *> *)reactions;
1
Copied!

2. Add an emoticon response

You can call the addMessageReaction operation to add an emoticon response to any message sent in a private chat or a group chat. You can obtain the addition result by invoking the ZIMMessageReactionAddedCallback callback. In general, this Result can return information about a maximum of five users. For more user information details, see the "Query details of emoticon responses" section of the Respond to messages with emoticons topic.

Note
  • If you repeatedly call this operation to add emoticon responses to the same message, an error may occur.

  • By default, a maximum of 100 types of emoticon responses can be given to a message. To expand the upper limit, contact ZEGO technical support.

Sample code
// Add an emoticon response.
NSString* reactionType = @"key";

[zim addMessageReaction:reactionType message:message callback:^(ZIMMessageReaction * _Nonnull reaction, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == 0){
        // The operation is successful.
    }
    else{
        // The operation fails.
    }
}];
1
Copied!

3. Remove an emoticon response

After you add an emoticon response to a message, you can call the deleteMessageReaction operation to remove the emoticon response. You can obtain the removal result by invoking the ZIMMessageReactionDeletedCallback callback. In general, this Callback can return information about a maximum of five users. For more user information details, see the "Query details of emoticon responses" section of the Respond to messages with emoticons topic.

Note

You can call this operation to remove an emoticon response that you added.

Sample code
// Remove an emoticon response.
NSString* reactionType = @"key";

[zim deleteMessageReaction:reactionType message:message callback:^(ZIMMessageReaction * _Nonnull reaction, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == 0){
        //  The operation is successful.
    }
    else{
        //  The operation fails.
    }
}];
1
Copied!

What's more

Query details of emoticon responses

You can query only brief information about the users that listen to, add, and remove emoticon responses. By default, you can query information about a maximum of five users. To expand the upper limit, contact ZEGO technical support. To query specific users who give a specific type of emoticon responses to a specific message, call the queryMessageReactionUserListByMessage operation. You can obtain the operation result by invoking the ZIMMessageReactionUserListQueriedCallback callback.

Sample code
// Query details of emoticon responses.
ZIMMessageReactionUserQueryConfig *config = [[ZIMMessageReactionUserQueryConfig alloc] init];
config.nextFlag = 0;
config.reactionType = @"key";
config.count = 20;

[zim queryMessageReactionUserListByMessage:message config:config callback:^(ZIMMessage * _Nonnull message, NSArray<ZIMMessageReactionUserInfo *> * _Nonnull userList, NSString * _Nonnull reactionType, long long nextFlag, int totalCount, ZIMError * _Nonnull errorInfo) {
    if(errorInfo.code == 0){
        // The operation is successful.
    }
    else{
        // The operation fails.
    }
}];
1
Copied!

Previous

Search for local messages

Next

Export and import messages