> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/chat/delete-messages.md).

# Delete chat messages

Remove a persisted chat message with **`deleteChatHistoryMessage`**. Use this for user-initiated deletes, moderation, and compliance workflows.

***

## API contract

| Field       | Required | Description                                     |
| ----------- | -------- | ----------------------------------------------- |
| `senderId`  | Yes      | The acting user (must match connected `userId`) |
| `messageId` | Yes      | ID of the message to delete                     |

```js
await notifier.deleteChatHistoryMessage({
  senderId: "user-alice",
  messageId: "message-id-to-delete",
});
```

The `messageId` typically comes from `metadata.id` on received messages or from history fetch results.

***

## UX pattern

1. User long-presses a message → show delete option
2. Call `deleteChatHistoryMessage` with the message's `id`
3. Remove the message from local UI state
4. Optionally notify the peer via a separate `send()` with `{ type: "message-deleted", messageId }` if your app needs live sync

{% hint style="info" %}
Deletion removes the message from DNotifier chat history storage. Live UI updates for the peer require your app to send a notification or refetch history.
{% endhint %}

***

## Language guides

| Language                | Guide                                                                                   |
| ----------------------- | --------------------------------------------------------------------------------------- |
| JavaScript / TypeScript | [javascript-typescript.md](/product-docs/chat/delete-messages/javascript-typescript.md) |
| Dart / Flutter          | [dart-flutter.md](/product-docs/chat/delete-messages/dart-flutter.md)                   |

***

## Related topics

* [Chat history](/product-docs/chat/chat-history.md)
* [Save history flag](/product-docs/chat/save-history.md)
* [Chat UI patterns](/product-docs/chat/ui-patterns.md)
