On this page

Delete messages

delete() permanently removes a message from Message Persistence or marks it as deleted (soft delete).

Requires Message Persistence

Enable Message Persistence and Enable Delete-From-History in the Admin Portal.

Method signature

icon

Under the hood


This method takes the following parameters:

1message.delete(
2 {
3 soft?: boolean
4 },
5 preserveFiles?: boolean
6): Promise<true | Message>

Input

* required
ParameterDescription
soft
Type: boolean
Default:
false
Define if you want to permanently remove message data. By default, the message data gets permanently deleted from Message Persistence. If you set this parameter to true, the Message object gets the deleted status and you can still restore/get its data.
preserveFiles
Type: boolean
Default:
n/a
Define if you want to keep the files attached to the message or remove them.

Output

TypeDescription
Promise<true> or Promise<Message>
For hard delete, a confirmation that the message data was permanently deleted. For soft delete, an updated message instance with an added deleted action type.

Sample code

Permanently delete the message with the 16200000000000001 timetoken from the support channel.

1// reference the "message" object
2const message = await channel.getHistory({
3 startTimetoken: "16200000000000000",
4 endTimetoken: "162000000000000001"
5})
6// invoke the "delete()" method. By default, the "soft" parameter is set to "false" and can be skipped.
7await message.delete()

Other examples

Archive (soft delete) the message with the 16200000000000001 timetoken from the support channel, keeping its data in Message Persistence.

1await message.delete({
2 soft: true
3})
Last updated on