The ZIM SDK supports forwarding messages in one of the following ways:
Before you implement the "Forward Messages" feature, ensure that the following conditions are met:
Below is the procedure:
Call the ZIMCombineMessage operation to construct a combined message. The following table lists the parameters.
Parameter | Type | Required | Description |
---|---|---|---|
type | number | Yes | It must be set to 31, which indicates a combined message. |
title | string | Yes | The title of the combined message, which can contain up to 20 bytes in length. If you need a longer length, contact ZEGO technical support. |
summary | string | Yes | The summary of the combined message, which can contain up to 100 bytes in length. If you need a longer length, contact ZEGO technical support. |
messageList | ZIMMessage[] | Yes | The list of messages to be combined and forwarded. Signaling messages, on-screen comments, recalled messages, system messages, and messages that failed to be sent are not supported. |
The ZIM SDK supports containing a combined message in another combined message.
To send a combined message, call the sendMessage operation. For more information about this operation, see Send & Receive messages - Send messages.
Below is the sample code for sending a combined message in a one-to-one chat:
// Send a combined message in a one-to-one chat.
var toConversationID = ''; // The ID of the other user.
var conversationType = 0; // The conversation type. Valid values: 0: one-to-one chat; 1: voice chatroom; 2: group chat.
var config = {
priority: 1, // Specify the message priority. Valid values: 1 (default): low; 2: medium; 3: high.
};
var messageCombineObj = {
type: 31,
title: 'Title', // The title of the combined message.
summary: 'Summary' , // The summary of the combined message.
messageList: [message1, message2], // The list of messages to be combined and forwarded, which can be obtained from historical messages.
};
var notification = {
onMessageAttached: function(message) {
// To-do: loading.
}
}
zim.sendMessage(messageCombineObj, toConversationID, conversationType, config, notification)
.then(function ({ message }) {
// Sending succeeded.
})
.catch(function (err) {
// Sending failed.
});
Call the same operation for receiving ordinary messages to receive a combined message. For more information about this operation, see Send & Receive messages - Receive messages.
The callback for receiving messages returns only the title, summary, and ID of the combined message. To obtain the combined message content, see View the details of a combined message.
Below is the sample code for receiving a combined message in a one-to-one chat:
// The user receives a combined message in a one-to-one chat.
zim.on('receivePeerMessage', function (zim, { messageList, fromConversationID }) {
console.log(messageList, fromConversationID);
messageList.forEach(function (msg) {
// The `Combine` message is received.
if (msg.type == 31) {
}
})
});
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 ZIMCombineMessageDetailQueriedResult callback.
queryCombineMessageDetail(message: ZIMCombineMessage): Promise<ZIMCombineMessageDetailQueriedResult>
Parameter | Type | Required | Description |
---|---|---|---|
message | ZIMCombineMessage | Yes | The combined message. |
zim.queryCombineMessageDetail(message)
.then(function (message) {
// Operation succeeded. The list of sub-messages of the combined message is updated on the UI.
// The detailed sub-messages are contained in the messageList of the message in the callback.
console.log(message.messageList)
})
.catch(function (err) {
// Operation failed.
});
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.
Forwarding messages one by one is sending messages that are sent successfully to another conversation as a parameter. The operation for achieving this is the same as that for sending ordinary messages. For more information about this operation, see Send & Receive messages - Send messages.