Skip to main content
Quick Reference for AI Agents & Developers
While deleting a message is straightforward, receiving events for deleted messages with CometChat has two parts:
  1. Adding a listener to receive real-time message deletes when your app is running.
  2. Calling a method to retrieve missed message deletes when your app was not running.
Available via: SDK | REST API | UI Kits

Delete a Message

In other words, as a sender, how do I delete a message? To delete a message, use the deleteMessage() method. This method takes the message ID of the message to be deleted.
This operation is irreversible. Deleted messages cannot be recovered.
On SuccessdeleteMessage() returns the deleted message object with deletedAt and deletedBy fields set:Message Object:
sender Object:
receiver Object:
data Object:
data.entities Object:
data.entities.sender Object:
data.entities.sender.entity Object:
data.entities.receiver Object:
data.entities.receiver.entity Object:
Once the message is deleted, in the onSuccess() callback, you get an object of the BaseMessage class, with the deletedAt field set with the timestamp of the time the message was deleted. Also, the deletedBy field is set. These two fields can be used to identify if the message is deleted while iterating through a list of messages. By default, CometChat allows certain roles to delete a message.

Real-time Message Delete Events

In other words, as a recipient, how do I know when someone deletes a message when my app is running? In order to receive real-time events for a message being deleted, you need to override the onMessageDeleted() method of the MessageListener class.
On EventonMessageDeleted callback receives the deleted message object:Message Object:
sender Object:
receiver Object:
data Object:
data.entities Object:
data.entities.sender Object:
data.entities.sender.entity Object:
data.entities.receiver Object:
data.entities.receiver.entity Object:
Always remove listeners when they are no longer needed (e.g., on component unmount or screen navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.

Missed Message Delete Events

In other words, as a recipient, how do I know if someone deleted a message when my app was not running? When you retrieve the list of previous messages, for the messages that were deleted, the deletedAt and the deletedBy fields will be set. Also, for example, of the total number of messages for a conversation are 100, and the message with message ID 50 was deleted. Now the message with id 50 will have the deletedAt and the deletedBy fields set whenever it is pulled from the history. Also, the 101st message will be an Action message informing you that the message with id 50 has been deleted.
When fetching message history — deleted messages have deletedAt and deletedBy fields set:Message Object (per item in array):
sender Object:
receiver Object:
data Object:
data.entities Object:
data.entities.sender Object:
data.entities.sender.entity Object:
data.entities.receiver Object:
data.entities.receiver.entity Object:
For the message deleted event, in the Action object received, the following fields can help you get the relevant information-
  1. action - deleted
  2. actionOn - Updated message object which was deleted.
  3. actionBy - User object containing the details of the user who has deleted the message.
  4. actionFor - User/group object having the details of the receiver to which the message was sent.
When fetching message history, deleted messages include deletedAt and deletedBy fields. You can check if deletedAt is set to identify deleted messages. Additionally, an Action message with action: "deleted" is added to the message list for audit/timeline purposes.
In order to edit or delete 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.
  • Check deletedAt when rendering messages. Before displaying a message, check if deletedAt is set. If it is, show a “This message was deleted” placeholder instead of the original content.
  • Use unique listener IDs. Use a unique identifier per screen or component (e.g., "ChatScreen_DeleteListener") to avoid conflicts with other listeners.
  • Always clean up listeners. Remove message listeners in your component’s cleanup or unmount lifecycle to prevent memory leaks.
  • Handle permissions gracefully. If a user attempts to delete a message they don’t have permission to delete, handle the error callback and inform the user.
  • “Message delete failed” error: Verify that the message ID is valid and that the current user has permission to delete the message (sender, group admin, or group moderator).
  • onMessageDeleted not firing: Ensure you have registered the MessageListener with CometChat.addMessageListener() before the delete event occurs, and that the listener ID is unique.
  • Deleted messages still showing in the UI: Make sure you are checking the deletedAt field on each message when rendering your message list, and updating your local state when onMessageDeleted fires.
  • Duplicate delete events: This usually happens when multiple listeners are registered with the same or different IDs without being removed. Ensure you remove listeners on component unmount.

Next Steps

Edit a Message

Modify the content of a sent message

Send Messages

Send text, media, and custom messages

Receive Messages

Listen for and retrieve incoming messages

Flag a Message

Report inappropriate or unwanted messages