Message Extension
Use Cases
Message extension can be used to add status identifiers to original messages.
- For message commenting needs, you can add comment information by setting the original message's extension information.
- For gift collection or order status changes, this feature can be used to alter the message display status. For example, when sending a gift to a user, the default status is "uncollected," and clicking on it can set the message extension to "collected."
- This feature allows you to set extension information for a
message
. - It only supports one-to-one and group chat conversation types, not chatroom types.
- Each time the message extension is set, a built-in notification message will be generated. Frequent setting of extensions will produce a large number of messages.
Setting Message Extensibility
After [constructing the message], set the expansion
property of the message. By default, it is not enabled. Once a value is set, it will automatically be enabled. This can be set when sending the message, but cannot be changed after the message is sent.
Code Example
engine.createImageMessage(type, targetId, channelId, path)
.then((message: RCIMIWImageMessage) => {
message.expansion = {};
});
Updating Message Extension Information
- Update the message extension information.
- Call after the message is sent.
Method
updateMessageExpansion(
messageUId: string,
expansion: Map<string, string>,
callback: IRCIMIWUpdateMessageExpansionCallback
): Promise<number>;
Parameter Description
Parameter | Type | Description |
---|---|---|
messageUId | string | The messageUid of the message, which can be obtained from the message object. Only successfully sent messages will have this value. |
expansion | Map<string, string> | The key-value pairs for the message extension information to be updated, of type HashMap. Key supports a combination of uppercase and lowercase letters, numbers, and some special symbols + = - _. Chinese characters are not supported. Value can include spaces. |
callback | IRCIMIWUpdateMessageExpansionCallback | Callback for the interface call result. |
Return Value
Return Value | Description |
---|---|
number | The status code of the current interface operation. 0 indicates a successful call. The specific result needs to be implemented in the interface callback. Non-zero indicates that the current interface call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes. |
Code Example
const callback = {
onMessageExpansionUpdated: (code: number) => {
//...
},
};
let code = await engine.updateMessageExpansion(messageUId, expansion, callback);
Deleting Message Extension Information
- Delete specific key-value pairs from the message extension information.
- Call after the message is sent.
Method
removeMessageExpansionForKeys(
messageUId: string,
keys: Array<string>,
callback: IRCIMIWRemoveMessageExpansionForKeysCallback
): Promise<number>;
Parameter Description
Parameter | Type | Description |
---|---|---|
messageUId | string | The messageUid of the message, which can be obtained from the message object. Only successfully sent messages will have this value. |
keys | Array<string> | The list of keys to be deleted from the message extension information, of type ArrayList. |
callback | IRCIMIWRemoveMessageExpansionForKeysCallback | Callback for the interface call result. |
Return Value
Return Value | Description |
---|---|
number | The status code of the current interface operation. 0 indicates a successful call. The specific result needs to be implemented in the interface callback. Non-zero indicates that the current interface call operation failed, and the interface callback will not be triggered. For detailed errors, refer to the error codes. |
Code Example
const callback = {
onMessageExpansionForKeysRemoved: (code: number) => {
//...
},
};
let code = await engine.removeMessageExpansionForKeys(messageUId, keys, callback);
Message Extension Update Listener
Method
setOnRemoteMessageExpansionUpdatedListener(listener?: (expansion: Map<string, string>, message: RCIMIWMessage) => void): void;
Parameter Description
Parameter | Type | Description |
---|---|---|
expansion | Map<string, string> | The updated key-value pairs in the message extension information, containing only the updated pairs, not all data. To get all key-value pairs, use the expansion property of the message. |
message | RCIMIWMessage | The message that has changed |
Code Example
engine?.setOnRemoteMessageExpansionUpdatedListener((expansion: Map<string, string>, message: RCIMIWMessage) => {
//...
});
Message Extension Removal Listener
Method
setOnRemoteMessageExpansionForKeyRemovedListener(listener?: (message: RCIMIWMessage, keys: Array<string>) => void): void;
Parameter Description
Parameter | Type | Description |
---|---|---|
message | RCIMIWMessage | The message that has changed |
keys | Array<string> | The list of keys deleted from the message extension information |
Code Example
engine?.setOnRemoteMessageExpansionForKeyRemovedListener((message: RCIMIWMessage, keys: Array<string>) => {
//...
});