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
This method takes the following parameters:
1message.delete(soft: Boolean = false, preserveFiles: Boolean = false): PNFuture<Message?>
Input
* required
| Parameter | Description |
|---|---|
softType: BooleanDefault: false | When false (default), permanently deletes message data. When true, marks the Message object as deleted while preserving data for restoration. |
preserveFilesType: BooleanDefault: false | Whether to keep files attached to the message. |
Output
| Type | Description |
|---|---|
PNFuture<Message?> | For hard delete, the method returns the last version of the Message object before it 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.
1val channel: Channel
2// ...
3
4// define the timetoken of the message to archive (soft delete)
5val messageTimetoken: Long = 16200000000000001
6
7channel.getMessage(messageTimetoken).async { messageResult ->
8 messageResult.onSuccess { message ->
9 // handle success
10 message?.delete()?.async { deleteResult ->
11 deleteResult.onSuccess {
12 // handle success
13 println("Message successfully deleted: ${it?.timetoken}")
14 }.onFailure {
15 // handle failure
show all 23 linesOther examples
Archive (soft delete) the message with the 16200000000000001 timetoken from the support channel, keeping its data in Message Persistence.
1val channel: Channel
2// ...
3
4// define the timetoken of the message to archive (soft delete)
5val messageTimetoken: Long = 16200000000000001
6
7channel.getMessage(messageTimetoken).async { messageResult ->
8 messageResult.onSuccess { message ->
9 // handle success
10 message?.delete(soft = true)?.async { deleteResult ->
11 deleteResult.onSuccess {
12 // handle success
13 println("Message successfully soft deleted: ${it?.timetoken}")
14 }.onFailure {
15 // handle failure
show all 23 lines