Message Extensions
The message extension feature allows adding Key/Value state identifiers to message objects (Message). Extension information can be set or updated both before and after message sending, enabling business requirements such as message comments, gift claiming, and order status updates.
tip
- Whether a message can carry or have extensions is determined by the
canIncludeExpansionproperty of theMessagewhen sending. This property must be set before sending and cannot be modified afterward. - A single message can have up to 20 extension KV pairs per operation, with a total limit of 300 KV pairs. In concurrent scenarios, any extensions exceeding 300 will be discarded.
- If cloud message storage is enabled, historical messages retrieved from the server will include any set extensions.
- Each extension update generates a built-in notification message, so frequent updates may produce numerous messages.
Monitoring Message Processing
You can monitor remote users' modifications to message extensions by implementing the setUltraGroupMessageChangeListener method:
// Ultra group message change notifications
interface UltraGroupMessageChangeListener {
// Message extension updates/deletions
void onUltraGroupMessageExpansionUpdated(List<Message> messages);
// Message content modifications
void onUltraGroupMessageModified(List<Message> messages);
// Message recalls
void onUltraGroupMessageRecalled(List<Message> messages);
}
// Set ultra group message change listener
public void setUltraGroupMessageChangeListener(IRongCoreListener.UltraGroupMessageChangeListener listener)
Setting and Updating Message Extensions
tip
The message extension feature requires messages to be marked as extensible before sending. For details on modifying a message's extensible property, refer to the setCanIncludeExpansion() documentation in Message Extensions.
class OperationCallback {
onSuccess()
onError(ErrorCode code)
}
// Update message extensions
public void updateUltraGroupMessageExpansion(final Map<String, String> expansion, final String messageUId, final IRongCoreCallback.OperationCallback callback)
// Remove message extensions
public void removeUltraGroupMessageExpansion(final String messageUId, final List<String> keyArray, final IRongCoreCallback.OperationCallback callback)