# Set Up a WhatsApp Cloud API Bot: Webhook, Token, Templates, Costs

> How to set up a WhatsApp chatbot on the official Cloud API: the two routes, webhook and token steps, the 24-hour window, template rules, pricing categories and the limits to plan around.

Source: https://www.epifive.com/blog/whatsapp-business-api-chatbot-setup · Published 2026-12-02 · EpiFive

## Key takeaways

- A WhatsApp chatbot on the official platform is a webhook that receives messages and a call to the /messages endpoint that replies.
- Free-form replies are allowed only inside the 24-hour customer service window; outside it you can send only approved templates.
- Meta charges per delivered message by category and country, with rate cards published per currency.
- Automated replies need an escalation path to a human under the WhatsApp Business messaging policy.
- Verify webhook signatures with the App Secret and return 200 quickly, because failed deliveries are retried for up to 7 days.

A WhatsApp Business API chatbot is a small web service. Meta's Cloud API posts each incoming customer message to your HTTPS webhook, and your service answers by calling the `/messages` endpoint with a permanent access token. You can build that service yourself or buy it from a provider that runs it for you.

## Who this is for and what you will have

This guide is for small-business owners, operations leads and developers who want an automated first response on WhatsApp (order status, opening hours, lead capture) without breaking Meta's rules. By the end you will know which setup route to pick, the sequence to get a bot answering on a test number, the limits that shape what the bot may say and when, and how the costs are structured.

It covers the official Cloud API only. Libraries that connect through a QR scan are a different, riskier route; see [unofficial WhatsApp API vs the official Cloud API](https://www.epifive.com/blog/unofficial-whatsapp-api-vs-official-cloud-api).

## Choose a setup route

| Route | You manage | Good for | Watch out for |
| --- | --- | --- | --- |
| Cloud API directly | Meta app, webhook server, token, templates | Teams with a developer, custom logic, AI replies | You own uptime, security and retries |
| Business Solution Provider (BSP) or no-code chatbot tool | Flows in the provider's dashboard | Teams without developers | Provider fees on top of Meta's, the provider's terms, customer data handled by a third party |
| WhatsApp Business app | Quick replies, away messages | Very small volumes | Not a programmable bot |

The rest of this guide follows the direct route, because the same concepts (window, templates, categories) apply when a provider hides them behind a dashboard. If you pick a provider, check which Meta account owns your phone number and whether you can take it with you later.

## Prerequisites

Meta's Cloud API overview lists what you need before you start:

- A business portfolio ("You must have a business portfolio to use the platform").
- A WhatsApp account and a Messaging account tied to that portfolio.
- A business app associated with the portfolio, with access tokens and permissions.
- An HTTPS endpoint with a valid certificate. Meta's webhook documentation states that self-signed certificates are not supported.

Business phone numbers can be real or virtual. A test number is created for you automatically, so you can build before you register a production number.

## Step-by-step: from test number to a replying bot

### 1. Create the app and connect the Messaging account

In the Meta App Dashboard, create an app with the WhatsApp use case, choose or create your business portfolio, and connect a Messaging account. Save the Messaging account ID and the test phone number ID; you need both later.

### 2. Send a first message with the temporary token

The getting-started page has you generate a temporary access token, pick the test "From" number and enter a "To" number. The temporary token expires quickly and is not meant for development, so use it only for this first send.

### 3. Create a system user and a permanent token

Create a system user, assign your app and WhatsApp account to it, and generate a token with these three permissions: `business_management`, `whatsapp_business_messaging` and `whatsapp_business_management`. Store the token in a secret manager or environment variable, never in code or a chat message.

### 4. Build the webhook endpoint

Your endpoint has to handle two kinds of request.

Verification: Meta sends a GET with `hub.mode` (always `subscribe`), `hub.challenge` (an integer you must pass back) and `hub.verify_token` (the string you typed in the Verify Token field in the App Dashboard). Check that the token matches, then respond with the `hub.challenge` value.

Event notifications: Meta sends a POST with a JSON body. Respond with `200 OK` to every notification. Meta signs each one with SHA256 using your App Secret and puts the signature in the `X-Hub-Signature-256` header. The documentation says you do not have to validate it but you should: generate the signature from the raw payload and your App Secret, then compare it with the header value after `sha256=`.

An incoming text message looks like this (abridged from Meta's documented sample; the name and numbers are Meta's sample values):

```json
{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "102290129340398",
    "changes": [{
      "value": {
        "messaging_product": "whatsapp",
        "metadata": {
          "display_phone_number": "15550783881",
          "phone_number_id": "106540352242922"
        },
        "contacts": [{ "profile": { "name": "Sheena Nelson" }, "wa_id": "16505551234" }],
        "messages": [{
          "from": "16505551234",
          "id": "wamid.HBgLMTY1MDM4Nzk0MzkVAgASGBQzQTRBNjU5OUFFRTAzODEwMTQ0RgA=",
          "timestamp": "1749416383",
          "type": "text",
          "text": { "body": "Does it come in another color?" }
        }]
      },
      "field": "messages"
    }]
  }]
}
```

Meta's page also recommends identifying users by their BSUID (`user_id` or `from_user_id`), because phone number fields may be omitted if a user has adopted a username. Build your customer records around that identifier where it is present.

### 5. Subscribe to the `messages` field

In the App Dashboard go to **WhatsApp > Configuration** and subscribe to `messages`. If you created the app with the "Connect with customers through WhatsApp" use case, go to **Use cases > Customize > Configuration** instead. Reading `messages` webhooks requires the `whatsapp_business_messaging` permission. Make sure the app is in Live mode, because some webhooks are not delivered in Dev mode.

### 6. Reply to the customer

Send a POST to `https://graph.facebook.com/<version>/<PHONE_NUMBER_ID>/messages` with the headers `Content-Type: application/json` and `Authorization: Bearer <ACCESS_TOKEN>`. Meta's documentation example uses version `v27.0`; use the version current in your App Dashboard.

```json
{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "+16505551234",
  "type": "text",
  "text": {
    "preview_url": true,
    "body": "Thanks for your message. Your order ships tomorrow."
  }
}
```

The response gives the recipient's `wa_id` and a message `id` starting with `wamid.`. It confirms only that the API accepted the request, not that the message was delivered; delivery status arrives through webhooks.

## The 24-hour window decides what your bot can say

"When a WhatsApp user messages you or calls you, a 24-hour timer called a customer service window starts," and it resets to 24 hours each time the user writes again. Inside it you may send non-template messages. After it closes you can only send approved templates.

The WhatsApp Business messaging policy (page last updated September 23, 2026) says the same from the compliance side: "You may use automation when responding during the 24-hour window," and automated responses must come with an escalation path to a human, such as an in-chat agent transfer, phone number, email, web support or a support form. Build the "talk to a person" branch before you build the clever branches.

### Templates for everything outside the window

Templates are the only message type that can be sent outside the window, and you must have the customer's opt-in first. Opt-in must state your business name and intent.

- Each template has a category: authentication, marketing or utility. The category also affects pricing.
- Templates are reviewed automatically on creation or edit. WhatsApp Manager notes that review can take up to 24 hours.
- Only templates with status `APPROVED` can be sent. `REJECTED` templates cannot be sent. `PAUSED` templates, applied after recurring negative feedback or low read rates, cannot be sent until resumed.
- Names may contain only lowercase letters, digits and underscores, and are limited to 512 characters.

A template send uses `"type": "template"` with a `template` object. This payload follows the structure in Meta's template documentation and is illustrative; the template name and parameters must match one you created:

```json
{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "+14155550199",
  "type": "template",
  "template": {
    "name": "shipping_update",
    "language": { "code": "en_GB" },
    "components": [
      {
        "type": "body",
        "parameters": [
          { "type": "text", "text": "Marcus" },
          { "type": "text", "text": "TRK-77421" }
        ]
      }
    ]
  }
}
```

## What it costs

Meta charges per delivered message, not per conversation. This has been the model since July 1, 2025. Messages users send to you are not charged. The rate depends on the category and the recipient's country calling code.

| Category | What it covers | Notes from Meta's pricing page |
| --- | --- | --- |
| Marketing | Promotional templates | Fixed rates on the Cloud API |
| Utility | Transactional templates | Volume tiers can lower rates |
| Authentication | Identity verification templates | Volume tiers apply |
| Service | Non-template replies inside an open window | 1,000 free service messages per phone number per month; charges begin at the 1,001st |
| Meta Business Agent | Replies powered by Meta's Business Agent Platform | Billed per token, listed at $2.00 per 1M tokens |

Two details change a budget. Service messages, and utility messages sent inside an open window, were free earlier but became charged on October 1, 2026, apart from the monthly free tier. And a customer who starts a chat from a Click to WhatsApp ad opens a free entry point window of up to 7 days, within which marketing, utility, authentication and service replies are not charged.

The currency is chosen when the Messaging account is created and cannot be changed afterward. Rate cards are published per currency and category for 47 pricing regions; the current cards took effect October 1, 2026 and updated cards take effect January 1, 2027. For a worked India example see [WhatsApp Business API pricing in India](https://www.epifive.com/blog/whatsapp-cloud-api-pricing-india-2026). Provider fees, if you use a BSP, are separate and come from the provider's own price page.

## Limits to design around

- Throughput: business phone numbers send up to 80 messages per second by default, with capacity upgrades available.
- Pair rate: one message every 6 seconds to the same user. Bursts of up to 45 messages are allowed but reduce later quota.
- Messaging limits cap the unique users you can reach outside a customer service window in a moving 24-hour period, set at the business portfolio level.
- Webhook payloads can be up to 3 MB.

## Troubleshooting

| Symptom | Likely cause and fix |
| --- | --- |
| Verification fails when saving the callback URL | Endpoint is not HTTPS with a valid certificate, it does not return the `hub.challenge` value, or the verify token differs from the dashboard field |
| No incoming messages | The `messages` field is not subscribed, or the app is in Dev mode |
| Same message processed twice | Meta retries any non-200 response for up to 7 days; deduplicate on the message `id` |
| Free-form reply is rejected | The 24-hour window has closed; send an approved template instead |
| Template cannot be sent | Status is not `APPROVED` (in review, rejected or paused); check the `status` field with the Template API |
| Requests start failing soon after setup | The temporary token expired; switch to the system user's permanent token |

Keep the webhook fast: acknowledge with 200 first, then do slow work (database lookups, AI calls) in a queue. If a number is restricted, see [what to do when a WhatsApp Business number is banned](https://www.epifive.com/blog/whatsapp-business-number-banned-request-review).

## Launch checklist

1. Route chosen (direct or provider) and the phone number's owner account confirmed.
2. Permanent system-user token stored as a secret.
3. Webhook on HTTPS, verification passing, signature check on, 200 returned quickly, duplicates handled.
4. `messages` subscribed and the app live.
5. Human escalation path in every automated flow.
6. Opt-in recorded before any template send; templates approved.
7. Monthly cost estimated from the current rate card for your recipients' countries.

## What we checked

- Opened Meta's Cloud API overview on 2026-12-02: business portfolio prerequisite, 80 messages per second default throughput, one message per 6 seconds per user, and templates as the only message type outside a window.
- Opened Meta's WhatsApp pricing page on 2026-12-02: per-message model, categories, 1,000 free service messages per month, free entry point window of up to 7 days, and the October 1, 2026 and January 1, 2027 rate card dates.
- Opened the send-messages page on 2026-12-02: endpoint path, required headers, text payload and the 24-hour window wording (the recipient in the example is Meta's sample number).
- Opened the webhook pages (the WhatsApp subscription page and the Graph API webhooks page) on 2026-12-02: verification parameters, `X-Hub-Signature-256` validation, HTTPS requirement, 7-day retry and 3 MB payload limit.
- Opened the getting-started page: the three token permissions and the temporary token warning. Opened the message templates page: statuses, 24-hour review note and naming rules; the template payload is illustrative, as that page labels it.
- Opened the WhatsApp Business messaging policy (last updated September 23, 2026): automation is allowed in the 24-hour window with a human escalation path.
- Documented output: the success response fields (`messaging_product`, `contacts[].wa_id`, `messages[].id`) come from the fields Meta documents; the page has no standalone sample.
- Not checked: we did not run a webhook server or send messages on a live account; the steps follow Meta's documentation as of 2026-12-02. Rates for specific countries were not looked up, and we did not open any provider's price page.

Last tested: 2026-12-02

## References

- [WhatsApp Cloud API overview](https://developers.facebook.com/docs/whatsapp/cloud-api/overview)
- [Get started with the Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started)
- [Send messages](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages)
- [Set up webhooks for WhatsApp](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/set-up-webhooks)
- [Graph API webhooks: getting started](https://developers.facebook.com/docs/graph-api/webhooks/getting-started)
- [WhatsApp pricing](https://developers.facebook.com/docs/whatsapp/pricing)
- [Message templates](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates)
- [WhatsApp Business messaging policy](https://whatsappbusiness.com/policy/)

## Frequently asked questions

### Can a WhatsApp chatbot message customers first?

Only with an approved message template, and only after the customer has opted in. Meta's documentation says templates are the only type of message you can send outside a customer service window, and that you must get opt-in before sending them.

### How long can my bot reply with free-form text after a customer writes?

A 24-hour customer service window starts when the user messages or calls you, and it resets to 24 hours each time they write again. When it closes, only approved templates can be sent.

### Do I need a developer to build a WhatsApp chatbot?

Not always. You can build directly on the Cloud API with a webhook server, or use a Business Solution Provider or no-code tool that handles the webhook for you. Direct builds give more control; providers add their own fees and terms on top of Meta's.

### What happens if my webhook is down?

Meta retries any webhook request that does not get an HTTP 200, with decreasing frequency, for up to 7 days. Retries can produce duplicates, so your handler must tolerate receiving the same message twice.

