needReadReceipt
to true
, and sends the message.// Create a one-to-one messagelet message = chat.createTextMessage({to: 'user1',conversationType: TencentCloudChat.TYPES.CONV_C2C,payload: {text: 'Hello world!'},// To use it, purchase the Premium edition and set `needReadReceipt` to `true` when creating a message.needReadReceipt: true});// 2. Send the message.let promise = chat.sendMessage(message);promise.then(function(imResponse) {// Message sent successfullyconsole.log(imResponse);}).catch(function(imError) {// Failed to send the messageconsole.warn('sendMessage error:', imError);});
// Create a group messagelet message = chat.createTextMessage({to: 'test',conversationType: TencentCloudChat.TYPES.CONV_GROUP,payload: {text: 'Hello world!'},// To use it, purchase the Premium edition and set `needReadReceipt` to `true` when creating a message.needReadReceipt: true});// Send the messagelet promise = chat.sendMessage(message);promise.then(function(imResponse) {// Message sent successfullyconsole.log(imResponse);}).catch(function(imError) {// Failed to send the messageconsole.warn('sendMessage error:', imError);});
needReadReceipt
field in Message
. If yes, after the user reads the message, the receiver calls the sendMessageReadReceipt
API to send a read receipt.messageList
must be from the same one-to-one or group conversation.TencentCloudChat.TYPES.MESSAGE_READ_RECEIPT_RECEIVED
callback which contains the latest read information of the message.message.readReceiptInfo.isPeerRead
property of the message sender will be updated to true
. This property can be used for rendering the read receipt status of C2C messages. Calling this API will not update the isPeerRead
property of the message.chat.sendMessageReadReceipt(messageList);
Name | Type | Description |
messageList | Array | List of messages (up to 30) in the same conversation |
Promise
// Pull the group message listlet messageList = null;chat.getMessageList({conversationID: 'GROUPtest'}).then(function(imResponse) {messageList = imResponse.data.messageList; // Message listchat.sendMessageReadReceipt(messageList).then(function() {// Read receipt for the group message sent successfully}).catch(function(imError) {// Failed to send a read receipt for the group message});});
// Pull the one-to-one message listlet messageList = null;chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) {messageList = imResponse.data.messageList; // Message listchat.sendMessageReadReceipt(messageList).then(function() {// Read receipt for the one-to-one message sent successfully}).catch(function(imError) {// Failed to send a read receipt for the one-to-one message});});
let onMessageReadReceiptReceived = function(event) {// event.data - An array that stores message read receipt informationconst readReceiptInfoList = event.data;readReceiptInfoList.forEach((item) => {const { groupID, userID, messageID, readCount, unreadCount, isPeerRead, timestamp } = item;// messageID - Message ID// userID - one-to-one message receiver// isPeerRead - Whether the one-to-one message is read by the receiver// timestamp - one-to-one message peer send read receipt time.// groupID - Group ID// readCount - Number of members who have read the group message// unreadCount - Number of members who have not read the group messageconst message = chat.findMessage(messageID);if (message) {if (message.conversationType === TencentCloudChat.TYPES.CONV_C2C) {if (message.isPeerRead === true) {// Read by the receiver}} else if (message.conversationType === TencentCloudChat.TYPES.CONV_GROUP) {if (message.readReceiptInfo.unreadCount === 0) {// Read by all} else {// message.readReceiptInfo.readCount - Latest read count of the message// To query which group members have read the message// call the [getGroupMessageReadMemberList] API.}}}});}chat.on(TencentCloudChat.EVENT.MESSAGE_READ_RECEIPT_RECEIVED, onMessageReadReceiptReceived);
getMessageReadReceipt
API to pull the message read receipt information.messageList
must be from the same one-to-one or group conversation.chat.getMessageReadReceiptList(messageList);
Name | Type | Description |
messageList | Array | List of messages in the same conversation |
Promise
// Pull the group message listlet messageList = null;chat.getMessageList({conversationID: 'GROUPtest'}).then(function(imResponse) {messageList = imResponse.data.messageList; // Message listchat.getMessageReadReceiptList(messageList).then(function(imResponse) {messageList = imResponse.data.messageList; // Message list// `getMessageReadReceiptList` is called successfully,// `Message.readReceiptInfo` will contain the message read receipt information.// Message.readReceiptInfo.readCount - Read count of a message.// To query which group members have read the message, call the [getGroupMessageReadMemberList] API.// Message.readReceiptInfo.unreadCount - Unread count of a message.// `0` indicates that all members have read the message.}).catch(function(imError) {// Failed to pull the read receipt list});});
// Pull the one-to-one message listlet messageList = null;chat.getMessageList({conversationID: 'C2Ctest'}).then(function(imResponse) {messageList = imResponse.data.messageList; // Message listchat.getMessageReadReceiptList(messageList).then(function(imResponse) {messageList = imResponse.data.messageList; // Message list// After the message list is pulled successfully// `Message.readReceiptInfo` will contain the message read receipt information.// Message.readReceiptInfo.isPeerRead - Whether the receiver has sent a read receipt}).catch(function(imError) {// Failed to pull the read receipt list});});
getGroupMessageReadMemberList
API to pull the member list by page.chat.getGroupMessageReadMemberList(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
message | Message | Message instance |
cursor | String | Cursor for the paged pull. Pass in '' for the first pull. |
filter | Number | Specifies to pull the list of members who have or have not read the message. Valid values: 0 - pull the list of members who have read the message 1 - pull the list of members who have not read the message |
count | Number | Number of members to be pulled per page. Maximum value: 100. |
Promise
// Pull the list of members who have read the group messagelet promise = chat.getGroupMessageReadMemberList({message,filter: 0,cursor: '', // Pass in `''` for the first pullcount: 30,});promise.then(function(imResponse) {const { isCompleted, cursor, messageID, readUserIDList } = imResponse.data;// isCompleted - true: completed; false: not completed// cursor - Used for the subsequent pull when `isCompleted` is `false`// messageID - Group message ID// readUserIDList - List of `userID` values of members who have read the message}).catch(function(imError) {// Failed to pull the list of members who have read the group message});
// Pull the list of members who have not read the group messagelet promise = chat.getGroupMessageReadMemberList({message,filter: 1,cursor: '', // Pass in `''` for the first pullcount: 30,});promise.then(function(imResponse) {const { isCompleted, cursor, messageID, readUserIDList } = imResponse.data;// isCompleted - true: completed; false: not completed// cursor - Used for the subsequent pull when `isCompleted` is `false`// messageID - Group message ID// unreadUserIDList - List of `userID` values of members who have not read the group message}).catch(function(imError) {// Failed to pull the list of members who have not read the group message// 10062 - The read receipt information for the group message was not found.});
Was this page helpful?