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

Modify a Message

Feature Description

This feature enables any member in a conversation to modify a successfully sent message in the conversation. The message will be synced to all the members in the conversation once modified successfully.

Display Effect

You can use the message modification API to change the cloudCustomData of a message, enabling features such as message replies and references as shown below:


modifyMessage

Modifying a Message

This API is used to modify a message. After a user modifies a message successfully, both the user and the receiver (one-to-one) or group members (Group) will receive the MESSAGE_MODIFIED event.
Note
1. It does not support modifying online messages or audio-video group messages. Do not modify the random, sequence, or time fields of a message.
2. It only supports modifying text, custom, geographical location, and emoji messages.
3. If a message is modified by another member during modification, the SDK will return the error code 2480, indicating that a conflict occurred while modifying the message.
4. It supports for modifying the cloudCustomData field of all types of messages.
API
chat.modifyMessage(message);
Parameter
Name
Type
Description
message
Message
Message instance
Returned value
Promise
Sample
// Listen for the `MESSAGE_MODIFIED` event
// which will be delivered by the SDK after a message is modified successfully
let onMessageModified = function(event) {
// event.data - An array that stores modified Message objects - [Message]
};
chat.on(TencentCloudChat.EVENT.MESSAGE_MODIFIED, onMessageModified);

// Change the text content of `txtMessage` to `Hello Tencent`
txtMessage.payload.text = "Hello Tencent";

let promise = chat.modifyMessage(txtMessage);
promise.then(function(imResponse) {
const { message } = imResponse.data;
// Message modified successfully. `message` is the latest message.
}).catch(function(imError) {
// Failed to modify the message
const { code, data } = imError;
if (code === 2480) {
// A conflict occurred while modifying the message. `data.message` is the latest message.
} else if (code === 2481) {
// Audio-video group messages cannot be modified.
} else if (code === 20026) {
// The message does not exist.
}
});