# Messages

## Send a template to a phone

`POST /v1/c/{slug}/messages/template` · Scopes: `messages:send_template`

In the contact's open conversation, or a new one handled the way the number handles what arrives. The contact is created if missing. `idempotencyKey` (or the Idempotency-Key header) prevents sending twice.

### Path parameters

| Field | Notes |
|---|---|
| `slug` | The company's identifier in DoneTalk (the key's own). |

### Request body

| Field | Type | Required | Notes |
|---|---|---|---|
| `phone` | string | yes |  |
| `contactName` | string | no | up to 200 characters |
| `channelId` | string (uuid) | no |  |
| `templateId` | string (uuid) | yes |  |
| `body` | list of string | no | up to 20; default `[]` |
| `header` | list of string | no | up to 5; default `[]` |
| `buttons` | object | no | default `{}` |
| `handling` | one of `number`, `team` | no | default `"number"` |
| `assigneeEmail` | string (email) | no | up to 320 characters |
| `idempotencyKey` | string | yes | up to 200 characters |

### Request example

```bash
curl -X POST "https://api.donetalk.com/v1/c/demo/messages/template" \
  -H "Authorization: Bearer $DONETALK_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "phone": "+5548999990001",
  "contactName": "Ana Souza",
  "templateId": "01a0cad0-0000-7000-8000-000000000002",
  "body": [
    "Ana",
    "ANA10"
  ],
  "idempotencyKey": "pedido-88213-lembrete"
}'
```

### Response 201

```json
{
  "message": {
    "id": "01a3c0de-8b22-7c33-9d44-0e55f6677889",
    "status": "queued"
  },
  "conversation": {
    "id": "01a3c0de-7a11-7b22-8c33-9d44e55f6677"
  },
  "replay": false
}
```

### Possible errors

- `401` `unauthorized`
- `403` `insufficient_scope`
- `409` `template_not_approved`
- `422` `validation_failed`
- `429` `rate_limited`

## A message's status and reply

`GET /v1/c/{slug}/messages/{id}` · Scopes: `conversations:read` · `messages:send_template` · `messages:send_text`

### Path parameters

| Field | Notes |
|---|---|
| `slug` | The company's identifier in DoneTalk (the key's own). |
| `id` | The record's id. |

### Request example

```bash
curl -X GET "https://api.donetalk.com/v1/c/demo/messages/:id" \
  -H "Authorization: Bearer $DONETALK_KEY"
```

### Response 200

```json
{
  "message": {
    "id": "01a3c0de-8b22-7c33-9d44-0e55f6677889",
    "conversationId": "01a3c0de-7a11-7b22-8c33-9d44e55f6677",
    "channelId": "01a0cccc-0000-7000-8000-000000000002",
    "direction": "outbound",
    "from": null,
    "type": "template",
    "text": "Oi Ana! Seu cupom ANA10 vale até sexta. Quer usar agora?",
    "status": "read",
    "errorCode": null,
    "createdAt": "2026-10-23T13:02:11.000Z",
    "sentAt": "2026-10-23T13:02:12.000Z",
    "deliveredAt": "2026-10-23T13:02:13.000Z",
    "readAt": "2026-10-23T13:05:40.000Z",
    "reply": {
      "id": "01a0d05a-3ee3-75bd-9db5-dc9856f079c9",
      "type": "button",
      "text": "Quero o cupom",
      "at": "2026-10-23T13:05:52.000Z"
    }
  }
}
```

### Possible errors

- `401` `unauthorized`
- `403` `insufficient_scope`
- `422` `validation_failed`
- `429` `rate_limited`

## A phone's messages

`GET /v1/c/{slug}/messages` · Scopes: `conversations:read`

A phone's messages since a moment, newest first (with or without Brazil's ninth digit).

### Path parameters

| Field | Notes |
|---|---|
| `slug` | The company's identifier in DoneTalk (the key's own). |

### Query parameters

| Field | Type | Required | Notes |
|---|---|---|---|
| `phone` | string | yes |  |
| `since` | string (date-time) | yes |  |
| `channelId` | string (uuid) | no |  |
| `direction` | one of `inbound`, `outbound` | no |  |
| `limit` | integer | no | up to 100; at least 1; default `20` |

### Request example

```bash
curl -X GET "https://api.donetalk.com/v1/c/demo/messages" \
  -H "Authorization: Bearer $DONETALK_KEY"
```

### Response 200

```json
{
  "messages": [
    {
      "id": "01a3c0de-8b22-7c33-9d44-0e55f6677889",
      "conversationId": "01a3c0de-7a11-7b22-8c33-9d44e55f6677",
      "channelId": "01a0cccc-0000-7000-8000-000000000002",
      "direction": "outbound",
      "from": null,
      "type": "template",
      "text": "Oi Ana! Seu cupom ANA10 vale até sexta. Quer usar agora?",
      "status": "read",
      "errorCode": null,
      "createdAt": "2026-10-23T13:02:11.000Z",
      "sentAt": "2026-10-23T13:02:12.000Z",
      "deliveredAt": "2026-10-23T13:02:13.000Z",
      "readAt": "2026-10-23T13:05:40.000Z"
    }
  ]
}
```

### Possible errors

- `401` `unauthorized`
- `403` `insufficient_scope`
- `422` `validation_failed`
- `429` `rate_limited`

