please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Web/
Message/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Client APIs
  • Changelog
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Historical Message
    • Forward Messages
    • Modify a Message
    • Delete Messages
    • Clear History Message
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Translation
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Group Counter
  • Community Topic
    • Community Management
  • User Profile and Relationship Chain
    • User Profile
    • User Status
    • Friend Management
    • Friend Group
    • Block List
  • 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

Forward Messages

Feature Description

You can merge and forward messages in the following steps:
1. Create a merged message based on the list of original messages.
2. Send the merged message to the receiver.
3. The receiver receives the merged message and parses the list of original messages.
The title and digest are needed to display the merged message, as shown below:
Merge and Forward
Display of Merged Message
Click Merged Message to Download Message List for Display












Creating a Merged Message

This API is used to create a merged message. It returns a message instance, which can be sent by calling the sendMessage API when you need to send a merged message.
Note
1. Unable to merge messages that failed to be sent. If the message list contains a message that failed to be sent, the API will report an error.
API
chat.createMergerMessage(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Default
Description
to
String
-
userID or groupID of the message receiver
conversationType
String
-
Conversation type. Valid values:
TencentCloudChat.TYPES.CONV_C2C (one-to-one conversation)
TencentCloudChat.TYPES.CONV_GROUP (group conversation)
priority
String
TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL
Message priority. If messages in a group exceed the frequency limit, the backend will deliver high-priority messages first. Supported enumerated values:
TencentCloudChat.TYPES.MSG_PRIORITY_HIGH
TencentCloudChat.TYPES.MSG_PRIORITY_NORMAL (default)
TencentCloudChat.TYPES.MSG_PRIORITY_LOW
TencentCloudChat.TYPES.MSG_PRIORITY_LOWEST
payload
Object
-
Message content container
cloudCustomData
String
''
Custom message data, which is saved in the cloud, will be sent to the receiver, and can still be pulled after the application is uninstalled and reinstalled.
The payload is as described below:
Name
Type
Description
messageList
Array
Merged message list
title
String
Title of merged messages, for example, "Chat History of the Talent Center in the Greater Bay Area"
abstractList
String
Digest list. You can set digest information in different formats for different message types, for example, in the sender:text format for a text message, in the sender:[image] format for an image message, or in the sender:[file] format for a file message.
compatibleText
String
Compatibility text. If the early SDK version does not support the merged message, the user will receive a text message with the content ${compatibleText} by default. This field is required.
Returned value
Message
Sample
// 1. Forward group messages to a one-to-one conversation.
// `message1`, `message2`, and `message3` are group messages.
let mergerMessage = chat.createMergerMessage({
to: 'user1',
conversationType: TencentCloudChat.TYPES.CONV_C2C,
payload: {
messageList: [message1, message2, message3],
title: 'Chat History of the Talent Center in the Greater Bay Area',
abstractList: ['allen: 666', 'iris: [Image]', 'linda: [File]'],
compatibleText: 'Upgrade your Chat SDK to v2.10.1 or later to view this message.'
},
// cloudCustomData: 'your cloud custom data'
});

// 2. Send the message.
let promise = chat.sendMessage(mergerMessage);
promise.then(function(imResponse) {
// Message sent successfully
console.log(imResponse);
}).catch(function(imError) {
// Failed to send the message
console.warn('sendMessage error:', imError);
});

Downloading a Merged Message

This API is used to download a merged message. When the merged message sent by the sender is large in size, the SDK will store it in the cloud, and the message receiver needs to download it from the cloud before viewing it.
API
chat.downloadMergerMessage(message);
Parameter
Name
Type
Description
message
Message
Message instance
Returned value
Promise
Sample
// If `downloadKey` exists, the received merged message is stored in the cloud
// and needs to be downloaded first.
if (message.type === TencentCloudChat.TYPES.MSG_MERGER && message.payload.downloadKey !== '') {
let promise = chat.downloadMergerMessage(message);
promise.then(function(imResponse) {
// After the download is successful
// the SDK will update information such as `message.payload.messageList`.
console.log(imResponse.data);
}).catch(function(imError) {
// Download failed
console.warn('downloadMergerMessage error:', imError);
});
}

Forwarding Messages One by One

To forward a single message, create a message identical to the original message through the createForwardMessage API first, and then call the sendMessage API to send the message.
API
chat.createForwardMessage(message);
Parameter
Name
Type
Description
message
Message
Message instance
Returned value
Message
Sample
let forwardMessage = chat.createForwardMessage({
to: 'user1',
conversationType: TencentCloudChat.TYPES.CONV_C2C,
payload: message, // Message instance for the received or sent message
// cloudCustomData: 'your cloud custom data'
});
// 2. Send the message.
let promise = chat.sendMessage(forwardMessage);
promise.then(function(imResponse) {
// Message sent successfully
console.log(imResponse);
}).catch(function(imError) {
// Failed to send the message
console.warn('sendMessage error:', imError);
});