Delete messages
A user can delete messages they sent in a DM or group chat. In a group chat, the super admin role can delete any message in the group.
How message deletion works
When a user deletes a message, a DeleteMessage content type containing the target message ID is sent to the conversation. Clients receiving this message validate the deletion request and filter the deleted message from queries.
When you query messages, the client automatically:
- Replaces deleted messages with a placeholder that indicates whether the sender or an admin deleted it
- Filters out the
DeleteMessagecontent type from message lists
The deletion mechanism does NOT remove the original message from:
- Local databases
- Network nodes
- Backup systems
What can't be deleted
The following message types cannot be deleted:
- Group membership changes (members added/removed)
- Group update messages (name, description, image changes)
Attempting to delete these messages will throw an error.
Delete a message
// Delete a message by its ID
await conversation.deleteMessage(messageId);Handle delete message errors
The method throws an error if the deletion fails, such as when attempting to delete a message you didn't send (and you're not a super admin).
try {
await conversation.deleteMessage(messageId);
// Message deleted successfully
} catch (error) {
console.log(`Failed to delete message: ${error}`);
}Stream message deletions
Listen for message deletion events in real-time across all conversations. This method is available on the conversations object.
// Stream all message deletions
const stream = await client.conversations.streamDeletedMessages();
for await (const deletedMessageId of stream) {
console.log("Message deleted:", deletedMessageId);
}
