createCustomMessage API (details), 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 (details) to set the message extension. If an extension already exists, modify its value info. Otherwise, add new ones.setMessageExtensions API are detailed as follows:Attribute | Definition | Description |
message | Message object | Three message conditions to meet: The message is sent successfully. The message is not a message of a community/audio-video group. |
extensions | Extensions | Modify the `value` info of an existing extension, or add new extensions. |
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.// Setting message extensionV2TimValueCallback<List<V2TimMessageExtensionResult>>setMessageExtensionsRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().setMessageExtensions(msgID: '', // ID of the message for extension settingextensions: []); // Message extension fieldif (setMessageExtensionsRes.code == 0) {// Set message extensions successfully}
// Get message extensionsV2TimValueCallback<List<V2TimMessageExtension>> getMessageExtensionsRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().getMessageExtensions(msgID: '', // ID of the message whose extension information is to be obtained);if (getMessageExtensionsRes.code == 0) {// Got message extensions successfullygetMessageExtensionsRes.data?.forEach((element) {element.extensionKey; // Key of the extension field modifiedelement.extensionValue; // Value of the extension field modified});}
deleteMessageExtensions API (details) to delete message extensions. If the value of the keys field is set to null, all message extensions will be cleared.// Delete message extensionsV2TimValueCallback<List<V2TimMessageExtensionResult>>deleteMessageExtensionsRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().deleteMessageExtensions(msgID: '', // ID of the message for extension deletionkeys: []); // List of keys of the extension fields to be deletedif (deleteMessageExtensionsRes.code == 0) {// Deleted message extensions successfullydeleteMessageExtensionsRes.data?.forEach((element) {element.extension; // Message extension informationelement.resultCode; // Operation result codeelement.resultInfo; // Result description});}
addAdvancedMsgListener, you will receive the onRecvMessageExtensionsChanged callback (details) when message extensions are added or updated, and the onRecvMessageExtensionsDeleted callback (details) when message extensions are deleted.// Create a message listenerV2TimAdvancedMsgListener listener = V2TimAdvancedMsgListener(onRecvMessageExtensionsChanged:(String msgID, List<V2TimMessageExtension> extensions) {// msgID: ID of the message modified// extensions: List of extension fields modifiedfor (V2TimMessageExtension element in extensions) {element.extensionKey; // Key of the extension field modifiedelement.extensionValue; // Value of the extension field modified}},onRecvMessageExtensionsDeleted: (msgID, extensionKeys) {// msgID: ID of the message whose extension information is deleted// extensionKeys: List of keys whose extension information is deleted},);// Add an event listener for advanced messagesTencentImSDKPlugin.v2TIMManager.getMessageManager().addAdvancedMsgListener(listener: listener);
Feedback