> 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/realtime-communication/send-and-receive.md).

# Send & receive text

The core realtime pattern is **send a JSON payload to a receiver ID** and **handle incoming messages in `onMessage`**. This hub covers the concept; language pages have complete examples.

***

## The `send()` contract

| Field         | Required | Description                                                                                                |
| ------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| `senderId`    | Yes      | Must match the connecting user's `userId`                                                                  |
| `receiverId`  | One of   | Single recipient user ID                                                                                   |
| `receiverIds` | One of   | Multiple recipients (see [Multiple receivers](/product-docs/realtime-communication/multiple-receivers.md)) |
| `data`        | Yes      | JSON-serializable payload — typically `{ type: "text", text: "..." }`                                      |
| `saveHistory` | No       | Default `true` — persist for chat history APIs                                                             |

Example payload:

```json
{
  "type": "text",
  "text": "Hello from DNotifier!"
}
```

Use any `type` string your app understands. DNotifier does not enforce a fixed enum.

***

## Receiving messages

Register `onMessage` when constructing the client:

```
  send({ data: { type, text, ... } })
              │
              ▼
        DNotifier cloud
              │
              ▼
  onMessage({ metadata, payload })
              │
              ├── metadata.sender    → who sent it
              ├── metadata.timestamp → when
              └── payload.toJSON()   → your { type, text, ... }
```

Each message includes:

* **`metadata`** — `sender`, `timestamp`, `id`, `type`
* **`payload`** — body with `toJSON()`, `toString()`, `raw()`, `toBase64()`

→ [Understanding messages](/product-docs/getting-started/understanding-messages.md)

***

## Requirements

* **`transport: "ws"`** — realtime send/receive uses WebSocket
* **`connect()` completed** — `isConnected` must be `true`
* **Matching `appId`** — sender and receiver must use the same application

{% hint style="success" %}
The receiver does not need to be online at send time for history-backed chat. For **live** delivery, the receiver must be connected. See [Chat overview](/product-docs/chat/overview.md) for thread persistence.
{% endhint %}

***

## Language guides

| Language                | Guide                                                                                                      |
| ----------------------- | ---------------------------------------------------------------------------------------------------------- |
| JavaScript / TypeScript | [javascript-typescript.md](/product-docs/realtime-communication/send-and-receive/javascript-typescript.md) |
| Dart / Flutter          | [dart-flutter.md](/product-docs/realtime-communication/send-and-receive/dart-flutter.md)                   |

***

## Related topics

| Topic                     | Link                                                                               |
| ------------------------- | ---------------------------------------------------------------------------------- |
| First message walkthrough | [Your first message](/product-docs/getting-started/first-message.md)               |
| Structured media          | [Structured payloads](/product-docs/realtime-communication/structured-payloads.md) |
| Multiple recipients       | [Multiple receivers](/product-docs/realtime-communication/multiple-receivers.md)   |
| Building chat             | [Building 1:1 chat](/product-docs/chat/building-one-to-one-chat.md)                |
