> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routa.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Messages and lifecycle

> The message object, the content types and how the status moves from accepted to read or failed.

A message is a communication in either direction: `outbound` (sent from the channel's number, through the API or, on channels in coexistence mode, from the WhatsApp Business app) or `inbound` (received from a customer). It does not depend on the provider: the same object serves any channel, present or future.

## The message object

```json theme={null}
{
  "id": "msg_01J8ZK9M3Q7X...",
  "channel": "chan_01J8...",
  "direction": "outbound",
  "origin": "api",
  "from": "+5581988888888",
  "to": "+5581999999999",
  "content": { "type": "text", "body": "Hi! Your order is confirmed." },
  "content_redacted_at": null,
  "status": "delivered",
  "failure_code": null,
  "metadata": { "order_id": "1234" },
  "accepted_at": "2026-09-04T13:22:40.812Z",
  "sent_at": "2026-09-04T13:22:41.031Z",
  "delivered_at": "2026-09-04T13:22:42.402Z",
  "read_at": null,
  "failed_at": null
}
```

| Field | Description |
| - | - |
| `id` | Message ID (`msg_...`). |
| `channel` | Channel used (`chan_...`). |
| `direction` | `outbound` or `inbound`. |
| `origin` | Where an `outbound` message came from: `api` (sent through Routa) or `business_app` (the business sent it from the WhatsApp Business app). It is `null` on `inbound` messages. Always present. See [Messages sent from the WhatsApp Business app](#messages-sent-from-the-whatsapp-business-app). |
| `from`, `to` | Addresses in E.164 format. On a message with `origin: "business_app"`, `to` can be a provider identifier instead of a number. |
| `content` | Content, an object with a `type`. See the content types table below. It is `null` once retention removes the content. |
| `content_redacted_at` | When retention removed the content, or `null` while the message still has it. |
| `status` | Current state in the lifecycle. |
| `failure_code` | Reason for the failure. It is `null` until the message fails. See [Failure reasons](#failure-reasons). |
| `metadata` | Up to 20 text key-value pairs that you own. Up to 1 KB in total. |
| `accepted_at` | When Routa accepted the message. Always present. |
| `sent_at`, `delivered_at`, `read_at`, `failed_at` | Time of each transition, or `null` if it has not happened. |

Use `metadata` to link the message to your domain, such as the order ID. It is returned when you retrieve the message and in its events.

### Content removed by retention

Routa keeps the content of a message for a period that depends on your plan. After that, the content is removed: `content` becomes `null` and `content_redacted_at` gives the time of the removal. The rest of the message stays, including `metadata`.

> [!NOTE]
>
> Treat `content` as optional when you read old messages. The removal is permanent: extending retention later does not bring the content back. The `message.*` events already delivered do not change. See [Data retention](https://docs.routa.chat/en/reliability/delivery-guarantees.md#message-content-retention).

## Lifecycle

```text theme={null}
accepted ──► sent ──► delivered ──► read
    │          │
    └──────────┴──► failed        (terminal)
```

| Status | Meaning |
| - | - |
| `accepted` | Routa stored the message durably. It has not reached the provider yet. |
| `sent` | The provider accepted the message. |
| `delivered` | The provider confirmed delivery to the recipient's device. |
| `read` | The recipient read the message (when the channel offers read receipts). |
| `failed` | Terminal failure. |

> [!WARNING]
>
> `202 Accepted` on creation only means `accepted`. Delivery happens later, asynchronously. Treat the message as delivered only when you receive `delivered`.

### The status never goes back

Providers send status updates out of order and more than once. Routa only applies a transition that moves forward in the cycle, so a message never goes from `read` back to `sent` because an old notice arrived late. You can write `if (message.status === 'delivered')` with no defensive ordering logic.

`failed` is accepted only while the message has not been delivered yet (`accepted` or `sent`).

### Retries are not a status

If the provider fails temporarily, Routa tries again on its own, with growing delays. Meanwhile the message stays `accepted`. There is no `queued` or `retrying` status in the public API. If the attempts run out, the message becomes `failed`. The reason shows up in the message timeline in the dashboard.

### Failure reasons

`failure_code` explains why the message became `failed`. It is never a provider code.

| Value | Meaning |
| - | - |
| `invalid_recipient` | The recipient is not a number WhatsApp can reach. |
| `session_expired` | The 24-hour customer service window ended. Outside it, only an approved [template](https://docs.routa.chat/en/concepts/templates.md) can start the conversation. |
| `content_rejected` | The provider refused the content or the parameters of the message. |
| `media_unavailable` | A file of the message, such as a template header file, became unavailable before sending. There is no retry: upload the file again with [`POST /v1/media`](https://docs.routa.chat/en/api-reference/endpoint/media/upload) and create another message. |
| `provider_payment_issue` | WhatsApp refused the send because of a problem with the payment method of the WhatsApp Business account, such as a missing payment method, an exceeded credit limit or an account with no currency or time zone set. There is no retry and the channel stays as it was. Only the account owner can solve it, on WhatsApp. The failure can arrive after `sent`. |
| `unsupported_by_app` | The channel's number is also in the WhatsApp Business app and the provider could not deliver the message. It can happen on the first message or with a linked device it does not support. There is no retry: open the app and confirm the conversation. |
| `provider_auth_failed` | The provider refused the channel credential or restricted the account. Check the channel in the dashboard. |
| `provider_unavailable` | The provider was unavailable. |
| `provider_rate_limited` | The provider rate limited the send. |
| `provider_internal` | The provider answered with an error it does not explain. |
| `provider_reported_failure` | The provider reported the failure without a reason Routa recognizes. |
| `dispatch_exhausted` | The send attempts ran out. |
| `channel_inactive`, `channel_not_found`, `capability_unsupported` | The channel stopped being able to send between accept and send. See [Error codes](https://docs.routa.chat/en/errors/error-codes.md). |
| `template_not_found`, `template_not_approved`, `template_paused` | The template stopped being approved between accept and send. |

> [!NOTE]
>
> The set can grow. Treat an unknown value as a generic failure and use `failure_code` only to decide what to show or log.

## Inbound messages

An inbound message starts with `direction: "inbound"` and `status: "delivered"`, and produces the `message.received` event. To tell the sender you read it, use `POST /v1/messages/{id}/read`, which moves the message to `read`.

A content type Routa cannot model yet, such as `interactive` or `contacts`, arrives as `{ "type": "unsupported" }`: the message exists and produces `message.received`.

Two inbound things are **ignored on purpose**: reactions and system notices, such as a contact changing their number. They create no message, produce no `message.received` and do not count as usage.

## Messages sent from the WhatsApp Business app

On a channel connected **in coexistence mode**, the number stays in the WhatsApp Business app. What the business sends from the app, or from a linked device, also shows up in the API.

* The message is `outbound`, with `origin: "business_app"`. Routa did not send it: it only records it.
* It starts as `sent`, without going through `accepted`. The only event is `message.sent`, with no `message.accepted`. `accepted_at` and `sent_at` mark the moment the business sent it.
* Later status changes (`message.delivered`, `message.read` and `message.failed`) arrive as usual.
* It **uses none of your allowance** and does not appear in [`GET /v1/usage`](https://docs.routa.chat/en/billing/usage).
* `to` is the number in E.164 format. When the provider only reports an identifier of the person, `to` carries that identifier instead of a number. The same customer, by number and by identifier, appears as two conversations.
* If the business edits the text or the caption in the app, `content` is updated. If it deletes the message, `content` becomes `null` and `content_redacted_at` records the moment. Neither produces an event.

### Imported history

When the channel is connected, Routa **silently** imports the conversations the business already had in the app. These messages appear in `GET /v1/messages` and `GET /v1/messages/{id}`, but:

* They produce no event or webhook, use none of your allowance and do not count as usage.
* `accepted_at` is the original time of the message, so the order follows real time. Those sent by the business have `origin: "business_app"`, and the received ones, `origin: null`.
* Content older than your plan's [retention](https://docs.routa.chat/en/reliability/delivery-guarantees.md#message-content-retention) already arrives with `content: null` and `content_redacted_at`.
* Only text and location carry content. Images, audio, videos and documents arrive as `{ "type": "unsupported" }`.

## Content types

The `content` field is an object discriminated by `type`.

| `type` | Fields | Notes |
| - | - | - |
| `text` | `body` | Text message. |
| `template` | `template_id`, `body_parameters`, `header_parameter?`, `button_parameters?` | Approved template. See [Template content](#template-content). |
| `image` | `media_id`, `caption?` | Image. |
| `document` | `media_id`, `filename?`, `caption?` | Document. |
| `audio` | `media_id` | Audio. |
| `video` | `media_id`, `caption?` | Video. |
| `sticker` | `media_id` | Sticker. |
| `location` | `latitude`, `longitude`, `name?`, `address?` | Location. |
| `reaction` | `target_message_id`, `emoji` | Reaction to another message. The type exists in the schema, but no message uses it today: inbound reactions are ignored and `POST /v1/messages` does not send reactions. |
| `unsupported` | n/a | Received content of a type Routa does not model yet. |

> [!NOTE]
>
> Today `POST /v1/messages` sends only `text` and `template`. The other types, except `reaction`, appear in inbound messages and in the history, and you can read them as usual. To download the media of a message, use its `media_id` in [`GET /v1/media/{id}`](https://docs.routa.chat/en/api-reference/endpoint/media/retrieve).

### Template content

The content keeps the values as you sent them:

```json theme={null}
{
  "type": "template",
  "template_id": "tmpl_01J8...",
  "body_parameters": ["Ana", "1234"],
  "header_parameter": { "media_id": "med_01J8...", "filename": "invoice.pdf" },
  "button_parameters": [{ "index": 1, "text": "1234" }]
}
```

| Field | Description |
| - | - |
| `header_parameter` | `{ "text" }`, the value of the header variable, or `{ "media_id", "filename"? }`, the file of a media header. Never a URL. |
| `button_parameters` | One `{ "index", "text" }` item per URL button with a variable. `index` is the position of the button in the template, starting at 0. |

Both keys are absent when the template asks for nothing there, and on old messages. See [Header and buttons](https://docs.routa.chat/en/guides/send-template-message.md#header-and-buttons).

## Validation at accept time

Routa validates the message **when it accepts it**, not when it sends it. This turns predictable problems into an immediate `422` error instead of a `message.failed` seconds later:

* The channel must be `active` (`channel_inactive`).
* The channel must support the content type (`capability_unsupported`).
* The recipient must be a valid number (`invalid_recipient`).
* A template must be approved and sendable (`template_not_approved`, `template_paused`, `template_not_sendable`).
* The body, header and button parameters must be exactly what the template asks for (`content_rejected`).
* The file of a media header must belong to this project, be available and have an accepted type (`media_not_found`, `media_not_ready`, `media_content_type_rejected`).
* Provide `text` or `template`. With neither, the API responds `content_rejected`. With both, it sends the template and ignores `text`.

See every code in [Error codes](https://docs.routa.chat/en/errors/error-codes.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.