Skip to main content
Quick Reference - Edit a text message:
let receiverID = "RECEIVER_UID";
let messageText = "Updated message text";
let receiverType = CometChat.RECEIVER_TYPE.USER;
let textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);
textMessage.setId(MESSAGE_ID);

CometChat.editMessage(textMessage).then(
  message => console.log("Message Edited", message),
  error => console.log("Edit failed:", error)
);
Available via: SDK | REST API | UI Kits
While editing a message is straightforward, receiving events for edited messages with CometChat has two parts:
  1. Adding a listener to receive real-time message edits when your app is running.
  2. Calling a method to retrieve missed message edits when your app was not running.

Edit a Message

In other words, as a sender, how do I edit a message? To edit a message, you can use the editMessage() method. This method takes an object of the BaseMessage class. At the moment, you are only allowed to edit TextMessage and CustomMessage. Thus, the BaseMessage object must either be a Text or a Custom Message.

Add/Update Tags

While editing a message, you can update the tags associated with the message. Use the setTags() method to do so. The tags added while editing a message will replace the tags set when the message was sent.
let tags = ["pinnedMessage"];

textMessage.setTags(tags);
Once the message object is ready, you can use the editMessage() method and pass the message object to it.
let receiverID = "RECEIVER_UID";
let messageText = "Hello world!";
let receiverType = CometChat.RECEIVER_TYPE.USER;
let messageId = "MESSAGE_ID_OF_THE_MESSAGE_TO_BE_EDITED";
let textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);

textMessage.setId(messageId);

CometChat.editMessage(textMessage).then(
message => {
  console.log("Message Edited", message);
}, error => {
  console.log("Message editing failed with error:", error);
}
);
On SuccesseditMessage() returns the edited message object with editedAt and editedBy fields:Message Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25652"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringEdited message text content"Nice, Any Update?"
sentAtnumberUnix timestamp when originally sent1772446840
editedAtnumberUnix timestamp when edited1772446861
editedBystringUID of user who edited the message"cometchat-uid-6"
deliveredAtnumberUnix timestamp when delivered1772446841
readAtnumberUnix timestamp when read1772446841
updatedAtnumberUnix timestamp when updated1772446841
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446655
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446782
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice, Any Update?"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓
moderationobjectModeration status{"status": "approved"}

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446655
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446782
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue

metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue
The object of the edited message will be returned in the onSuccess() callback method of the listener. The message object will contain the editedAt field set with the timestamp of the time the message was edited. This will help you identify if the message was edited while iterating through the list of messages. The editedBy field is also set to the UID of the user who edited the message. By default, CometChat allows certain roles to edit a message.
User RoleConversation TypeEdit Capabilities
Message SenderOne-on-One ConversationMessages they have sent.
Message SenderGroup ConversationMessages they have sent.
Group OwnerGroup ConversationAll messages in the group.
Group ModeratorGroup ConversationAll messages in the group.

Real-time Message Edit Events

In other words, as a recipient, how do I know when someone has edited their message when my app is running? To receive real-time events for a message being edited, you need to override the onMessageEdited() method of the MessageListener class.
var listenerID = "UNIQUE_LISTENER_ID";

CometChat.addMessageListener(
listenerID,
new CometChat.MessageListener({
  onMessageEdited: message => {
    console.log("Edited Message", message);
  }
})
);  
On EventonMessageEdited callback receives the edited message object:Message Object:
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25652"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringEdited message text content"Nice, Any Update?"
sentAtnumberUnix timestamp when originally sent1772446840
editedAtnumberUnix timestamp when edited1772446861
editedBystringUID of user who edited the message"cometchat-uid-6"
deliveredAtnumberUnix timestamp when delivered1772446841
readAtnumberUnix timestamp when read1772446841
updatedAtnumberUnix timestamp when updated1772446841
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446655
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446782
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice, Any Update?"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓
moderationobjectModeration status{"status": "approved"}

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446655
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446782
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue

metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue
Always remove your message listeners when the component unmounts to prevent memory leaks and unexpected behavior. Call CometChat.removeMessageListener("UNIQUE_LISTENER_ID") in your cleanup function (e.g., in a useEffect return or componentWillUnmount).

Missed Message Edit Events

In other words, as a recipient, how do I know when someone edited their message when my app was not running? When you retrieve the list of previous messages, for the message that was edited, the editedAt and the editedBy fields will be set. Also, for example, if the total number of messages for a conversation is 100, and the message with message ID 50 was edited, the message with ID 50 will have the editedAt and the editedBy fields set whenever it is pulled from the history. Additionally, the 101st message will be an [Action] message informing you that the message with ID 50 has been edited.
When fetching message history — edited messages have editedAt and editedBy fields set:Message Object (per item in array):
ParameterTypeDescriptionSample Value
idstringUnique message identifier"25652"
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
receiverIdstringReceiver’s UID"cometchat-uid-7"
receiverTypestringType of receiver"user"
typestringMessage type"text"
categorystringMessage category"message"
textstringEdited message text content"Nice, Any Update?"
sentAtnumberUnix timestamp when originally sent1772446840
editedAtnumberUnix timestamp when edited1772446861
editedBystringUID of user who edited the message"cometchat-uid-6"
deliveredAtnumberUnix timestamp when delivered1772446841
readAtnumberUnix timestamp when read1772446841
updatedAtnumberUnix timestamp when updated1772446841
senderobjectSender user detailsSee below ↓
receiverobjectReceiver user detailsSee below ↓
dataobjectAdditional message dataSee below ↓
metadataobjectMessage metadataSee below ↓
reactionsarrayMessage reactions[]
mentionedUsersarrayUsers mentioned in message[]
mentionedMebooleanWhether current user is mentionedfalse

sender Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446655
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

receiver Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringURL to user’s avatar"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
statusstringUser’s online status"online"
rolestringUser’s role"default"
lastActiveAtnumberLast active timestamp1772446782
hasBlockedMebooleanWhether user has blocked current userfalse
blockedByMebooleanWhether current user blocked this userfalse
deactivatedAtnumberDeactivation timestamp (0 if active)0
tagsarrayUser tags[]

data Object:
ParameterTypeDescriptionSample Value
textstringMessage text"Nice, Any Update?"
resourcestringSDK resource identifier"REACT_NATIVE-4_0_14-..."
entitiesobjectSender and receiver entitiesSee below ↓
metadataobjectInjected metadataSee below ↓
moderationobjectModeration status{"status": "approved"}

data.entities Object:
ParameterTypeDescriptionSample Value
senderobjectSender entity wrapperSee below ↓
receiverobjectReceiver entity wrapperSee below ↓

data.entities.sender Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.sender.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-6"
namestringUser’s display name"Ronald Jerry"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446655
tagsarrayUser tags[]

data.entities.receiver Object:
ParameterTypeDescriptionSample Value
entityTypestringType of entity"user"
entityobjectUser entity detailsSee below ↓

data.entities.receiver.entity Object:
ParameterTypeDescriptionSample Value
uidstringUser’s unique identifier"cometchat-uid-7"
namestringUser’s display name"Henry Marino"
avatarstringUser’s avatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"
rolestringUser’s role"default"
statusstringUser’s online status"online"
lastActiveAtnumberLast active timestamp1772446782
conversationIdstringConversation identifier"cometchat-uid-6_user_cometchat-uid-7"
tagsarrayUser tags[]

data.metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue

metadata Object:
ParameterTypeDescriptionSample Value
editedbooleanIndicates message was editedtrue
For the message edited event, in the Action object received, the following fields can help you get the relevant information:
  1. action - edited
  2. actionOn - Updated message object with the edited details.
  3. actionBy - User object containing the details of the user who has edited the message.
  4. actionFor - User/group object having the details of the receiver to which the message was sent.
To edit a message, you need to be either the sender of the message or the admin/moderator of the group in which the message was sent.
  • Always verify the message type (TextMessage or CustomMessage) before attempting an edit, as other message types are not supported.
  • Use the editedAt and editedBy fields to display edit indicators in your UI so users know a message has been modified.
  • Register your message edit listener early in the component lifecycle to avoid missing real-time edit events.
  • When updating tags via setTags(), remember that the new tags fully replace any previously set tags — merge existing tags manually if you need to preserve them.
  • Edit fails with permission error: Ensure the current user is the message sender, or a group owner/moderator for group messages.
  • onMessageEdited not firing: Confirm that CometChat.addMessageListener() has been called with a unique listener ID and that the listener has not been removed prematurely.
  • Edited message not reflected in history: After editing, re-fetch or update the local message list. The editedAt field on the message object confirms the edit was applied.
  • Tags not updating: Make sure you call setTags() on the message object before passing it to editMessage(). Tags set during editing replace all previous tags.

Next Steps