Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Delete a message in a channel

A user can delete any messages which were sent by themselves. An error is returned if a user attempts to delete messages sent by others. Also channel operators can delete any messages in a channel. This works the same way for both open channels and group channels.

// The MESSAGE argument below indicates a UserMessage or FileMessage object to delete.
await channel.deleteMessage(MESSAGE);

If a message is deleted, the onMessageDeleted() method in the channel event handler will be invoked on all channel participants' devices including the one that deleted the message.

Open channelGroup channel
const channelHandler = new OpenChannelHandler({
    onMessageDeleted: (channel: BaseChannel, message: BaseMessage) => {
        // ...

sb.openChannel.addOpenChannelHandler(UNIQUE_HANDLER_ID, channelHandler);