logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Forward messages


Overview

ZIM SDK supports two forms of message forwarding:

  • Forwarding combined messages.
  • Forwarding messages one by one.

Forwarding combined messages

Note
  • Only ZIM SDK version 2.14.0 and above supports sending and receiving combined messages.
  • If the SDK version of the receiving end is between [2.0.0, 2.14.0), the receiving end can receive combined messages, but the message type will be displayed as unknown and the message content cannot be obtained. To obtain this message, please upgrade the SDK to version 2.14.0 or above.
  • If the SDK version of the receiving end is version 1.x.x, it cannot receive combined messages.

Send combined messages

The steps to send combined messages are as follows:

  1. Construct the combined message body using the ZIMCombineMessage object. The parameters include:
ParameterTypeRequiredDescription
titleStringYesThe title of the combined message, with a default maximum length of 20 bytes. If you need to configure it, please contact ZEGOCLOUD technical support.
summaryStringYesThe summary of the combined message, with a default maximum length of 100 bytes. If you need to configure it, please contact ZEGOCLOUD technical support.
messageListList <ZIMMessage>*YesThe original message list to be combined and forwarded. It does not support merging and forwarding messages of signaling, barrage, recall, and system types, and does not support merging and forwarding unsuccessful messages.
Note

ZIM SDK supports including other combined messages in a combined message.

  1. Call the sendMessage interface to send the combined message. For more information about this operation, see Send & Receive messages - Send messages.

The following is an example code for a user to send a combined message in a one-on-one conversation:

Untitled
// Send a combined message in a one-on-one chat session

try {
    // Conversation type, values are one-on-one: peer, room: room, group: group
    ZIMConversationType type = ZIMConversationType.peer;
    ZIMMessageSendConfig config = ZIMMessageSendConfig();
    // The original message list to be combined and forwarded, which can be obtained from the message history
    List<ZIMMessage> messageList = [message1,message2];
    ZIMCombineMessage combineMessage = ZIMCombineMessage(title: 'Title', summary: 'Summary', messageList: messageList);
    ZIMMessageSentResult result = await ZIM.getInstance()!.sendMessage(combineMessage, 'conv_id', type, config);
    // Message sent successfully
} on PlatformException catch (onError){
    onError.code;//Handle according to the error code table
    onError.message;//Error message
}
1
Copied!

Receive combined messages

The callback interface for receiving combined messages is the same as the callback interface for receiving normal messages. Please refer to Send & Receive messages - Receive messages for the specific interface.

Warning

The receive message callback only returns the title, summary, and combination ID of the combined message. If you need to know the content of the combined message, please refer to View Combined Message Details.

The following is an example code for a user to receive combined messages in a one-on-one conversation:

Untitled
// User receives a combined message in a one-on-one chat session
ZIMEventHandler.onReceivePeerMessage = (ZIM zim, List<ZIMMessage> messageList, String fromUserID){
    for(ZIMMessage message in messageList){
    if(message.type == ZIMMessageType.combine){
        // combined message
    }
    }
};
1
Copied!

View combined message details

Operations on a combined message, for example, listening, adding, and historical message pulling, return only the title, summary, and ID of the combined message. To view sub-messages contained in the combined message, call the queryCombineMessageDetail operation.

The result is returned in the ZIMCombineMessageDetailQueriedCallback callback.

Untitled
Future<ZIMCombineMessageDetailQueriedResult> queryCombineMessageDetail(ZIMCombineMessage message);
1
Copied!
ParameterTypeRequiredDescription
messageZIMCombineMessageYesThe combined message to be queried.
Untitled
try {
    // Conversation type, values are one-on-one: peer, room: room, group: group
    ZIMCombineMessageDetailQueriedResult result = await ZIM.getInstance()!.queryCombineMessageDetail(combineMessage);
    // View the combined message, the specific sub-messages are in the messageList of the message in the callback.
    result.message.messageList;
    // Message sent successfully
} on PlatformException catch (onError){
    onError.code;//Handle according to the error code table
    onError.message;//Error message
}
1
Copied!

If one of the sub-messages is a combined message, you need to call the queryCombineMessageDetail operation to obtain the sub-messages of the combined message. If there are multiple nested combined messages, you need to call this operation multiple times accordingly.

Forward messages one by one

Forwarding messages one by one is essentially sending messages that have been successfully sent as parameters to other conversations. It uses the same interface as sending normal messages. Developers can refer to Send & Receive messages - Send messages for details of this interface.

Previous

Insert local messages

Next

Recall messages