> 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/reference/chat-methods/javascript-typescript.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# JavaScript / TypeScript

## `fetchChatHistory(options)`

Request stored messages between the sender and one or more receivers.

| Parameter     | Type       | Required | Description           |
| ------------- | ---------- | -------- | --------------------- |
| `senderId`    | `string`   | ✅        | Requesting user id    |
| `receiverIds` | `string[]` | ✅        | Other participant ids |

**Server metadata:** `type: "text"`, `code: 201`

**Returns:**

| Transport | Behavior                                        |
| --------- | ----------------------------------------------- |
| `http`    | History payload in RPC response                 |
| `ws`      | Request sent; history delivered via `onMessage` |

```js
await notifier.fetchChatHistory({
  senderId: "user-alice",
  receiverIds: ["user-bob"],
});
```

Handle history in `onMessage` when using WebSocket:

```js
onMessage: (msg) => {
  const body = msg.payload.toJSON();
  // Inspect body for history array shape from your server plan
},
```

## `deleteChatHistoryMessage(options)`

Delete one message from chat history by id.

| Parameter   | Type     | Required | Description          |
| ----------- | -------- | -------- | -------------------- |
| `senderId`  | `string` | ✅        | Requesting user id   |
| `messageId` | `string` | ✅        | Message id to delete |

**Server metadata:** `type: "text"`, `code: 202`

```js
await notifier.deleteChatHistoryMessage({
  senderId: "user-alice",
  messageId: "msg-uuid-here",
});
```

## Errors

| Error                    | Cause                                |
| ------------------------ | ------------------------------------ |
| `"Not connected"`        | Not authenticated                    |
| `"senderId required"`    | Missing sender                       |
| `"receiverIds required"` | `fetchChatHistory` without receivers |
| `"messageId required"`   | Delete without id                    |
