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

# Send a WhatsApp reply

> Let your own app answer a WhatsApp number: get each message and delivery status by webhook, and reply inside the 24-hour window

Your own app can answer a WhatsApp number in place of the AI or your team. Botcadence posts each customer message and each delivery status to your app's webhook, and your app replies with this endpoint while the customer's 24-hour window is open. Outside that window, send an approved template with [Send a WhatsApp template](https://docs.botcadence.com/docs/api-reference/whatsapp/send-message.md).

## Setup

1. In **Channels**, open the WhatsApp channel. Under **Webhooks**, add your app's public HTTPS address (up to 2,048 characters) and a signing secret (up to 256), pick the events, and save. Spaces around both are trimmed. You can add up to 5 webhooks.
2. To stop the AI and your team from answering, set **Default reply mode** to **Your app replies**. This mode needs a webhook that takes `message.received`. In this mode Botcadence does not read images with AI and does not bill them as media; your app gets the signed image link. Webhooks also work with any other reply mode; they only notify.
3. Create a project API key with the `whatsapp:create` scope.

## Events

### `message.received`

Each customer message is posted as JSON:

```json theme={null}
{
  "event_id": "4f1c2e…",
  "event_type": "message.received",
  "schema_version": "2026-12-01.v1",
  "occurred_at": "2026-12-01T10:00:00+00:00",
  "message": {
    "id": "665f1a2b3c4d5e6f7a8b9c0d",
    "provider_message_id": "wamid.HBgL…",
    "type": "image",
    "text": "Front door",
    "media": [{ "type": "image", "urls": ["https://…signed…"], "title": null, "content_type": "image/jpeg" }],
    "button_payload": null,
    "button_id": null,
    "reply_to_provider_message_id": null
  },
  "sender": "14155552671",
  "conversation": { "id": "665f1a2b3c4d5e6f7a8b9c0e", "channel_id": "665f1a2b3c4d5e6f7a8b9c0f" }
}
```

* `occurred_at` is when the customer sent the message, as WhatsApp reports it.
* `conversation.id` is the chat; pass it as `conversation_id` when you reply.
* `message.type` is `text`, `image`, `video`, `audio` or `document`. Each `message.media` item has `type`, `urls`, `title` and `content_type`. The links are signed and expire, so download them when the post arrives.
* `button_payload` is set when the customer taps a template quick-reply button. It is the payload Meta sends for that button: Meta's default unless an automation maps the button's payload to a variable (for example `button_payload_0`) in its template settings.
* `button_id` is set when the customer taps a reply button or picks a list row; for the reply buttons this API sends, it is the button title.
* `sender` is the customer's WhatsApp number, without `+`.

### `message.status`

Each delivery status Meta reports for a message sent from the number, including your app's replies:

```json theme={null}
{
  "event_id": "9b2d…",
  "event_type": "message.status",
  "schema_version": "2026-12-01.v1",
  "occurred_at": "2026-12-01T10:00:05+00:00",
  "message": { "id": "665f1a2b3c4d5e6f7a8b9c0d", "provider_message_id": "wamid.HBgL…" },
  "status": "delivered",
  "error": null,
  "recipient": "14155552671"
}
```

* `status` is `sent`, `delivered`, `read` or `failed`; `error` explains a failure.
* `message.id` is the inbox message: agent, AI and API replies, and templates sent from the inbox. For your replies it is the `message_id` this API returns. It is `null` for messages that are not in the inbox (broadcasts, automation templates, and messages sent from the WhatsApp Business app); match those on `provider_message_id`.
* A reply with an image and text goes out as two WhatsApp messages, so each part gets its own statuses: same `message.id`, different `provider_message_id`.

### Delivery

Answer with any `2xx` status within 15 seconds. A `5xx`, a `429`, a timeout, a network error or a failed DNS lookup is retried with the same `event_id`, also sent as the `Idempotency-Key` header, so ignore an `event_id` you have already handled. Retries back off, waiting up to 50 minutes between tries, for about 2 hours in total.

Other statuses are not retried. Redirects are not followed, and a `3xx` is not retried. An address that resolves to a private network is refused and not retried.

Events can arrive out of order, so order them by `occurred_at`. When a delivery gives up, the webhook in the channel settings shows **Last delivery failed** with the time and the error.

### Verify the signature

Each post carries `X-Botcadence-Timestamp` (Unix seconds) and `X-Botcadence-Signature: sha256=<hex>`. The signature is the HMAC-SHA256, keyed with your signing secret, of the timestamp, a `.`, and the raw request body:

```python theme={null}
import hashlib, hmac

def is_signed(secret: str, timestamp: str, body: bytes, signature: str) -> bool:
    digest = hmac.new(secret.encode(), f"{timestamp}.".encode() + body, hashlib.sha256)
    return hmac.compare_digest(f"sha256={digest.hexdigest()}", signature)
```

Refuse a post whose signature does not match or whose timestamp is more than a few minutes old.

## Authentication

Send the project API key as a Bearer token. See [API authentication](https://docs.botcadence.com/docs/api-reference/authentication.md).

```http theme={null}
Authorization: Bearer bot_live_YOUR_KEY
```

**Required scope:** `whatsapp:create`

## Request body

**to** `string` *required*

The customer's number in international format, for example `+14155552671`. It must have a live WhatsApp chat in the project.

**conversation\_id** `string`

The chat to reply in: `conversation.id` from the `message.received` event. It must be a live WhatsApp chat in this project with the `to` number. Without it, the reply goes to the latest live chat with that number.

**text** `string`

Up to 4,096 characters. Required unless `image_url` is set, and always required with `quick_replies`, as 1 to 1,024 characters.

**image\_url** `string`

A public HTTPS image address. The image is sent first, then the text.

**quick\_replies** `string[]`

Up to three different button titles of 1 to 20 characters after trimming spaces, sent as reply buttons on the text. A tap arrives as an inbound message with `button_id` set to the title.

## Example

```bash theme={null}
curl -X POST \
  "https://backend.botcadence.com/organizations/ORG_ID/projects/PROJECT_ID/whatsapp/messages" \
  -H "Authorization: Bearer $BOTCADENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+14155552671",
    "conversation_id": "665f1a2b3c4d5e6f7a8b9c0e",
    "text": "Someone is at the front door.",
    "image_url": "https://cdn.example.com/front-door.jpg",
    "quick_replies": ["Sound siren", "Seen"]
  }'
```

## Response

```json theme={null}
{
  "status": "success",
  "message": "Message sent",
  "data": {
    "message_id": "665f1a2b3c4d5e6f7a8b9c0d",
    "conversation_id": "665f1a2b3c4d5e6f7a8b9c0e"
  },
  "status_code": 200
}
```

The reply shows in the conversation in your inbox.

## Idempotent retries

Send an `Idempotency-Key` header (1 to 255 characters) to retry safely. A repeated key with the same body returns the first response without sending again.

* A failure before the reply is stored frees the key for another try.
* A failure after the reply is stored keeps the key as `outcome_unknown`, because the reply may have reached the customer. A replay with that key answers `409`; check the conversation before you send again with a new key.

```http theme={null}
Idempotency-Key: alert-1042
```

## Errors

| Status | Meaning |
| - | - |
| `400` | Invalid organization or project id, an `Idempotency-Key` that is not 1 to 255 characters, the WhatsApp channel is off or cannot send, or WhatsApp refused the message. |
| `401` | API key is missing, invalid, or revoked. |
| `403` | API key belongs to another organization/project or lacks `whatsapp:create`. |
| `404` | No live WhatsApp chat with this number, or `conversation_id` is not a live WhatsApp chat in this project with this number. |
| `409` | The customer's 24-hour window has closed (send a template instead); this customer opted out; or the idempotency key was used with a different body, is still being sent, or its outcome is unknown. |
| `422` | Invalid body: missing text and image, a non-public image address, or invalid quick replies. |
| `500` | Something failed on our side. If you sent an `Idempotency-Key`, the reply may have reached the customer; see [Idempotent retries](#idempotent-retries). |


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