# WhatsApp Cloud API

The Cloud API is Meta's official WhatsApp platform. Bonga manages the account, resolves tokens, sends templates and media, and receives webhooks.

## Prerequisites

1. A Meta Business portfolio.
2. A Meta app with the WhatsApp product.
3. A system user with `whatsapp_business_messaging` and a permanent token.
4. A WABA ID and phone number ID.
5. A webhook URL and verify token for the app.

Detailed setup: [Connect WhatsApp Cloud API](/guides/facebook-whatsapp-cloud-api).

## Connect the account

In **Dashboard → Channels → WhatsApp Cloud**, enter the phone number ID, WABA ID and access token. Bonga verifies the credentials before saving, encrypts the token, and shows the account with a readiness state.

The same operation is available on the dashboard API at `POST /api/whatsapp/cloud/accounts` and `POST /api/whatsapp/cloud/accounts/verify`. The token is never returned by a list or detail endpoint.

## Templates

Create, list and delete templates from the dashboard or `/api/whatsapp/cloud/accounts/:id/templates`. Approval is Meta's decision:

- `APPROVED` templates can send.
- `PENDING`, `REJECTED`, `PAUSED` and `DISABLED` templates cannot.
- A template is read again at send time; a template that changed after you queued a send is refused.

Authentication templates are required for OTP. Utility and marketing templates follow Meta's category rules.

## Sending

```bash
curl -X POST 'https://api.bonga.africa/api/v1/whatsapp/cloud/accounts/acc_123/send' \
  -H "Authorization: Bearer $BONGA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{
    "to": "254712345678",
    "type": "template",
    "template_name": "order_ready",
    "template_language": "en_US"
  }'
```

Free-form text is allowed inside the customer service window. Outside it, use an approved template. Bulk sends accept recipients and a shared template. Scheduled sends accept a future timestamp and run through the queue.

## Webhooks

Point the Meta app webhook at:

```
https://api.bonga.africa/api/whatsapp/cloud/webhook
```

Bonga verifies `X-Hub-Signature-256` with `META_APP_SECRET`, and follows the app-specific path when the multi-app registry is enabled. Messages, statuses and template events are committed once and projected into the inbox and automations.

## Delivery evidence

Cloud sends record the provider message ID, template name and language, and the latest status. `sent` means Meta accepted the message; `delivered` and `read` require receipts. A failed send includes Meta's error code in the delivery row.

## Best practices

- Use a permanent system-user token, not a temporary developer token.
- Keep WABA and phone number IDs in configuration, not source code.
- Subscribe only to the webhook fields you need.
- Recheck template status before scheduling a large campaign.
- Respect the 24-hour customer service window.

## Next

- [Meta Embedded Signup](/guides/meta-embedded-signup)
- [WhatsApp](/docs/whatsapp)
- [API reference](/docs/api-reference)
