> ## 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.

# Receive messages

> Receive customer messages by webhook (message.received), query the history and download inbound media.

When a customer writes to your number, Routa normalizes the message, stores it with `direction: "inbound"` and produces the `message.received` event. You do not deal with the provider payload, or with verifying the provider's webhook.

> [!NOTE]
>
> Required scopes: `webhooks:write` to register the endpoint, `messages:read` to retrieve messages and `media:read` to download media.

## Receive by webhook

**1. Register an endpoint**

Create an HTTPS endpoint that subscribes to `message.received`.

```bash cURL theme={null}
curl https://api.routa.chat/v1/webhook_endpoints \
  -H "Authorization: Bearer $ROUTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/routa",
    "subscribed_types": ["message.received"]
  }'
```

```ts Node.js theme={null}
const webhook = await routa.webhooks.create({
  url: 'https://example.com/webhooks/routa',
  subscribedTypes: ['message.received'],
})

console.log(webhook.secret) // store it safely, it is shown once
```

The returned `secret` is used to [verify the signature](https://docs.routa.chat/en/webhooks/signatures.md) of each delivery. It is shown only on creation (and on rotation).

**2. Verify and process the event**

Validate the signature over the **raw body** and handle `message.received`. The `data` field is the inbound message.

```ts theme={null}
const event = await routa.webhooks.constructEvent(
  rawBody,
  request.headers.get('routa-signature'),
  signingSecret
)

if (event.type === 'message.received') {
  console.log(event.data) // the inbound message
}
```

**3. Answer 2xx quickly**

Return `2xx` within 10 seconds and do the heavy work afterwards. If you are slow or fail, Routa tries again. See [Retries and replay](https://docs.routa.chat/en/webhooks/retries-and-replay.md).

### Example event

```json theme={null}
{
  "id": "evt_01J8...",
  "type": "message.received",
  "api_version": "v1",
  "schema_version": 1,
  "project_id": "proj_01J8...",
  "external_ref": null,
  "sequence": 918300,
  "occurred_at": "2026-09-04T13:25:02.100Z",
  "recorded_at": "2026-09-04T13:25:02.311Z",
  "data": {
    "id": "msg_01J8...",
    "channel": "chan_01J8...",
    "direction": "inbound",
    "origin": null,
    "from": "+5581999999999",
    "to": "+5581988888888",
    "content": { "type": "text", "body": "I want to change my order." },
    "content_redacted_at": null,
    "status": "delivered",
    "failure_code": null,
    "metadata": {},
    "accepted_at": "2026-09-04T13:25:02.100Z",
    "sent_at": null,
    "delivered_at": "2026-09-04T13:25:02.100Z",
    "read_at": null,
    "failed_at": null
  }
}
```

## Inbound content types

The `content` of an inbound message can be `text`, `image`, `document`, `audio`, `video`, `sticker` or `location`. A type Routa does not model yet, such as `interactive` or `contacts`, arrives as `{ "type": "unsupported" }`: the message exists and produces `message.received`. See [Content types](https://docs.routa.chat/en/concepts/messages.md).

> [!NOTE]
>
> Reactions and system notices, such as a contact changing their number, are **ignored on purpose**. They create no message, produce no `message.received` and do not count as usage. Routa does not yet tell you when a contact changes their number.

## Download inbound media

For `image`, `document`, `audio`, `video` and `sticker`, the content carries a `media_id`. Routa downloads and stores the file asynchronously. Ask for a signed URL:

```bash theme={null}
curl https://api.routa.chat/v1/media/med_01J8... \
  -H "Authorization: Bearer $ROUTA_API_KEY"
```

If `status` is `pending`, try again in a moment. The URL is valid for 15 minutes. See [Media](https://docs.routa.chat/en/concepts/media.md).

## Mark as read

To send the read receipt to the customer, call:

```bash theme={null}
curl -X POST https://api.routa.chat/v1/messages/msg_01J8.../read \
  -H "Authorization: Bearer $ROUTA_API_KEY"
```

Only `inbound` messages can be marked as read. For an `outbound` message, the API returns `422 message_direction_invalid`. Scope: `messages:write`.

## Query the history

List inbound messages with cursor pagination:

```bash cURL theme={null}
curl "https://api.routa.chat/v1/messages?direction=inbound&limit=50" \
  -H "Authorization: Bearer $ROUTA_API_KEY"
```

```ts Node.js theme={null}
for await (const message of routa.messages.list({ direction: 'inbound', limit: 50 })) {
  console.log(message.id, message.from, message.content)
}
```

See [Pagination](https://docs.routa.chat/en/reliability/pagination.md).

## Make sure no message is lost

Webhooks are delivered **at least once**, so the same event can arrive more than once. Deduplicate by the event `id`. If your server was down, recover what you missed with [`GET /v1/events`](https://docs.routa.chat/en/webhooks/reconciliation).


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