please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
React Native/
Message/
SDK
  • Run Demo
  • SDK Integration
  • Initialization
  • Login and Logout
  • Message
    • Message Overview
    • Sending Message
    • Receiving Message
    • Historical Message
    • Forwarding Message
    • Modifying Message
    • Message Inserting
    • Deleting Message
    • Clearing Messages
    • Recalling Message
    • Online Message
    • Read Receipt
    • Querying Message
    • Group @ Message
    • Targeted Group Message
    • Notification Muting
    • Message Extension
  • Group
    • Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Community Management
  • User
    • User Profile
    • Friend Management
    • Friend List
    • Blocklist
  • Offline Push
    • Offline Push
  • Local Search
    • Searching for Message
    • Searching for Friend
    • Searching Group
    • Searching for Group Member
  • Signaling
    • Signaling Management
  • Changelog
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Forwarding Message

Feature Description

You can implement the feature of merging and forwarding messages as provided by WeChat in the following steps:
1. Create a merged message based on the list of original messages.
2. Send the merged message to the peer end.
3. The peer end receives the merged message and parses the list of original messages.
The title and digest are needed to display the merged message:
Merge and Forward
Display of Merged Message
Click Merged Message to Download Message List for Display




Merging and Forwarding Messages

Creating and sending a merged message

A merged message can be created by setting the message list along with the merged message title and digest. The process is as follows:
1. Call the createMergerMessage API (Details) to create a merged message. The list of original messages as well as the merged message title and digest also need to be set.

Attribute
Description
Remarks
msgIDList
List of IDs of original messages
List of IDs of original messages to be merged and forwarded
title
Title
Title of the merged message, such as "Chat History of xixiyah and Hello"
abstractList
Digest list
Digest list of the merged message. The original message digests need to be displayed for the merged message, which will be unfolded after the user clicks the cell.
compatibleText
Compatibility text message
If the SDK on an early version does not support the merged message, the user will receive a text message with the content compatibleText by default.
Below is the sample code for creating and sending a merged message:
// List of messages to be forwarded, which can contain merged messages but not group tips
const msgIDList = ["msgid1", "msgid2"];
const title = "Chat between user1 and user2";// Combined message title
const abstractList = ["user1:hello", "user2:hello"]; // Digest list of the merged message
const compatibleText = "The current version does not support the message"; // Compatibility text of the merged message. If the SDK on an early version does not support the merged message, the user will receive a text message with the content `compatibleText` by default.
const createMergerMessageResult =
await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.createMergerMessage(
msgIDList,
title, // Title of the merged message
abstractList, // Digest list of the merged message
compatibleText,
);
if (createMergerMessageResult.code == 0) {
TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(
id: createMergerMessageResult.data.id,
receiver: "",
groupID: "",
);
}

Receiving a merged message

Adding a listener

The receiver calls addAdvancedMsgListener (Details) to add the advanced message listener. We recommend it be called early, such as after the chat page is initialized, to ensure timely message receiving in the application.
Below is the sample code:
TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.addAdvancedMsgListener(listener);

Parsing a message

After the listener is added, the receiver will receive the merged message V2TimMessage in onRecvNewMessage. You can use the merged message element V2TimMergerElem (Details) to get the title and abstractList for UI display. Then, when the user clicks the merged message, you can call the downloadMergerMessage (Details) to download the merged message list for UI display.
Below is the sample code:
if(message.elemType == MessageElemType.V2TIM_ELEM_TYPE_MERGER){
message.mergerElem.abstractList;
message.mergerElem.isLayersOverLimit;
message.mergerElem.title;
const download = await TencentImSDKPlugin.v2TIMManager.getMessageManager().downloadMergerMessage(message.msgID,);
if(download.code == 0){
const messageList = download.data;
}
}

Forwarding Messages One by One

To forward a single message, create a message identical to the original message through the createForwardMessage API (Details) first, and then call the sendMessage API (Details) to send the message.
Below is the sample code:
// Create a message with the same elements as the original message
const createForwardMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createForwardMessage("msgid");
// Send the message to the user `denny`
if(createForwardMessageRes.code == 0){
TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: createForwardMessageRes.data.id, receiver: "denny", groupID: "");
}