createCustomMessage
API, where data
stores the polling title and options. And store the user ID of the voter and selected option(s) in the key
and value
of the message extension, respectively. With the selected options of users, we can calculate the polling percentage in real time.createCustomMessage
API, where data
stores the title of the group notice, and then store the user ID and the corresponding info in the key
and value
of the message extension, respectively.createCustomMessage
API, where data
stores the title and options of the survey, and then store the user ID and the corresponding info in the key
and value
of the message extension, respectively.setMessageExtensions
API to set a message extension. If the extension key
already exists, modify its value
. Otherwise, add the new key-value extension. After the message extension is set successfully, both yourself and the recipient (one-to-one) or group members (Group) will receive the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED
event.chat.setMessageExtensions(message, extensions);
Name | Type | Description |
message | Message | Message instance |
extensions | Array | List of key-value extensions of a message. If an extension key already exists, modify its value . Otherwise, add the new key-value extension. |
key
and value
of an extension can contain up to 100 B and 1 KB, respectively. You can set up to 20 extensions each time and 300 extensions for a message.key
of the same extension simultaneously, only the first user can operate successfully, and other users will receive the error code 23001 and the latest extension info in the setting response packet, who can set it again if necessary.userID
can be set as the key
of the extension in polling, group notices and survey.Promise
let 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. Try again according to the latest extension information returned as needed.}});}).catch(function(imError){// Failed to set message extensionsconsole.warn('setMessageExtensions error:', imError);});
getMessageExtensions
API to get the list of message extensions.chat.getMessageExtensions(message);
Name | Type | Description |
message | Message | Message instance |
Promise
let promise = chat.getMessageExtensions(message);promise.then(function(imResponse) {// Got message extensions successfullyconst { extensions } = imResponse.data;extensions.forEach((item) => {const { key, value } = item;// `key` - key in the message extension// `value` - value of the key in the message extension});}).catch(function(imError){// Failed to get message extensionsconsole.warn('getMessageExtensions error:', imError);});
deleteMessageExtensions
API to delete message extensions. If keyList
is not passed in, all message extensions will be cleared. After message extensions are successfully deleted, both the user and the recipient (one-to-one) or group members (Group) will receive the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED
event.chat.deleteMessageExtensions(message, keyList);
Name | Type | Description |
message | Message | Message instance |
keyList | Array | undefined | List of message extension keys |
key
of the same extension simultaneously, only the first user can operate successfully, and other users will receive the error code 23001 and the latest extension info, who can initiate the operation again if necessary.Promise
// Delete message extension keyslet 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) {// `key` conflict. Try again according to the latest extension information returned as needed.}});}).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) {// Message extensions cleared successfullyconsole.log('deleteMessageExtensions ok:', imResponse)}).catch(function(imError){// Failed to clear the message extensionsconsole.warn('deleteMessageExtensions error:', imError);});
TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED
event in advance, and message extensions are added or updated, the SDK distributes the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_UPDATED
event, and you can obtain the updated key-value information in the registered callback.let onMessageExtensionsUpdated = function(event) {const { messageID, extensions } = event.data;// `messageID` - Message ID// `extensions` - Message extension listextensions.forEach((item) => {const { key, value } = item;// `key` - key in the message extension// `value` - value of the key in the message extension});};chat.on(TencentCloudChat
.EVENT.MESSAGE_EXTENSIONS_UPDATED, onMessageExtensionsUpdated);
TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED
event in advance, and message extensions are deleted, the SDK distributes the TencentCloudChat.EVENT.MESSAGE_EXTENSIONS_DELETED
event, and you can obtain the deleted key
in the registered callback.let onMessageExtensionsDeleted = function(event) {const { messageID, keyList } = event.data;// `messageID` - Message ID// `keyList` - List of message extension keys deletedkeyList.forEach((key) => {// console.log(key)});};chat.on(TencentCloudChat
.EVENT.MESSAGE_EXTENSIONS_DELETED, onMessageExtensionsDeleted);
Was this page helpful?