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

# Chat use cases

**Chat** is a **use case** built on DNotifier's **realtime 1:1 messaging** layer. You send messages between user IDs, optionally persist history, and build conversation UIs — for support, social, team collaboration, and in-app messaging.

{% hint style="info" %}
Chat is **not** a separate transport. It uses `send` for delivery and chat-specific APIs for history. For raw live updates without conversation semantics, see [Realtime communication use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/realtime-communication.md).
{% endhint %}

***

## What makes chat different from realtime communication

| Aspect           | Realtime communication               | Chat                                    |
| ---------------- | ------------------------------------ | --------------------------------------- |
| **Purpose**      | Deliver payloads to IDs              | Human (or bot) conversations            |
| **History**      | Optional per message (`saveHistory`) | Fetch thread via `fetchChatHistory`     |
| **UX**           | Events, metrics, notifications       | Threads, bubbles, read state (your UI)  |
| **Participants** | Any sender/receiver IDs              | Typically paired user IDs or user ↔ bot |

Both use the same **`senderId` / `receiverId`** addressing model.

→ [Chat overview](https://dnotifier.gitbook.io/product-docs/chat/overview.md) · [Building 1:1 chat](https://dnotifier.gitbook.io/product-docs/chat/building-one-to-one-chat.md)

***

## Customer support chat

Help desks and SaaS products need end users to message support staff in real time.

### Pattern

| Component         | Role                                                                           |
| ----------------- | ------------------------------------------------------------------------------ |
| **End user**      | Connects as `user-{customerId}`; sends to `support-queue` or assigned agent ID |
| **Agent console** | Connects as `agent-{staffId}`; receives customer messages                      |
| **History**       | `fetchChatHistory` between customer and agent IDs for context                  |
| **Routing**       | Your backend assigns `receiverId` when agent claims ticket                     |

### Example flow

1. Customer opens widget → SDK connects, sends first message to support pool ID.
2. Agent dashboard connects; your server reassigns thread so messages route agent ↔ customer IDs.
3. Both sides use `onMessage` + history fetch on load.
4. Optional: add **AI** for first-line answers before human handoff — [Combined use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/combined.md).

→ [Chat UI patterns](https://dnotifier.gitbook.io/product-docs/chat/ui-patterns.md) · [Example: Minimal chat app](https://dnotifier.gitbook.io/product-docs/chat/example-minimal-chat.md)

***

## In-app messaging

Social, marketplace, and B2B apps let users message each other directly.

### Pattern

| Feature         | Implementation                                        |
| --------------- | ----------------------------------------------------- |
| **1:1 threads** | `senderId` = user A, `receiverId` = user B            |
| **Thread list** | Your backend stores pairs or derives from history API |
| **Rich media**  | `send` with `type: "image"`, `"audio"`, `"doc"`       |
| **Delete**      | `deleteChatHistoryMessage` for moderation             |

### Example flow

1. User A opens chat with User B → fetch history for `[userA, userB]`.
2. User A sends text → `send` with both IDs; User B receives in `onMessage` if online.
3. Offline users see history on next connect and fetch.

→ [Structured payloads](https://dnotifier.gitbook.io/product-docs/realtime-communication/structured-payloads.md) · [Chat history](https://dnotifier.gitbook.io/product-docs/chat/chat-history.md)

***

## Team collaboration tools

Internal tools — project updates, standup bots, channel-style team chat — map **teams** to ID schemes you control.

### Pattern

| Approach              | Description                                                                    |
| --------------------- | ------------------------------------------------------------------------------ |
| **Direct messages**   | Standard 1:1 between `employee-{id}` values                                    |
| **Group-style rooms** | Maintain member list; send to each member's `receiverId` (multi-receiver send) |
| **Bot participants**  | Bot connects as `bot-standup`; employees message or receive summaries          |

DNotifier does not provide room primitives — you implement membership and fan-out using **explicit receiver IDs**.

→ [Send to multiple receivers](https://dnotifier.gitbook.io/product-docs/realtime-communication/multiple-receivers.md)

***

## Social applications

Dating, community, and creator platforms prioritize low-latency DMs and media sharing.

### Pattern

| Concern        | Guidance                                                        |
| -------------- | --------------------------------------------------------------- |
| **Identity**   | Map your auth user to stable DNotifier `userId`                 |
| **Moderation** | Delete messages; build report flows in your backend             |
| **Media**      | Image/audio payloads with chunking for large files              |
| **Presence**   | Optional: realtime `{ type: "typing" }` messages to receiver ID |

→ [Save history flag](https://dnotifier.gitbook.io/product-docs/chat/save-history.md) · [Delete chat messages](https://dnotifier.gitbook.io/product-docs/chat/delete-messages.md)

***

## Bot-in-the-thread chat

Automated participants use the same messaging APIs as humans — connect as a bot user ID, respond with `send`.

| Bot type            | Behavior                                                         |
| ------------------- | ---------------------------------------------------------------- |
| **Rule-based**      | Backend listens via connected bot client; replies with templates |
| **AI-powered**      | `sendAI` generates reply; bot sends text to user's ID            |
| **Workflow-driven** | Workflow classifies intent, then bot sends response              |

For AI-heavy bots, see [AI use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/ai.md) and [Combined use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/combined.md).

***

## Chat vs AI chat

| Type                       | API                  | Purpose             |
| -------------------------- | -------------------- | ------------------- |
| **User ↔ user (or agent)** | `send`, chat history | Human conversations |
| **User ↔ AI assistant**    | `sendAI`, AI history | LLM sessions, RAG   |

You can embed both in one UI — tabs for "Messages" and "Assistant" — with separate history backends.

→ [Chat-style AI messages](https://dnotifier.gitbook.io/product-docs/ai/chat-style-messages.md)

***

## Implementation checklist

1. **Choose user ID scheme** — stable, unique per participant (see [Credentials & environment](https://dnotifier.gitbook.io/product-docs/getting-started/credentials.md)).
2. **Connect on login** — WebSocket with `transport: "ws"`.
3. **Load history** — `fetchChatHistory` when opening a thread.
4. **Send messages** — `send` with `saveHistory: true` (default).
5. **Render UI** — [Chat UI patterns](https://dnotifier.gitbook.io/product-docs/chat/ui-patterns.md).
6. **Handle offline** — history on reconnect; optional push notifications via your mobile stack.

***

## Examples and reference

| Resource           | Link                                                                                                    |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| Beginner example   | [Echo bot](https://dnotifier.gitbook.io/product-docs/examples/echo-bot.md)                              |
| Full 1:1 chat      | [1:1 chat example](https://dnotifier.gitbook.io/product-docs/examples/one-to-one-chat.md)               |
| API reference      | [Chat methods](https://dnotifier.gitbook.io/product-docs/reference/chat-methods.md)                     |
| Combined AI + chat | [Combined use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/combined.md) |
