For AI agents: see the complete documentation index at /llms.txt.
Message receipts
Updated
Introduces how to use the Agora Chat SDK to implement message receipt functionalities in one-to-one chats and chat groups.
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses ChatManager to provide message receipt. The following are the core methods:
ChatOptions.setRequireAck: Enables message read receipt.ChatOptions.setRequireDeliveryAck: Enables message delivery receipt.ackConversationRead: Sends a conversation read receipt.ackMessageRead: Sends a message read receipt.ackGroupMessageRead: Sends a message read receipt for group chat.
The logic for implementing these receipts are as follows:
-
Message delivery receipts
- The message sender enables delivery receipts by setting
ChatOptions.setRequireDeliveryAckastrue. - After the recipient receives the message, the SDK automatically sends a delivery receipt to the sender.
- The sender receives the delivery receipt by listening for
onMessageDelivered.
- The message sender enables delivery receipts by setting
-
Conversation and message read receipts
- The message sender enables read receipt by setting
ChatOptions.setRequireAckastrue. - After reading the message, the recipient calls
ackConversationReadorackMessageReadto send a conversation or message read receipt. - The sender receives the conversation or message receipt by listening for
onConversationReadoronMessageRead.
- The message sender enables read receipt by setting
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
The message sender sets
setRequireDeliveryAckinChatOptionsastruebefore sending the message:ChatOptions chatOptions = new ChatOptions(); chatOptions.setRequireDeliveryAck(true); ... ChatClient.getInstance().init(mContext, chatOptions); -
Once the recipient receives the message, the SDK triggers
onMessageDeliveredon the message sender's client, notifying the message sender that the message has been delivered to the recipient.// Add a message listener to listen for the receipt message. MessageListener msgListener = new MessageListener() { // Occurs when the message is received. @Override public void onMessageReceived(List messages) { } // Occurs when the message delivery receipt is received @Override public void onMessageDelivered(List message) { } }; // Register a message listener. ChatClient.getInstance().chatManager().addMessageListener(msgListener); // Remove the message listener when it is not used. ChatClient.getInstance().chatManager().removeMessageListener(msgListener);
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
-
Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
ackConversationReadto send a conversation read receipt.// The message receiver calls ackConversationRead to send the conversation read receipt. // This is an asynchronous method. try { ChatClient.getInstance().chatManager().ackConversationRead(conversationId); } catch (ChatException e) { e.printStackTrace(); } -
The message sender listens for message events and receives the conversation read receipt in
onConversationRead.// The message sender calls addConversationListener to listen for conversation events. ChatClient.getInstance().chatManager().addConversationListener(new ConversationListener() { ... @Override // Occurs when the all the messages in the conversation is read. public void onConversationRead(String from, String to) { // Add follow-up logics such as poping up a notification. } });
In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation as 0, and all the other devices receive
onConversationRead. -
-
Message read receipts
To implement the message read receipt, take the following steps:
-
Send a conversation read receipt when the recipient enters the conversation.
// The message receiver calls ackConversationRead to send the conversation read receipt. try { ChatClient.getInstance().chatManager().ackConversationRead(conversationId); }catch (ChatException e) { e.printStackTrace(); } -
When a new message arrives, send the message read receipt and add proper handling logics for the different message types.
ChatClient.getInstance().chatManager().addMessageListener(new MessageListener() { ...... @Override // Occurs when the specified message is received. public void onMessageReceived(List messages) { ...... // Send the message read receipt. sendReadAck(message); ...... } ...... }); // Send the message read receipt. public void sendReadAck(ChatMessage message) { // For messages in one-to-one chat if(message.direct() == ChatMessage.Direct.RECEIVE undefined message.getChatType() == ChatMessage.ChatType.Chat) { ChatMessage.Type type = message.getType(); // For voice, video, and file messages, you need to send the receipt after clicking the files. if(type == ChatMessage.Type.VIDEO || type == ChatMessage.Type.VOICE || type == ChatMessage.Type.FILE) { return; } try { // Call ackMessageRead to send the message read receipt. ChatClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (ChatException e) { e.printStackTrace(); } } } -
The message sender listens for the message receipt:
// The message sender calls addMessageListener to listen for message events. ChatClient.getInstance().chatManager().addMessageListener(new MessageListener() { ...... @Override // Occurs when the specified message is read. public void onMessageRead(List messages) { // Add follow-up logics such as poping up a notification. } ...... });
-
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | All group members | By default, all group members can request read receipts when sending a message. You can contact support@agora.io to grant the permission only to the group owner and administrators. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 200 members | This feature is available only to groups with up to 200 members. If the upper limit is exceeded, no read receipts are returned for the message sent within the group. To increase the upper limit of group member count, you can contact support@agora.io. |
| View the number of read receipts returned for a group message | Message sender | By default, only the message sender can view the number of read receipts returned for a group message (or the number of group members that have returned the read receipts). To allow all group members to view the count, you can contact support@agora.io. |
Follow the steps to implement read receipts for a chat group message:
-
When sending a message, a group member can set whether to require a message read receipt.
// Set setIsNeedGroupAck as true when sending the group message ChatMessage message = ChatMessage.createTextSendMessage(content, to); message.setIsNeedGroupAck(true); -
After the group member reads the chat group message, call
ackGroupMessageReadfrom the group member's client to send a message read receipt.// Send the group message read receipt. public void sendAckMessage(ChatMessage message) { if (!validateMessage(message)) { return; } if (message.isAcked()) { return; } // May a user login from multiple devices, so do not need to send the ack msg. if (ChatClient.getInstance().getCurrentUser().equalsIgnoreCase(message.getFrom())) { return; } try { if (message.isNeedGroupAck() && !message.isUnread()) { String to = message.conversationId(); // do not use getFrom() here String msgId = message.getMsgId(); ChatClient.getInstance().chatManager().ackGroupMessageRead(to, msgId, ((TextMessageBody)message.getBody()).getMessage()); message.setUnread(false); EMLog.i(TAG, "Send the group ack cmd-type message."); } } catch (Exception e) { EMLog.d(TAG, e.getMessage()); } } -
The message sender listens for the message read receipt.
// Occurs when the group message is read. void onGroupMessageRead(List groupReadAcks) { // Add follow-up notifications } -
The message sender can get the detailed information of the read receipt using
asyncFetchGroupReadAcks.// msgId: The message ID. // pageSize: The page size. The value range is [1,50]. // startAckId: The starting receipt ID for query. Set it as null for the first call of the method and the SDK retrieves from the latest receipt. * @return The message receipt list and a cursor. */ ChatClient.getInstance().chatManager().asyncFetchGroupReadAcks(msgId, pageSize, startAckId, new ValueCallBack>() { @Override public void onSuccess(CursorResult value) {// Succeeded in getting the details of the read receipt. } @Override public void onError(int error, String errorMsg) { // Failed to get the details of the read receipt. } });
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses IAgoraChatManager to provide message receipt. The following are the core methods:
AgoraChatOptions.enableRequireReadAck: Enables message read receipt.AgoraChatOptions.enableDeliveryAck: Enables message delivery receipt.ackConversationRead: Sends a conversation read receipt.sendMessageReadAck: Sends a message read receipt.sendGroupMessageReadAck: Sends a message read receipt for group chat.
The logic for implementing these receipts are as follows:
-
Message delivery receipts
- The message sender enables delivery receipts by setting
AgoraChatOptions.enableDeliveryAckasYES. - After the recipient receives the message, the SDK automatically sends a delivery receipt to the sender.
- The sender receives the delivery receipt by listening for
messageDidDeliver.
- The message sender enables delivery receipts by setting
-
Conversation and message read receipts
- The message sender enables read receipt by setting
AgoraChatOptions.enableRequireReadAckasYES. - After reading the message, the recipient calls
ackConversationReadorsendMesageReadAckto send a conversation or message read receipt. - The sender receives the conversation or message receipt by listening for
onConversationReadormessageDidRead.
- The message sender enables read receipt by setting
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
The message sender sets
enableDeliveryAckinAgoraChatOptionsasYESbefore sending the message:options.enableDeliveryAck = YES; -
Once the recipient receives the message, the SDK triggers
messageDidDeliveron the message sender's client, notifying the message sender that the message has been delivered to the recipient.- (void)messagesDidDeliver:(NSArray *)aMessages { } [[AgoraChatClient sharedClient].chatManager removeDelegate:self];
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
- Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
ackConversationReadto send a conversation read receipt.[[AgoraChatClient sharedClient].chatManager ackConversationRead:conversationId completion:nil]; -
The message sender listens for message events and receives the conversation read receipt in
onConversationRead.- (void)onConversationRead:(NSString *)from to:(NSString *)to { // Add handling logics, for example, for refreshing the UI }In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation as 0, and all the other devices receive
onConversationRead.
- Message read receipts
To implement the message read receipt, take the following steps:
-
Send a conversation read receipt when the recipient enters the conversation.
[[AgoraChatClient sharedClient].chatManager sendMessageReadAck:messageId toUser:conversationId completion:nil]; -
When a new message arrives, send the message read receipt and add proper handling logics for the different message types.
// Occurs when the message is received. - (void)messagesDidReceive:(NSArray *)aMessages { for (AgoraChatMessage *message in aMessages) { // Sends a message read receipt [self sendReadAckForMessage:message]; } } - (void)sendReadAckForMessage:(AgoraChatMessage *)aMessage { // The received message if (aMessage.direction == AgoraChatMessageDirectionSend || aMessage.isReadAcked || aMessage.chatType != AgoraChatTypeChat) return; MessageBody *body = aMessage.body; // For audio, video, and file messages, send them after the user clicks the file. if (body.type == MessageBodyTypeFile || body.type == MessageBodyTypeVoice || body.type == MessageBodyTypeImage) return; [[AgoraChatClient sharedClient].chatManager sendMessageReadAck:aMessage.messageId toUser:aMessage.conversationId completion:nil]; } -
The message sender listens for the message receipt:
// Occurs when the message read receipt is received - (void)messagesDidRead:(NSArray *)aMessages { for (AgoraChatMessage *message in aMessages) { // Adds handling logics } }
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | Group owner and administrators | By default, only the group owner and administrators can request read receipts when sending a message. You can contact support@agora.io to grant the permission to regular group members. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 500 members | This feature is available only to groups with up to 500 members. In other words, each message in a group can have up to 500 read receipts. If the upper limit is exceeded, the latest read receipt record will overwrite the earliest one. |
| Maximum number of group messages that can have read receipts per day | 500 | A group can have up to 500 messages each day for which read receipts can be returned. |
Follow the steps to implement read receipts for a chat group message:
-
When sending a message, a group member can set whether to require a message read receipt.
AgoraChatMessage *message = [[AgoraChatMessage alloc] initWithConversationID:to from:from to:to body:aBody ext:aExt]; message.isNeedGroupAck = YES; -
After the group member reads the chat group message, call
sendGroupMessageReadAckfrom the group member's client to send a message read receipt:- (void)sendGroupMessageReadAck:(AgoraChatMessage *)msg { if (msg.isNeedGroupAck && !msg.isReadAcked) { [[AgoraChatClient sharedClient].chatManager sendGroupMessageReadAck:msg.messageId toGroup:msg.conversationId content:@"123" completion:^(AgoraChatError *error) { if (error) { } }]; } } -
The message sender listens for the message read receipt.
// Occurs when the group message is received. - (void)groupMessageDidRead:(AgoraChatMessage *)aMessage groupAcks:(NSArray *)aGroupAcks { for (AgoraChatGroupMessageAck *messageAck in aGroupAcks) { //receive group message read ack } } -
The message sender can get the detailed information of the read receipt using
asyncFetchGroupMessageAcksFromServer.// messageId: The message ID. // pageSize: The page size. The value range is [1,50]. // startGroupAckId: The starting receipt ID for query. Set it as nil or "" for the first call of the method and the SDK retrieves from the latest receipt. [[AgoraChatClient sharedClient].chatManager asyncFetchGroupMessageAcksFromServer:messageId groupId:groupId startGroupAckId:nil pageSize:pageSize completion:^(AgoraChatCursorResult *aResult, AgoraChatError *error, int totalCount) { // Add subsequent logics, for example, refreshing the UI }];
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The message delivery receipts and read receipts are implemented as follows:
-
Message delivery receipt for one-to-one chats
- The message sender enables delivery receipts by setting
deliveryastruewhen creating theconnectionobject during SDK initialization. - A user sends a message.
- After the recipient receives the message, the SDK automatically sends a delivery receipt to the sender.
- The sender receives the delivery receipt by listening for
onDeliveredMessage.
- The message sender enables delivery receipts by setting
-
Conversation and message read receipts for one-to-one chats
- A user sends a message.
- After reading the message, the recipient calls
sendto send a conversation or message read receipt. - The sender receives the conversation or message receipt by listening for
onChannelMessageoronReadMessage.
-
Message read receipt for group chats
- A group member sends a message with
allowGroupAckset totrueto request message read receipts. - After reading the message, the recipient calls
sendto send a read receipt. - The sender receives the message read receipt by listening for
onReadMessagewhen online oronStatisticsMessagewhen offline. - The sender can know which group members have read the message by calling
getGroupMsgReadUser.
- A group member sends a message with
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
The message sender sets
deliveryinoptionsastruewhen initializing theconnectionobject.const chatClient = new AgoraChat.connection({ appKey: "your appKey", delivery: true, }); -
Once the recipient receives the message, the SDK triggers
onDeliveredMessageon the message sender's client, notifying that the message has been delivered to the recipient.chatClient.addEventHandler("handlerId", { onReceivedMessage: function (message) {}, // Received a receipt for message delivery to the server. onDeliveredMessage: function (message) {}, // Received a receipt for message delivery to the client. });
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chat
The one-to-one chats support both conversation read receipts and message read receipts. We recommend you use both types of read receipts together to reduce the number of message read receipts:
- If several messages are received when the chat page is not opened yet, send a conversation read receipt when the chat page is opened.
- If a message is received on an open chat page, send a message read receipt.
Conversation read receipts
-
The message recipient sends a conversation read receipt.
The message recipient opens the conversation page to check whether there are unread messages. If yes, call
sendto send a conversation read receipt.const options = { chatType: "singleChat", // The chat type: singleChat for one-to-one. type: "channel", // The type of read receipt: channel indicates the conversation read receipt. to: "userId", // The user ID of the message recipient. }; const msg = AgoraChat.message.create(options); chatClient.send(msg); -
The message sender receives the conversation read receipt in the
onChannelMessagecallback.chatClient.addEventHandler("handlerId", { onChannelMessage: (message) => {}, });
Message read receipts
For one-to-one chats, message read receipts are stored as long as messages on the Chat server. Specifically, message read receipts can be sent whenever the messages are available on the Chat server. The message storage period on the Chat server depends on your product plan. For details, see the pricing plan details.
Refer to the following steps to implement message read receipt in one-to-one chats:
-
The message recipient sends a message read receipt.
-
If there are several unread messages in the conversation, to minimize the number of sent message read receipts, we recommend that a conversation read receipt be sent when the message recipient enters the conversation.
const options = { chatType: "singleChat", // The chat type: singleChat for one-to-one chat. type: "channel", // The type of read receipt: channel indicates the conversation read receipt. to: "userId", // The user ID of the message receipt. }; const msg = AgoraChat.message.create(options); chatClient.send(msg); -
If there is only one unread message in the conversation, after reading it, call
sendfrom the recipient's client to send the message read receipt.const options = { type: "read", // The message read receipt. chatType: "singleChat", // The chat type: singleChat for one-to-one chat. to: "userId", // The user ID of the message receipt. id: "id", // The ID of the message that requires the read receipt. }; const msg = AgoraChat.message.create(options); chatClient.send(msg);
-
-
The message sender listens for
onReadMessageto receive the message read receipt.chatClient.addEventHandler("handlerId", { onReadMessage: (message) => {}, });
Group chat
For group chats, the conversation read receipt is only used to clear the
unread message count of the group chat on the server. The message sender
will not receive the conversation read receipt via the onChannelMessage
callback.
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
| Feature Restriction | Default | Description | Error |
|---|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. | The error 503 "group ack not open" is returned if you fail to enable this feature before using it. |
| Permission | All group members | By default, all group members can request read receipts when sending a message. You can contact support@agora.io to grant the permission only to the group owner and administrators. | If you only allow the group owner and administrators to send read receipts, the error "group ack msg permission denied" is returned if regular group members request read receipts when sending a message. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. | The error "group ack msg not found" is returned if read receipts are sent three days after the message is sent. |
| Chat group size | 200 members | This feature is available only to groups with up to 200 members. If the upper limit is exceeded, no read receipts are returned for the message sent within the group. To increase the upper limit of group member count, you can contact support@agora.io. | |
| View the number of read receipts returned for a group message | Message sender | By default, only the message sender can view the number of read receipts returned for a group message (or the number of group members that have returned the read receipts). To allow all group members to view the count, you can contact support@agora.io. |
Follow the steps to implement read receipts for a chat group message:
-
When sending a message, a group member can set whether to require a message read receipt by setting
allowGroupAcktotrue.sendGroupReadMsg = () => { const options = { type: 'txt', // Message type. chatType: 'groupChat', // Conversation type: groupChat for group chat. to: 'groupId', // The message recipient: group ID. msg: 'message content' // Message content. msgConfig: { allowGroupAck: true } // Setting that this message requires a read receipt. } const msg = AgoraChat.message.create(options); chatClient.send(msg).then((res) => { console.log('send message success'); }).catch((e) => { console.log("send message error"); }) } -
After reading the group message, the recipient calls
sendto send the message read receipt.sendReadMsg = () => { const options = { type: "read", // Whether the message has been read. chatType: "groupChat", // Conversation type: groupChat means group chat. id: "msgId", // The message ID for which the read receipt is sent. to: "groupId", // Group ID. ackContent: JSON.stringify({}), // The content of the message read receipt. }; const msg = AgoraChat.message.create(options); chatClient.send(msg); }; -
The message sender receives the message read receipt by listening for either of the following callbacks:
-
onReadMessage, when the message sender is online. -
onStatisticsMessage, when the message sender is offline.// You can listen in onReadMessage when online. chatClient.addEventHandler("handlerId", { onReadMessage: (message) => { let { mid } = message; let msg = { id: mid, }; if (message.groupReadCount) { // The message has been read. msg.groupReadCount = message.groupReadCount[message.mid]; } }, // You can listen for onStatisticMessage upon login when the read receipt is received when you are offline. onStatisticMessage: (message) => { let statisticMsg = message.location && JSON.parse(message.location); let groupAck = statisticMsg.group_ack || []; }, });
-
-
After receiving the read receipt, the message sender can retrieve the detailed information of the group members that have read the message.
chatClient .getGroupMsgReadUser({ msgId: "messageId", // Message ID. groupId: "groupId", // Group ID. }) .then((res) => { console.log(res); });
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses ChatManager to provide message receipt, which includes delivery receipts and read receipts. The following are the core methods:
ChatOptions.requireDeliveryAck: Enable message delivery receipts.ChatOptions.requireAck: Enable conversation and message read receipts.ChatManager.sendConversationReadAck: Send a conversation read receipt.ChatManager.sendMessageReadAck: Send a message read receipt.ChatManager.sendGroupMessageReadAck: Send a group message read receipt.
The logic for implementing these receipts are as follows:
-
Message delivery receipts
- The message sender enables delivery receipts by setting
ChatOptions.requireDeliveryAckastrue. - After the recipient receives the message, the SDK automatically sends a delivery receipt to the sender.
- The sender receives the delivery receipt by listening for
onMessageDelivered.
- The message sender enables delivery receipts by setting
-
Conversation and message read receipts
- The message sender enables read receipt by setting
ChatOptions.requireAckastrue. - After reading the message, the recipient calls
sendConversationReadAckorsendMessageReadAckto send a conversation or message read receipt. - The sender receives the conversation or message receipt by listening for
onConversationReadoronMessagesRead.
- The message sender enables read receipt by setting
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
When initializing the SDK, set
requireDeliveryAckinChatOptionsastrueon the sender's client.// The App Key String appKey = "appKey"; // Enables message delivery receipt bool requireDeliveryAck = true; ChatOptions options = ChatOptions( appKey: appKey, requireDeliveryAck: requireDeliveryAck, ); await ChatClient.getInstance.init(options); -
Once the recipient receives the message, the SDK triggers
onMessagesDeliveredon the message sender's client, notifying the message sender that the message has been delivered to the recipient. Listen for theonMessagesDeliveredcallback on the sender's client:ChatClient.getInstance.chatManager.addEventHandler( "UNIQUE_HANDLER_ID", ChatEventHandler( onMessagesDelivered: (messages) {}, ), );
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When initializing the SDK, set
requireAckinChatOptionsastrue.ChatOptions options = ChatOptions( appKey: "", requireAck: true, ); ChatClient.getInstance.init(options); -
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
sendConversationReadAckto send a conversation read receipt.String convId = "convId"; try { await ChatClient.getInstance.chatManager.sendConversationReadAck(convId); } on ChatError catch (e) { // Sending conversation read receipts fails. See e.code for the error code and e.description for the error description. } -
The message sender listens for message events and receives the conversation read receipt in
onConversationRead.ChatClient.getInstance.chatManager.addEventHandler( "UNIQUE_HANDLER_ID", ChatEventHandler( onConversationRead: (from, to) {}, ), );
In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation as 0, and all the other devices receive onConversationRead.
Message read receipts
To implement the message read receipt in one-to-one chats, take the following steps:
-
When initializing the SDK, set
requireAckinChatOptionsastrue.ChatOptions options = ChatOptions( appKey: "", requireAck: true, ); ChatClient.getInstance.init(options); -
The message sender listens for the message receipt in
onMessagesRead:ChatClient.getInstance.chatManager.addEventHandler( "UNIQUE_HANDLER_ID", ChatEventHandler( onMessagesRead: (messages) {}, ), ); -
When the message arrives, the recipient reads the message and calls
sendMessageReadAckto notify the sender that the message is read. The SDK will triggeronMessagesReadon the sender's client.try { ChatClient.getInstance.chatManager.sendMessageReadAck(msg); } on ChatError catch (e) { // Fails to send the message. See e.code for the error code, and e.description for the error description. }
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | Group owner and administrators | By default, only the group owner and administrators can request read receipts when sending a message. You can contact support@agora.io to grant the permission to regular group members. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 500 members | This feature is available only to groups with up to 500 members. In other words, each message in a group can have up to 500 read receipts. If the upper limit is exceeded, the latest read receipt record will overwrite the earliest one. |
| Maximum number of group messages that can have read receipts per day | 500 | A group can have up to 500 messages each day for which read receipts can be returned. |
Follow the steps to implement read receipts for a chat group message:
-
To receive the chat group message read receipts, the sender listens for the
onGroupMessageReadcallback.ChatClient.getInstance.chatManager.addEventHandler( "UNIQUE_HANDLER_ID", ChatEventHandler( onGroupMessageRead: (messages) {}, ), ); -
The sender sends a chat group message. Ensure that you set
needGroupAckastrue.// Sets the chat type as group chat msg.chatType = ChatType.GroupChat; // Whether to require a group message read receipt msg.needGroupAck = true; try { await ChatClient.getInstance.chatManager.sendMessage(msg); } on ChatError catch (e) { // Fails to send the message. See e.code for the error code, and e.description for the error description. } -
The chat group member reads the message and call
sendGroupMessageReadAckto send a chat group message receipt. The SDK will triggeronGroupMessageReadon the sender's client.try { ChatClient.getInstance.chatManager.sendGroupMessageReadAck(msgId, groupId); } on ChatError catch (e) { // Fails to send the group message read receipt. See e.code for the error code, and e.description for the error description. }
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses IChatManager to provide message receipt, which includes delivery receipts and read receipts. The following are the core methods:
ChatOptions.requireDeliveryAck: Enable message delivery receipts.ChatOptions.requireAck: Enable conversation and message read receipts.ChatManager.sendConversationReadAck: Send a conversation read receipt.ChatManager.sendMessageReadAck: Send a message read receipt.ChatManager.sendGroupMessageReadAck: Send a group message read receipt.
The logic for implementing these receipts are as follows:
-
Message delivery receipts
- The message sender enables delivery receipts by setting
ChatOptions.requireDeliveryAckastrue. - After the recipient receives the message, the SDK automatically sends a delivery receipt to the sender.
- The sender receives the delivery receipt by listening for
onMessageDelivered.
- The message sender enables delivery receipts by setting
-
Conversation and message read receipts
- The message sender enables read receipt by setting
ChatOptions.requireAckastrue. - After reading the message, the recipient calls
sendConversationReadAckorsendMessageReadAckto send a conversation or message read receipt. - The sender receives the conversation or message receipt by listening for
onConversationReadoronMessageRead.
- The message sender enables read receipt by setting
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
When initializing the SDK, set
requireDeliveryAckinChatOptionsastrueon the sender's client.// Set the SDK app key. const appKey = "appKey"; // Enable message delivery receipts. const requireDeliveryAck = true; ChatClient.getInstance() .init( new ChatOptions({ appKey, requireDeliveryAck, }) ) .then(() => { console.log("init sdk success"); }) .catch((reason) => { console.log("init sdk fail.", reason); }); -
Once the recipient receives the message, the SDK triggers
OnMessageDeliveredon the message sender's client, notifying the message sender that the message has been delivered to the recipient. Listen for theonMessageDeliveredcallback on the sender's client:class ChatMessageEvent implements ChatMessageEventListener { onMessagesDelivered(messages: ChatMessage[]): void { console.log(`onMessagesDelivered: `, messages); } // ... } // Add a message listener const listener = new ChatMessageEvent(); ChatClient.getInstance().chatManager.addMessageListener(listener);
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When initializing the SDK, set
requireAckinChatOptionsastrue.// Set the SDK app key. const appKey = "appKey"; // Enable the conversation and message read receipt. const requireAck = true; ChatClient.getInstance() .init( new ChatOptions({ appKey, requireAck, requireDeliveryAck, }) ) .then(() => { console.log("init sdk success"); }) .catch((reason) => { console.log("init sdk fail.", reason); }); -
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
sendConversationReadAckto send a conversation read receipt.// Get the conversation ID const convId = "convId"; // Call sendConversationReadAck to send the receipt. ChatClient.getInstance() .chatManager.sendConversationReadAck(convId) .then(() => { console.log("send conversation read success"); }) .catch((reason) => { console.log("send conversation read fail.", reason); }); -
The message sender listens for message events and receives the conversation read receipt in
onConversationRead.class ChatMessageEvent implements ChatMessageEventListener { onConversationRead(from: string, to?: string): void { // `from` indicates the message recipient that sends this receipt, and `to` indicates the message sender that receives this receipt. console.log(`onConversationRead: `, from, to); } // ... } // Add a chat message event. const listener = new ChatMessageEvent(); ChatClient.getInstance().chatManager.addMessageListener(listener);
In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation as 0, and all the other devices receive onConversationRead.
Message read receipts
To implement the message read receipt in one-to-one chats, take the following steps:
-
When initializing the SDK, set
requireAckinChatOptionsastrue.// Set the SDK app key. const appKey = "appKey"; // Enable the conversation and message read receipt. const requireAck = true; ChatClient.getInstance() .init( new ChatOptions({ appKey, requireAck, requireDeliveryAck, }) ) .then(() => { console.log("init sdk success"); }) .catch((reason) => { console.log("init sdk fail.", reason); }); -
The message sender listens for the message receipt in
onMessageRead:class ChatMessageEvent implements ChatMessageEventListener { onMessagesRead(messages: ChatMessage[]): void { // Receive the onMessageRead callback console.log(`onMessagesRead: `, messages); } // ... } // Add a chat message event. const listener = new ChatMessageEvent(); ChatClient.getInstance().chatManager.addMessageListener(listener); -
The sender sends a message. Ensure that you set
msg.hasReadAckastrue.// Send a message. // Set hasReadAck as true to require a message read receipt. msg.hasReadAck = true; // Call sendMessage to send the message ChatClient.getInstance() .chatManager.sendMessage(msg) .then(() => { // Print a log if message sending succeeds. console.log("send message success."); }) .catch((reason) => { // Print a log if message sends fails. console.log("send message fail.", reason); }); -
When the message arrives, the recipient reads the message and call
sendMessageReadAckto notify the send that the message is read. The SDK will triggeronMessageReadon the sender's client.// The message that requires a read receipt. const msg; // Call sendMessageReadAck to send a message read receipt. ChatClient.getInstance() .chatManager.sendMessageReadAck(msg) .then(() => { console.log("send message read success"); }) .catch((reason) => { console.log("send message read fail.", reason); });
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | Group owner and administrators | By default, only the group owner and administrators can request read receipts when sending a message. You can contact support@agora.io to grant the permission to regular group members. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 500 members | This feature is available only to groups with up to 500 members. In other words, each message in a group can have up to 500 read receipts. If the upper limit is exceeded, the latest read receipt record will overwrite the earliest one. |
| Maximum number of group messages that can have read receipts per day | 500 | A group can have up to 500 messages each day for which read receipts can be returned. |
Follow the steps to implement read receipts for a chat group message:
-
To receive the chat group message read receipts, the sender listens for the
onGroupMessageReadcallback.class ChatMessageEvent implements ChatMessageEventListener { onGroupMessageRead(groupMessageAcks: ChatGroupMessageAck[]): void { // Receive the onGroupMessageRead callback. console.log(`onGroupMessageRead: `, messages); } // ... } // Add a chat message event. const listener = new ChatMessageEvent(); ChatClient.getInstance().chatManager.addMessageListener(listener); -
The sender sends a chat group message. Ensure that you set
needGroupAckastrue.// Send a group message // Set needGroupAck as true to require a chat group message read receipt msg.needGroupAck = true; // Call sendMessage to send the group message ChatClient.getInstance() .chatManager.sendMessage(msg) .then(() => { // Print a log here if the message sending succeeds. console.log("send message success."); }) .catch((reason) => { // Print a log here if the message sending fails. console.log("send message fail.", reason); }); -
The chat group member reads the message and call
sendGroupMessageReadAckto send a chat group message receipt. The SDK will triggeronGroupMessageReadon the sender's client.// Send a chat group message read receipt // The ID of the message that requires a read receipt const msgId; // The chat group ID const groupId; // Call sendGroupMessageReadAck ChatClient.getInstance() .chatManager.sendGroupMessageReadAck(msgId, groupId) .then(() => { // Print a log here if the message sending succeeds. console.log("send message read success."); }) .catch((reason) => { // Print a log here if the message sending fails. console.log("send message read fail.", reason); });
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses IChatManager to provide message receipt. The following are the core methods:
Options.RequireDeliveryAck: Enable message delivery receipt.IChatManager.SendConversationReadAck: Send a conversation read receipt.IChatManager.SendMessageReadAck: Send a message read receipt.SendReadAckForGroupMessage: Send a message read receipt for group chat.
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
The message sender sets
RequireDeliveryAckinChatOptionsastruebefore sending the message:Options.RequireDeliveryAck = true; -
Once the recipient receives the message, the SDK triggers
OnMessageDeliveredon the message sender's client, notifying the message sender that the message has been delivered to the recipient.// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is delivered. public void OnMessagesDelivered(List messages) { } } // Add the chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate(); SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
-
Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
SendConversationReadAckto send a conversation read receipt.SDKClient.Instance.ChatManager.SendConversationReadAck(conversationId, new CallBack( onSuccess: () => { }, onError:(code, desc) => { } )); -
The message sender listens for message events and receives the conversation read receipt in
OnConversationRead.// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the conversation read receipt is received. // `from` indicates the message recipient that sends this receipt, and `to` indicates the message sender that receives this receipt. public void OnConversationRead(string from, string to) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation to 0, and all other devices receive
OnConversationRead. -
-
Message read receipts
To implement the message read receipt, take the following steps:
-
Send a conversation read receipt when the recipient enters the conversation.
SDKClient.Instance.ChatManager.SendConversationReadAck(conversationId, new CallBack( onSuccess: () => { }, onError:(code, desc) => { } )); -
When a new message arrives, send the message read receipt and add proper handling logics for the different message types.
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is received. public void OnMessageReceived(List messages) { ...... sendReadAck(message); ...... } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Send a message read receipt. public void sendReadAck(Message message) { // For a received message that has not sent a read receipt. if(message.Direction == MessageDirection.RECEIVE undefined message.MessageType == MessageType.Chat) { MessageBodyType type = message.Body.Type; // For attachment messages such as video and voice, send the message read receipt after the receiver clicks the files. if(type == MessageBodyType.VIDEO || type == MessageBodyType.VOICE || type == MessageBodyType.FILE) { return; } SDKClient.Instance.ChatManager.SendMessageReadAck(message.MsgId, new CallBack( onSuccess: () => { }, onError: (code, desc) => { } ); } } -
The message sender listens for the message receipt:
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is read. public void OnMessagesRead(string from, string to) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
-
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | Group owner and administrators | By default, only the group owner and administrators can request read receipts when sending a message. You can contact support@agora.io to grant the permission to regular group members. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 500 members | This feature is available only to groups with up to 500 members. In other words, each message in a group can have up to 500 read receipts. If the upper limit is exceeded, the latest read receipt record will overwrite the earliest one. |
| Maximum number of group messages that can have read receipts per day | 500 | A group can have up to 500 messages each day for which read receipts can be returned. |
Follow the steps to implement read receipts for a chat group message:
-
When sending a message, a group member can set whether to require a message read receipt.
// Set `IsNeedGroupAck` in `Message` as `true` when creating the message. Message msg = Message.CreateTextSendMessage("to", "hello world"); msg.IsNeedGroupAck = true; -
After the group member reads the chat group message, call
SendReadAckForGroupMessagefrom the group member's client to send a message read receipt:void SendReadAckForGroupMessage(string messageId, string ackContent) { SDKClient.Instance.ChatManager.SendReadAckForGroupMessage(messageId, ackContent,callback: new CallBack( onSuccess: () => { }, onError: (code, desc) => { } )); } -
The message sender listens for the message read receipt.
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the group message is read. public void OnGroupMessageRead(List list) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); -
The message sender can get the detailed information of the read receipt using
FetchGroupReadAcks.// messageId: The message ID. // pageSize: The page size. The value range is [1,50]. // startAckId: The starting receipt ID for query. Set it as null for the first call of the method and the SDK retrieves from the latest receipt. SDKClient.Instance.ChatManager.FetchGroupReadAcks(messageId, groupId, startAckId, pageSize, new ValueCallBack>( onSuccess: (list) => { // Updates the UI. }, onError: (code, desc) => { } ));
The Chat SDK provides the message read receipt feature that allows the user, after sending a message, to know whether the message is read. The feature is available to both one-to-one chats and group chats.
- Message delivery receipt: Available only to one-to-one chats.
- Message read receipt: Available to both one-to-one chats and group chats.
Understand the tech
The Chat SDK uses IChatManager to provide message receipt. The following are the core methods:
Options.RequireDeliveryAck: Enable message delivery receipt.IChatManager.SendConversationReadAck: Send a conversation read receipt.IChatManager.SendMessageReadAck: Send a message read receipt.SendReadAckForGroupMessage: Send a message read receipt for group chat.
Prerequisites
Before proceeding, ensure that you meet the following requirements:
- You have integrated the Chat SDK, initialized the SDK and implemented the functionality of registering accounts and login. For details, see Chat SDK quickstart.
- You understand the API call frequency limits as described in Limitations.
- Message read receipts for chat groups are not enabled by default. To use this feature, contact support@agora.io.
Implementation
This section introduces how to implement message delivery and read receipts in your chat app.
Message delivery receipts
To send a message delivery receipt, take the following steps:
-
The message sender sets
RequireDeliveryAckinChatOptionsastruebefore sending the message:Options.RequireDeliveryAck = true; -
Once the recipient receives the message, the SDK triggers
OnMessageDeliveredon the message sender's client, notifying the message sender that the message has been delivered to the recipient.// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is delivered. public void OnMessagesDelivered(List messages) { } } // Add the chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate(); SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
Conversation and message read receipts
In both one-to-one chats and group chats, you can use message read receipts to notify the message sender that the message has been read. To minimize the method call for message read receipts, the SDK also supports conversation read receipts in one-to-one chats.
One-to-one chats
In one-to-one chats, the SDK supports sending both the conversation read receipts and message read receipts. Agora recommends using conversation read receipts if the new message arrives when the message recipient has not entered the conversation UI.
-
Conversation read receipts
Follow the steps to implement conversation read receipts in one-to-one chats.
-
When a user enters the conversation UI, check whether the conversation contains unread messages. If yes, call
SendConversationReadAckto send a conversation read receipt.SDKClient.Instance.ChatManager.SendConversationReadAck(conversationId, new CallBack( onSuccess: () => { }, onError:(code, desc) => { } )); -
The message sender listens for message events and receives the conversation read receipt in
OnConversationRead.// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the conversation read receipt is received. // `from` indicates the message recipient that sends this receipt, and `to` indicates the message sender that receives this receipt. public void OnConversationRead(string from, string to) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
In use-cases where a user is logged in multiple devices, if the user sends a conversation read receipt from one device, the server sets the count of unread messages in the conversation to 0, and all other devices receive
OnConversationRead. -
-
Message read receipts
To implement the message read receipt, take the following steps:
-
Send a conversation read receipt when the recipient enters the conversation.
SDKClient.Instance.ChatManager.SendConversationReadAck(conversationId, new CallBack( onSuccess: () => { }, onError:(code, desc) => { } )); -
When a new message arrives, send the message read receipt and add proper handling logics for the different message types.
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is received. public void OnMessageReceived(List messages) { ...... sendReadAck(message); ...... } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Send a message read receipt. public void sendReadAck(Message message) { // For a received message that has not sent a read receipt. if(message.Direction == MessageDirection.RECEIVE undefined message.MessageType == MessageType.Chat) { MessageBodyType type = message.Body.Type; // For attachment messages such as video and voice, send the message read receipt after the receiver clicks the files. if(type == MessageBodyType.VIDEO || type == MessageBodyType.VOICE || type == MessageBodyType.FILE) { return; } SDKClient.Instance.ChatManager.SendMessageReadAck(message.MsgId, new CallBack( onSuccess: () => { }, onError: (code, desc) => { } ); } } -
The message sender listens for the message receipt:
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the message is read. public void OnMessagesRead(string from, string to) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); // Remove the delegate. SDKClient.Instance.ChatManager.RemoveChatManagerDelegate(adelegate);
-
Chat groups
For a group chat, group members can determine whether to require message read receipts when sending a message. If yes, after a group member reads the message, the SDK sends a read receipt. In a group chat, the number of message read receipts that are sent for the message refers to the number of group members that have read this message.
The following table shows the restrictions of this feature:
| Feature Restriction | Default | Description |
|---|---|---|
| Enabling the function | Disabled | To use this feature, contact support@agora.io to enable it. |
| Permission | Group owner and administrators | By default, only the group owner and administrators can request read receipts when sending a message. You can contact support@agora.io to grant the permission to regular group members. |
| Number of days before read receipts cannot be returned after the message is sent | 3 days | The server no longer records the group members that read the message three days after it is sent, nor sends the read receipts. |
| Chat group size | 500 members | This feature is available only to groups with up to 500 members. In other words, each message in a group can have up to 500 read receipts. If the upper limit is exceeded, the latest read receipt record will overwrite the earliest one. |
| Maximum number of group messages that can have read receipts per day | 500 | A group can have up to 500 messages each day for which read receipts can be returned. |
Follow the steps to implement read receipts for a chat group message:
-
When sending a message, a group member can set whether to require a message read receipt.
// Set `IsNeedGroupAck` in `Message` as `true` when creating the message. Message msg = Message.CreateTextSendMessage("to", "hello world"); msg.IsNeedGroupAck = true; -
After the group member reads the chat group message, call
SendReadAckForGroupMessagefrom the group member's client to send a message read receipt:void SendReadAckForGroupMessage(string messageId, string ackContent) { SDKClient.Instance.ChatManager.SendReadAckForGroupMessage(messageId, ackContent,callback: new CallBack( onSuccess: () => { }, onError: (code, desc) => { } )); } -
The message sender listens for the message read receipt.
// Inherit and instantiate `IChatManagerDelegate`. public class ChatManagerDelegate : IChatManagerDelegate { // Occurs when the group message is read. public void OnGroupMessageRead(List list) { } } // Add a chat manager delegate. ChatManagerDelegate adelegate = new ChatManagerDelegate() SDKClient.Instance.ChatManager.AddChatManagerDelegate(adelegate); -
The message sender can get the detailed information of the read receipt using
FetchGroupReadAcks.// messageId: The message ID. // pageSize: The page size. The value range is [1,50]. // startAckId: The starting receipt ID for query. Set it as null for the first call of the method and the SDK retrieves from the latest receipt. SDKClient.Instance.ChatManager.FetchGroupReadAcks(messageId, groupId, startAckId, pageSize, new ValueCallBack>( onSuccess: (list) => { // Updates the UI. }, onError: (code, desc) => { } ));
