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

Delete a message

Users can delete any message they themselves have sent. 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);

After a message has been deleted, the onMessageDeleted() method in the channel event handler is invoked on all users' devices including the device where the message was deleted.

Open channel

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

sb.openChannel.addOpenChannelHandler(UNIQUE_HANDLER_ID, channelHandler);

Group channel

const channelHandler = new GroupChannelHandler({
    onMessageDeleted: (channel: BaseChannel, messageId: number) => {
        // ...
    },
});

sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);