please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Flutter/
Message/
SDK
  • Install Chat SDK
    • Install
  • Initialize Chat SDK
    • Initialize
  • Login And Logout
    • Login and Logout
  • Message
    • Message Overview
    • Sending Message
    • Receiving Message
    • Historical Message
    • Forwarding Message
    • Modifying Message
    • Message Inserting
    • Deleting Message
    • Clearing Messages
    • Recalling Message
    • Online Message
    • Read Receipt
    • Querying Message
    • Group @ Message
    • Targeted Group Message
    • Notification Muting
    • Message Extension
  • Conversation
    • Conversation Overview
    • Conversation List
    • Getting Conversation
    • Conversation Unread Count
    • Pinning Conversation to the Top
    • Deleting Conversation
    • Conversation Draft
    • Conversation Group
  • Group
    • Group Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
  • User
    • User Profile
    • Friend Management
    • Friend List
    • Blocklist
  • Offline Push
    • Offline Push
  • Signaling
    • Signaling Management
  • Local Search
    • Searching for Message
    • Searching for Friend
    • Searching Group
    • Searching for Group Member
  • API Reference
    • Client APIs
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Message Extension

Overview

Message extension allows you to configure keys and values for messages to implement polling, group notes, survey and other types of messages.
For polling, create a custom message using the 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.
For group notices, create a custom message for group notification using the 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.
For survey, create a custom message using the 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.
Note:

To use this feature, you need to purchase the Ultimate edition.
This feature is available only in SDK v4.1.8 or later.
You need to enable this feature via Chat console > Feature Configuration > Login and Message > Set message extension.
This feature is not available for communities and audio/video groups.

Setting message extension

Call the setMessageExtensions API (details) to set the message extension. If an extension already exists, modify its value info. Otherwise, add new ones.
The request parameters of the setMessageExtensions API are detailed as follows:
Attribute
Definition
Description
message
Message object
Three message conditions to meet:
Set supportMessageExtension (Flutter) to `YES` before message sending.
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.

Note:
1. The 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.
1. If multiple users set or delete the 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.
2. We recommend setting unique keys of extensions by different users to avoid conflicts in most cases. For example, the userID can be set as the key of the extension in polling, group notices and survey.
Sample code:
// Setting message extension
V2TimValueCallback<List<V2TimMessageExtensionResult>>
setMessageExtensionsRes = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.setMessageExtensions(msgID: '', // ID of the message for extension setting
extensions: []); // Message extension field
if (setMessageExtensionsRes.code == 0) {
// Set message extensions successfully
}

Getting message extensions

Call the getMessageExtensions API (details) to get the message extension list.
Note:
If the network is unavailable, the SDK will return the message extension list cached locally.
Sample code:
// Get message extensions
V2TimValueCallback<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 successfully
getMessageExtensionsRes.data?.forEach((element) {
element.extensionKey; // Key of the extension field modified
element.extensionValue; // Value of the extension field modified
});
}

Deleting message extensions

Call the deleteMessageExtensions API (details) to delete message extensions. If the value of the keys field is set to null, all message extensions will be cleared.
Sample code:
// Delete message extensions
V2TimValueCallback<List<V2TimMessageExtensionResult>>
deleteMessageExtensionsRes = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.deleteMessageExtensions(msgID: '', // ID of the message for extension deletion
keys: []); // List of keys of the extension fields to be deleted
if (deleteMessageExtensionsRes.code == 0) {
// Deleted message extensions successfully
deleteMessageExtensionsRes.data?.forEach((element) {
element.extension; // Message extension information
element.resultCode; // Operation result code
element.resultInfo; // Result description
});
}

Updating message extensions

If you have added an event listener for advanced messages by calling 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.
Sample code:
// Create a message listener
V2TimAdvancedMsgListener listener = V2TimAdvancedMsgListener(
onRecvMessageExtensionsChanged:
(String msgID, List<V2TimMessageExtension> extensions) {
// msgID: ID of the message modified
// extensions: List of extension fields modified
for (V2TimMessageExtension element in extensions) {
element.extensionKey; // Key of the extension field modified
element.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 messages
TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.addAdvancedMsgListener(listener: listener);