> 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/structured-payloads.md).

# Structured payloads (image, audio, doc)

Send **rich media and file attachments** through `send()` using typed `data` objects. The SDK serializes your payload, chunks large content automatically, and delivers a complete message to `onMessage`.

{% hint style="info" %}
Prefer **`send()` with a typed payload** for images, audio, and documents. Use **`sendBinary()`** only when you need raw bytes without JSON structure — see [Binary messaging](/product-docs/realtime-communication/binary-messaging.md).
{% endhint %}

***

## Recommended payload types

| `data.type` | Typical fields                    | Use case         |
| ----------- | --------------------------------- | ---------------- |
| `text`      | `text`                            | Chat messages    |
| `image`     | `content` (bytes)                 | Photo sharing    |
| `audio`     | `content`, `durationMs`           | Voice notes      |
| `doc`       | `content`, `fileName`, `mimeType` | File attachments |

DNotifier does not enforce a fixed enum — define conventions in your app and handle them in `onMessage`.

***

## Sending flow

```
  read file bytes locally
         │
         ▼
  send({ data: { type: "image", content: bytes } })
         │
         ▼
  SDK chunks if > messageSizeLimit
         │
         ▼
  receiver onMessage → payload.toJSON() or raw()
```

Large files are split automatically. Your handler always receives a **reassembled** payload.

→ [Large messages & chunking](/product-docs/realtime-communication/chunking.md)

***

## Receiving structured payloads

In `onMessage`, branch on `body.type`:

```js
onMessage: (msg) => {
  const body = msg.payload.toJSON();
  if (body?.type === "image") {
    // body.content — image bytes
  } else if (body?.type === "audio") {
    // body.content, body.durationMs
  } else if (body?.type === "doc") {
    // body.content, body.fileName, body.mimeType
  }
},
```

***

## Language guides

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

***

## Related topics

* [Send & receive text](/product-docs/realtime-communication/send-and-receive.md)
* [Chat UI patterns](/product-docs/chat/ui-patterns.md) — rendering media in bubbles
* [Save history flag](/product-docs/chat/save-history.md)
