> 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/session-logging/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

Enable dashboard AI telemetry with **`logs: true`** on the `DNotifier` constructor.

## Complete example

```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,
  logs: true,
  onConnected: () => console.log("Ready — logging enabled"),
  onMessage: () => {},
  onDisconnected: () => {},
});

await notifier.connect();

const response = await notifier.sendAI({
  senderId: USER_ID,
  message: {
    messages: [
      { role: "system", content: "You are a concise assistant." },
      { role: "user", content: "Explain session logging in one paragraph." },
    ],
  },
});

console.log(response?.data?.content ?? response);
// Check app.dnotifier.com → Logs for this session
```

## Production API service

```js
function createAiNotifier(serviceUserId) {
  return new DNotifier({
    appId: process.env.DNOTIFIER_APP_ID,
    secret: process.env.DNOTIFIER_SECRET,
    transport: "http",
    userId: serviceUserId,
    logs: process.env.NODE_ENV === "production",
    onConnected: () => {},
    onMessage: () => {},
    onDisconnected: () => {},
  });
}
```

## With session continuation

Logging tracks each `sendAI` call. When you pass `sessionId`, the SDK marks it as an existing session:

```js
const first = await notifier.sendAI({
  senderId: USER_ID,
  message: { text: "Start logged session." },
});

const sessionId = first?.metadata?.packet?.id ?? first?.metadata?.id;

await notifier.sendAI({
  senderId: USER_ID,
  sessionId,
  message: { text: "Follow-up — also logged." },
});
```

## Disable logging locally

```js
const notifier = new DNotifier({
  // ...
  logs: process.env.DNOTIFIER_LOGS === "true",
});
```

## Learn more

* [**Sessions**](https://dnotifier.gitbook.io/product-docs/ai/sessions/javascript-typescript.md)
* [**Workflow observability**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/observability.md)
