AI & automation10 min readReviewed by the Softivum team,

What is a WhatsApp bot API and how does it work?

Short answer

A WhatsApp bot API is how your software talks to WhatsApp. Meta's WhatsApp Business Platform, through its Cloud API, sends every customer message to your server as a webhook, and your server replies with a call to the messages endpoint. The bot is your own logic in between: rules, a flow builder or an AI model.

Two smartphones linked by cables to a laptop on a developer’s desk, with a blurred code monitor behind.

The key points

  • There is no separate bot API: you use the WhatsApp Business Platform, and the bot is whatever software you put behind it.
  • Messages arrive by webhook and leave by a POST to the messages endpoint.
  • Replies inside the 24-hour window can be free-form; anything outside it must be an approved template.
  • Your webhook must verify Meta's signature, answer 200 quickly and tolerate repeated deliveries.
  • You can connect directly with your own developers or onboard through a partner platform.

What is a WhatsApp bot API?

A WhatsApp bot API is the connection that lets software read and answer WhatsApp messages without a person typing. WhatsApp does not sell a product called a bot API. It offers the WhatsApp Business Platform, and the interface a bot uses is the Cloud API, which Meta's platform overview describes as a way to message and call WhatsApp users programmatically.

The bot itself is the part you or a vendor write. It can be a set of fixed rules, a visual flow builder, or an AI model that reads your documents, as in a RAG chatbot. The API only moves messages in and out. This is why two businesses with the same API can have bots that behave very differently.

The business app on a phone is a different product. The difference, and when each fits, is covered in WhatsApp Business app vs API.

How does a message travel through a WhatsApp bot?

A customer sends a message to your WhatsApp number. WhatsApp passes it to the Platform, and the Platform posts a JSON payload to a URL on your server. Your software reads it, decides what to do, and replies with a POST to the messages endpoint. The reply appears in the customer's chat.

Meta's overview says the contents of any message sent from a user to your business phone number are communicated by webhook, and that delivery status updates for your outgoing messages are reported the same way. Sending uses the Graph API over HTTP, with an access token in an Authorization: Bearer header. The success response means Meta accepted the request, not that the message was delivered; delivery arrives later as a status webhook.

What do you need before the first message?

Meta's get started guide lists the path. You create an app in the Meta App Dashboard with the WhatsApp use case and a business portfolio, connect it to a messaging account, and send a test message from a test number with a temporary access token. You subscribe to webhooks, and then you create a system user with the business_management, whatsapp_business_messaging and whatsapp_business_management permissions to get a token that does not expire quickly.

Two choices matter for a business. The WhatsApp Business account and the Meta business portfolio should belong to your company, not to a freelancer or an agency, so that you keep the number and the history if the supplier changes. And the way staff will share the number is planned before launch, as covered in sharing one number across a team.

How does the webhook work, and what must your server do?

A webhook is a message one system sends another the moment something happens. Meta's webhook endpoint guide sets four duties for your server.

First, pass the verification handshake. When you save the callback URL, Meta sends a GET with hub.mode, hub.challenge and your hub.verify_token. If the token matches, you return 200 and the challenge value. Second, check each POST. It carries an X-Hub-Signature-256 header, which is an HMAC-SHA256 of the raw body using your app secret, and you reject anything that does not match. Third, answer 200 for a valid POST. Fourth, expect repeats: a failed delivery is retried immediately and then several more times over seven days, and Meta says to deduplicate on your side.

The endpoint needs a public address with a valid certificate, since self-signed certificates are not supported. Meta also provides no API to fetch past webhook data, so a bot that needs the history stores payloads as they arrive. When messages stop arriving, work through why WhatsApp webhooks fail, in the order that guide gives.

What can a bot send?

While the conversation is open, a bot can send text, images, documents, location, interactive messages and Flows. The send messages reference lists these types and the request body: messaging_product set to whatsapp, a to number, a type, and an object named after that type.

Interactive messages are what make a bot feel quick. The reply buttons reference allows up to three buttons per message, and a tap reaches your webhook as a message of type interactive with a button_reply holding the button's id and title. Design the id as something your code can act on, such as book_room or talk_to_staff, and treat the title as display text only.

When can the bot message first, and when must it use a template?

A 24-hour customer service window opens when a user messages you, and it resets each time they write again. Inside it, you can send free-form messages. Outside it, only approved templates can be sent. The WhatsApp Business Policy adds that you may only start a conversation with an approved message template, and only with people who gave you permission to contact them.

Meta's template documentation says every template is authentication, marketing or utility, is reviewed when created or edited, and can be sent only when its status is APPROVED. Review can take up to 24 hours, so templates are submitted well before launch. Rules for wording, such as keeping a utility message free of offers, are in Meta's categorization guide, and a worked case is confirming cash on delivery orders.

Should you connect directly or through a partner platform?

WhatsApp's platform page names two routes for most businesses. Direct integration suits a business with developers that wants full control. Partner integration means choosing a partner and onboarding through its embedded signup, where the partner handles the technical setup with little or no code.

Direct suits a custom bot that must read your own systems. A partner platform suits a team that wants a ready inbox and template manager (WATI, Interakt, AiSensy and the Cloud API compared). Whichever you choose, the account stays in your business name, the contract states who owns the number and the data, and moving away later does not mean losing your history.

What does an incoming message look like, and what does a failure look like?

Meta's webhook reference for messages says an incoming message appears in a messages array, and its type property decides the structure of each object. A text message carries the sender in from and the words in text.body. A button tap arrives with type interactive. A type Meta cannot pass on arrives with type unsupported, so your code needs a polite fallback reply for it.

Outgoing messages produce a different payload: a statuses array with no message content. The status reference lists sent, delivered, read, played for voice notes, and failed. A message read in an open chat can skip the delivered status. A failed status carries an errors array with a code, a title, a message, error_data.details and an href to the documentation for that code.

Log every failed status against the conversation. A bot that never reads its failed statuses cannot tell a message that failed to deliver from a template that Meta paused, and the fix is different for each: the error details name the reason. Handle the two arrays separately in code, because a statuses payload has nothing to reply to.

What is Meta's own agent option?

Meta's platform overview also describes Meta Business Agent, AI agents that handle conversations with WhatsApp users autonomously, using knowledge sources you provide, and custom connectors that let the agent take actions through your external APIs. It is a third route next to direct and partner integration.

It suits a business whose questions are answered from documents plus a few simple API actions. A flow with state across several systems, such as holding a room against a payment link that confirms or releases it on a webhook, or applying your own approval rules, is built as your own software behind the API, where every step is logged and testable.

Where does the bot's own logic live?

The logic is a program that receives the webhook payload and returns an action. Three designs are common. A rules bot matches a button id or a keyword to a fixed reply. A flow bot follows a path you drew, such as collecting a name and a date. An AI bot sends the message and your reference text to a language model and sends back the answer.

Most useful bots combine them: buttons for the common paths, an AI model for open questions, and a handover to a person for anything the bot cannot answer from your approved content. See what an AI chatbot can do for a business for where that line sits, and building a WhatsApp chatbot for the project view of the same build.

How does Softivum build on the WhatsApp bot API?

Softivum scopes the bot in writing first: the flows, the data it reads, the templates and the people who receive handovers. The WhatsApp Business account and the Meta app are set up in your business name. We build the webhook with signature checks and duplicate handling, connect it to your CRM, calendar, store or payment events, and log every conversation so you can read what the bot said.

The work sits under AI chatbots, with workflow automation where the bot needs to write to your systems.

The two directions of a WhatsApp bot API

The two directions of a WhatsApp bot API
DirectionCustomer to your botYour bot to the customer
How it travelsWebhook: Meta POSTs JSON to your URLYour server POSTs to the messages endpoint on the Graph API
What you must doPass the handshake, verify the signature, answer 200, ignore repeatsSend an access token; use a template outside the 24-hour window
What it carriesMessage type, sender, text or button reply, message idMessage type and its content, such as text or interactive buttons
How you know it workedMeta stops retrying after a 200The response means accepted; sent, delivered and read arrive as status webhooks

How to connect a bot to the WhatsApp Cloud API

  1. Decide who owns the accounts

    Create or choose the Meta business portfolio and WhatsApp Business account in your company's name before anyone builds on them.

  2. Create the app

    In the Meta App Dashboard, create an app with the WhatsApp use case and connect it to your messaging account.

  3. Send a test message

    Use the temporary token and test number to send one message, then reply from your phone to open the 24-hour window.

  4. Stand up the webhook

    Host a public HTTPS endpoint that passes the verification handshake, verifies X-Hub-Signature-256 and answers 200.

  5. Create the permanent token

    Create a system user with the business_management, whatsapp_business_messaging and whatsapp_business_management permissions and store its token as a secret.

  6. Add the logic

    Route each message type to your rules, flow or AI step, and send replies to the messages endpoint.

  7. Submit templates and go live

    Submit the templates you need outside the window, wait for approval, and test the full path with real numbers.

Before the bot goes live

  • The Meta business portfolio and WhatsApp account belong to your business
  • The webhook passes the handshake and verifies X-Hub-Signature-256
  • The endpoint answers 200 before slow work, such as an AI call, which runs in a queue
  • Repeated deliveries are ignored using the message id
  • Payloads you need later are stored when they arrive
  • The access token is a system user token kept as a secret
  • Templates for messages outside the window are approved
  • Customers opted in before any business-started message
  • A handover path to a person exists for what the bot cannot answer

Sources

Rules and guidance this answer relies on. Policies change, so check the current version before acting on it.

  1. Meta for Developers: about the WhatsApp Business Platform
  2. Meta for Developers: get started with the WhatsApp Business Platform
  3. Meta for Developers: create a webhook endpoint
  4. Meta for Developers: send messages
  5. Meta for Developers: message templates overview
  6. WhatsApp: WhatsApp Business Policy
  7. Meta for Developers: message status webhooks
  8. Meta for Developers: messages webhook reference

Questions people also ask

Only for a direct integration, where your endpoint receives webhooks and calls the messages endpoint. Through a partner platform, the partner runs that layer and you build flows in its tools, with little or no code.

Ignore the repeat. Meta retries failed deliveries for up to seven days and advises deduplicating, so save each message id on arrival and skip any id you have already handled before sending a reply.

The send response only confirms Meta accepted it. Delivery arrives afterwards as status webhooks, for sent, delivered and read, or failed with error details you can log. A message read while the chat is open can skip delivered.

Want this applied to your business?

Tell us what you are planning in a free 30-minute call, or have your current website checked first with no call needed.

Get a Free 2-Minute Website Audit

Free 30 minutes · no obligation

WhatsAppCall