createCustomMessageAPI to create a custom message for voting, where data stores the voting title and options. Then, use the message extension key to store the voting user ID and the message extension value to store the voting user's option. With each user's voting option, we can dynamically calculate the user proportion for each voting option.createCustomMessageAPI, where data stores the title of the chain reaction. Then, use the message extension key to store user IDs and the message extension value to store the chain reaction information.createCustomMessageAPI, where data stores the title and options of the survey. Then, use the message extension key to store respondent IDs and the message extension value to store survey information.
setMessageExtensions interface can set message extensions. If the extension key already exists, it modifies the extension value. If the extension key does not exist, it adds a new extension. Once successfully set, both the sender and the recipient (C2C) or group members (Group) will receive the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED event.chat.setMessageExtensions(message, extensions);
Parameter | Type | Description |
message | Message | Message instance, three conditions to be met: The message's isSupportExtension attribute must be trueThe message must be sent successfully The message cannot be an AVChatRoom message |
extensions | Array | Message extension key-value list: if the extension key exists, update its value; if it doesn't exist, add new extensions. |
Promiselet promise = chat.setMessageExtensions(message, [{ key: 'a', value: '1' }, { key: 'b', value: '2' }]);promise.then(function(imResponse) {// Set message extensions successfullyconst { extensions } = imResponse.data;extensions.forEach((item) => {const { code, key, value } = item;if (code === 23001) {// Key conflict detected. Please retry as needed based on the returned latest extension info}});}).catch(function(imError) {// Failed to set message extensionsconsole.warn('setMessageExtensions error:', imError);});
getMessageExtensions API to get the message extension list.chat.getMessageExtensions(message);
Parameter | Type | Description |
message | Message | Message instance, three conditions to be met: The message's isSupportExtension attribute must be trueThe message must be sent successfully The message cannot be from a live broadcast group (AVChatRoom) |
Promiselet promise = chat.getMessageExtensions(message);promise.then(function(imResponse) {// Got message extensions successfullyconst { extensions } = imResponse.data;extensions.forEach((item) => {const { key, value } = item;// key - Message extension key// value - Value corresponding to the message extension key});}).catch(function(imError) {// Failed to get message extensionsconsole.warn('getMessageExtensions error:', imError);});
deleteMessageExtensionsAPI to delete specified message extensions. If the keyList field is not provided, all message extensions will be cleared. After successful deletion, both you and the other party (C2C) or group members (Group) will receive the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED event.chat.deleteMessageExtensions(message, keyList);
Parameter | Type | Description |
message | Message | Message instance, three conditions to be met: The message's isSupportExtension attribute must be true The message must be sent successfully The message cannot be from a live broadcast group (AVChatRoom) |
keyList | Array | undefined | Message extension key list. |
Promise// Delete message extension keylet promise = chat.deleteMessageExtensions(message, ['a', 'b']);promise.then(function(imResponse) {// Deleted message extensions successfullyconst { extensions } = imResponse.data;extensions.forEach((item) => {const { code, key, value } = item;if (code === 23001) {// Delete key conflict detected. Please retry as needed based on the returned latest extension info}});}).catch(function(imError) {// Failed to delete message extensionsconsole.warn('deleteMessageExtensions error:', imError);});
// Clear all message extension keyslet promise = chat.deleteMessageExtensions(message);promise.then(function(imResponse) {// Cleared message extensions successfullyconsole.log('deleteMessageExtensions ok:', imResponse)}).catch(function(imError) {// Failed to clear message extensionsconsole.warn('deleteMessageExtensions error:', imError);});
TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED event. You can get the updated key-value information in the registered callback.let onMessageExtensionsUpdated = function(event) {const { messageID, extensions } = event.data;// messageID - Message ID// extensions - Message extension informationextensions.forEach((item) => {const { key, value } = item;// key - Message extension key// value - Value corresponding to the message extension key});};chat.on(TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED, onMessageExtensionsUpdated);
TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED event. You can get the deleted key in the registered callback.let onMessageExtensionsDeleted = function(event) {const { messageID, keyList } = event.data;// messageID - Message ID// keyList - List of deleted message extension keyskeyList.forEach((key) => {// console.log(key)});};chat.on(TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED, onMessageExtensionsDeleted);
Feedback