> 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/ai/ai-history/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

Fetch and delete stored **AI conversation** turns over HTTP.

## Fetch history

```js
import { DNotifier } from "@dnotifier-realtime/dnotifier";

const USER_ID = "user-123";

const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "http",
  userId: USER_ID,
  onConnected: () => {},
  onMessage: () => {},
  onDisconnected: () => {},
});

await notifier.connect();

// Create some history
await notifier.sendAI({
  senderId: USER_ID,
  message: { text: "What is your return policy?" },
  saveHistory: true,
});

// Fetch all AI history for this user
const history = await notifier.fetchAIHistory({ senderId: USER_ID });
console.log(history);
```

## Delete a message

```js
const history = await notifier.fetchAIHistory({ senderId: USER_ID });

// Pick messageId from the response shape your app receives
const messageId = history?.data?.messages?.[0]?.id ?? "message-id-to-delete";

await notifier.deleteAIHistoryMessage({
  senderId: USER_ID,
  messageId,
});
```

## API route pattern

```js
app.get("/api/users/:userId/ai-history", async (req, res) => {
  const history = await notifier.fetchAIHistory({
    senderId: req.params.userId,
  });
  res.json(history);
});

app.delete("/api/users/:userId/ai-history/:messageId", async (req, res) => {
  await notifier.deleteAIHistoryMessage({
    senderId: req.params.userId,
    messageId: req.params.messageId,
  });
  res.status(204).end();
});
```

## Skip history for internal calls

```js
await notifier.sendAI({
  senderId: USER_ID,
  message: { text: "Classify: urgent or normal" },
  saveHistory: false,
});
```

## Learn more

* [**Sessions**](https://dnotifier.gitbook.io/product-docs/ai/sessions/javascript-typescript.md) — Multi-turn with `sessionId`
* [**Chat history**](https://dnotifier.gitbook.io/product-docs/chat/chat-history/javascript-typescript.md) — User-to-user messages
