Skip to main content

Message Extension

Use Cases

Message extension can be used to add status identifiers to original messages.

  • Message Comments: Add comment information by setting the extension information of the original message.
  • Gift Redemption & Order Status Updates: Change the display status of messages using this feature. For example, when sending a gift to a user, the default status is "unclaimed," and after the user clicks, the message extension can be set to "claimed."
  • Setting Extension Information: This feature allows you to set extension information for a message.
  • Supported Conversation Types: Only one-to-one chat and group chat are supported; chatroom is not supported.
  • Built-in Notification Messages: Each time you set a message extension, a built-in notification message will be generated. Frequent setting of extensions may result in a large number of messages.

Setting Message Extensibility

After creating the message, set the expansion property of the message. By default, it is not enabled. Setting a value will automatically enable it. It can be set when sending the message but cannot be changed after the message is sent.

Code Example

RCIMIWImageMessage? message = await engine.createImageMessage(
type,
targetId,
channelId,
path,
);
message?.expansion = {};

Updating Message Extension Information

  1. Update the message extension information.
  2. Call after the message is sent.

Method

Future<int> updateMessageExpansion(String messageUId, Map expansion, {IRCIMIWUpdateMessageExpansionCallback? callback});

Parameter Description

ParameterTypeDescription
messageUIdStringThe `` of the message, which can be obtained from the message object. Only successfully sent messages will have this value.
expansionMap<String, String>Key-value pairs for the message extension information to be updated, of type HashMap. Key supports combinations of uppercase and lowercase letters, numbers, and special symbols + = - _. Chinese characters are not supported. Value can include spaces.
callbackIRCIMIWUpdateMessageExpansionCallbackEvent callback. SDK supports callback from version 5.3.1. Other callback methods are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>The status code of the current operation. 0 indicates success. Specific results need to be implemented through the interface callback. Non-zero indicates that the current operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes.

Code Example

IRCIMIWUpdateMessageExpansionCallback? callback = IRCIMIWUpdateMessageExpansionCallback(onMessageExpansionUpdated: (int? code) {
//...
});

int? ret = await engine?.updateMessageExpansion(messageUId, expansion, callback:callback);

Callback Method

  • onMessageExpansionUpdated

    Listener for the interface call result.

Function(int? code, String? messageUId, Map? expansion)? onMessageExpansionUpdated;

Parameter Description

ParameterTypeDescription
codeintThe status code of the interface callback. 0 indicates success, non-zero indicates an exception.
messageUIdStringThe `` of the message.
expansionMap<String, String>Key-value pairs for the message extension information to be updated, of type HashMap.

Code Example

engine?.onMessageExpansionUpdated = (int? code, String? messageUId, Map? expansion) {
//...
};

Deleting Message Extension Information

  1. Delete specific key-value pairs from the message extension information.
  2. Call after the message is sent.

Method

Future<int> removeMessageExpansionForKeys(String messageUId, List<String> keys, {IRCIMIWRemoveMessageExpansionForKeysCallback? callback});

Parameter Description

ParameterTypeDescription
messageUIdStringThe `` of the message, which can be obtained from the message object. Only successfully sent messages will have this value.
keysList<String>The list of keys to be deleted from the message extension information, of type ArrayList.
callbackIRCIMIWRemoveMessageExpansionForKeysCallbackEvent callback. SDK supports callback from version 5.3.1. Other callback methods are deprecated from version 5.4.0. If the callback parameter is passed, only the callback will be triggered.

Return Value

Return ValueDescription
Future<int>The status code of the current operation. 0 indicates success. Specific results need to be implemented through the interface callback. Non-zero indicates that the current operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes.

Code Example

IRCIMIWRemoveMessageExpansionForKeysCallback? callback = IRCIMIWRemoveMessageExpansionForKeysCallback(onMessageExpansionForKeysRemoved: (int? code) {
//...
});

int? ret = await engine?.removeMessageExpansionForKeys(messageUId, keys, callback:callback);

Callback Method

  • onMessageExpansionForKeysRemoved

Listener for the interface call result.

Function(int? code, String? messageUId, List<String>? keys)? onMessageExpansionForKeysRemoved;

Parameter Description

ParameterTypeDescription
codeintThe status code of the interface callback. 0 indicates success, non-zero indicates an exception.
messageUIdStringThe `` of the message.
keysList<String>The list of keys to be deleted from the message extension information, of type ArrayList.

Code Example

engine?.onMessageExpansionForKeysRemoved = (int? code, String? messageUId, List<String>? keys) {
//...
};

Message Extension Update Listener

Method

Function(Map? expansion, RCIMIWMessage? message)? onRemoteMessageExpansionUpdated;

Parameter Description

ParameterTypeDescription
expansionMap<String, String>The updated key-value pairs in the message extension information. Only the updated key-value pairs are included, not the entire data. To get all key-value pairs, use the expansion property of the message.
messageRCIMIWMessageThe message that has changed.

Code Example

engine?.onRemoteMessageExpansionUpdated = (Map? expansion, RCIMIWMessage? message) {
//...
};

Message Extension Removal Listener

Method

Function(RCIMIWMessage? message, List<String>? keys)? onRemoteMessageExpansionForKeyRemoved;

Parameter Description

ParameterTypeDescription
messageRCIMIWMessageThe message that has changed.
keysList<String>The list of keys removed from the message extension information.

Code Example

engine?.onRemoteMessageExpansionForKeyRemoved = (RCIMIWMessage? message, List<String>? keys) {
//...
};