---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/messages/delete
title: Delete messages
updated_at: 2026-05-19T12:09:42.841Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Delete messages

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

:::note Requires Message Persistence
Enable [Message Persistence](https://youtu.be/qLMtbINWGig) and **Enable Delete-From-History** in the [Admin Portal](https://admin.pubnub.com/).
:::

### Method signature

##### Under the hood

`delete()` calls Message Actions API and the JavaScript SDK [addMessageAction()](https://www.pubnub.com/docs/sdks/javascript/api-reference/message-actions#add-message-reaction) method to mark the removed messages as `deleted` (for soft delete), the Message Persistence API and the [deleteMessages()](https://www.pubnub.com/docs/sdks/javascript/api-reference/storage-and-playback#delete-messages-from-history) method to permanently remove messages from Message Persistence, and the Files API with the [deleteFile()](https://www.pubnub.com/docs/sdks/javascript/api-reference/files#delete-file) method to remove files attached to the message.

This method takes the following parameters:

```ts
message.delete(
    {
        soft?: boolean,
        preserveFiles?: boolean
    }
): Promise<true | Message>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| soft | boolean | Optional | `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](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/message) gets the `deleted` status and you can still restore/get its data. |
| preserveFiles | boolean | Optional | `false` | Define if you want to keep the files attached to the message or remove them. |

#### Output

| Type | Description |
| --- | --- |
| `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.

```ts
// reference the "message" object
const { messages } = await channel.getHistory({
    startTimetoken: "16200000000000000",
    endTimetoken: "162000000000000001"
})
const message = messages[0]
// invoke the "delete()" method. By default, the "soft" parameter is set to "false" and can be skipped.
await message.delete()
```

### Other examples

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

```ts
await message.delete({
    soft: true
})
```