May 18, 2026

Build a WhatsApp Chatbot: End-to-End Guide for 2026

Build a WhatsApp chatbot from Business API setup to deployed AI assistant. Covers architecture, message handling, NLP, and production deployment.
Reading time :  
6
 min
Codewords
Codewords

Build a WhatsApp chatbot: end-to-end guide for 2026

Building a WhatsApp chatbot is one of those projects where the technology is straightforward but the logistics trip everyone up. The messaging logic is simple. The WhatsApp Business API approval, webhook verification, template message rules, and 24-hour conversation window — that is where builders stall.

Here is the direct answer: you need a WhatsApp Business API account (through Meta or a BSP), a webhook endpoint to receive messages, an AI layer for natural language handling, and a deployed runtime to keep it alive. According to Meta's 2025 business messaging report, WhatsApp has over 2.78 billion monthly active users, and businesses exchanged over 600 million messages per day through the Business API in 2024.

Unlike generic AI automation posts, this guide shows real CodeWords workflows — not just theory. You will walk through each layer of the stack and see how to assemble a production chatbot that handles real conversations.

Related reading: AI agents builder, workflow automation platform, AI automation tools, automation tools, CodeWords integrations, pricing, and CodeWords templates.

TL;DR

  • Building a WhatsApp chatbot requires a Business API account, a webhook server, message routing logic, and an AI layer for natural language understanding.
  • The 24-hour conversation window is the biggest design constraint — after 24 hours of user inactivity, you can only send pre-approved template messages.
  • CodeWords can serve as the webhook endpoint, AI reasoning layer, and integration hub, so you build the chatbot as a single deployable workflow.

What do you need before you build a WhatsApp chatbot?

The prerequisites split into two tracks: Meta's requirements and your technical stack.

Meta's requirements:

  • A Meta Business Account (create one at business.facebook.com)
  • A WhatsApp Business API account, either direct through Meta Cloud API or through a Business Solution Provider (BSP) like Twilio, MessageBird, or 360dialog
  • A verified phone number that is not currently registered with WhatsApp
  • Approved message templates for outbound notifications

Your technical stack:

  • A publicly accessible webhook URL to receive incoming messages
  • A server or serverless function to process messages and respond
  • An AI model for natural language understanding (optional for simple bots, essential for conversational ones)
  • A data layer for conversation state, user context, and logging

The Meta Cloud API is the fastest path. It is free to set up, gives you a test number, and the webhook configuration happens in the Meta Developer Dashboard. BSPs add features like analytics, template management, and multi-number support, but introduce another dependency.

How does the WhatsApp Business API message flow work?

Think of the message flow as a three-act loop: receive, process, respond.

Act 1: Receive. When a user sends a message, WhatsApp forwards it to your webhook URL as an HTTP POST with a JSON payload. The payload includes the sender's phone number, message type (text, image, document, location, button reply), and the message content.

Act 2: Process. Your server parses the payload, determines intent, and decides how to respond. For a simple bot, this is keyword matching. For an AI chatbot, this means passing the message to an LLM with conversation history and responding with structured output.

Act 3: Respond. You send a POST request to the WhatsApp Cloud API's messages endpoint with the recipient number and your response. Text, images, documents, interactive buttons, and list messages are all supported response types.

The critical constraint is the 24-hour window. Once a user messages you, you have 24 hours to respond freely. After that window closes, you can only send pre-approved template messages — which must be submitted to Meta for review and typically take 24–48 hours for approval.

How do you set up the webhook for your WhatsApp chatbot?

The webhook is where your chatbot lives. Meta requires two things: a verification endpoint (GET) and a message receiver (POST).

Verification: Meta sends a GET request with a hub.verify_token and hub.challenge. Your server checks the token and returns the challenge string. This confirms you control the endpoint.

Message handling: Every incoming message arrives as a POST request. Parse the JSON, extract the message content, and route it to your processing logic.

In CodeWords, this entire webhook layer is handled automatically. When you build a WhatsApp chatbot workflow, Cody creates a FastAPI endpoint that handles both verification and message processing. The endpoint deploys to a serverless runtime, so you do not manage infrastructure.

A practical CodeWords prompt:

Build a WhatsApp chatbot workflow.
Set up a webhook to receive WhatsApp messages.
For each incoming message, classify the intent as one of:
  greeting, product_question, support_request, order_status, other.
Use AI to generate a helpful response based on intent and context.
Log each conversation turn to Google Sheets.
Send the response back through WhatsApp Cloud API.

How do you add AI to a WhatsApp chatbot?

The difference between a menu-driven bot and a conversational assistant is the AI layer. Here is how to add it effectively.

Conversation memory. Store the last 5–10 message turns per user in Redis or a database. Pass this history as context with each new message so the AI maintains coherence. Without memory, every message is a cold start — which feels robotic.

System prompt design. Give the AI a persona, constraints, and fallback behavior. Example:

You are a customer support assistant for [Company].
Answer questions about products, orders, and returns.
If you cannot answer confidently, say so and offer to connect the user with a human agent.
Keep responses under 150 words. Use friendly, professional tone.
Never make up order numbers or delivery dates.

Structured output. Ask the AI to return JSON with fields like response_text, intent, confidence, and needs_human. This lets your workflow route low-confidence messages to a human queue instead of sending a bad response.

Tool calling. For order status or account lookups, give the AI access to your backend APIs via function calling. The AI decides when to call the function, passes the right parameters, and incorporates the result into its response. CodeWords supports this through its native LLM access — OpenAI, Anthropic, and Gemini models with tool-calling capabilities.

What are the common mistakes when building a WhatsApp chatbot?

Ignoring the 24-hour window. If your bot takes too long to respond or the user goes silent, the window closes. Design proactive template messages for follow-ups and time-sensitive notifications.

Sending too many messages. WhatsApp enforces rate limits and quality ratings. If users report your messages as spam, Meta can restrict or ban your number. Start with high-value messages only.

Skipping error handling. Webhook failures, API rate limits, and malformed payloads will happen. Log every incoming message and every outbound response. Implement retries with exponential backoff for API calls.

Not testing with real phones. The Meta test number works for development, but production behavior differs. Template approvals, delivery receipts, and media handling all behave differently with real numbers and real networks.

Hardcoding responses. The moment you hardcode more than five response paths, maintenance becomes painful. Use AI for the response layer and reserve hardcoding for menu structures and button labels only.

FAQ

How much does it cost to build a WhatsApp chatbot?

The WhatsApp Business API charges per conversation. As of 2025, Meta's pricing page shows costs vary by country and conversation category — marketing, utility, service, and authentication. Service conversations initiated by users are currently free for the first 1,000 per month. AI model costs add per-token fees depending on the provider.

Can I build a WhatsApp chatbot without coding?

Yes, using platforms that abstract the API layer. CodeWords lets you describe the chatbot logic to Cody in natural language. BSPs like Twilio and 360dialog also offer low-code builders. For full control over AI behavior and integrations, some code familiarity helps.

How do I handle multiple languages?

Use the AI layer for language detection. Pass the detected language into your system prompt so responses match the user's language. Store the user's preferred language in your conversation state so subsequent messages do not re-detect.

Can a WhatsApp chatbot integrate with my CRM?

Yes. The chatbot workflow can update HubSpot, Salesforce, Pipedrive, or any CRM after each conversation. CodeWords supports 500+ integrations through Composio, so CRM updates can be part of the same workflow that handles the conversation.

What comes after your first chatbot?

The first version handles basic conversations. The second version is where value compounds. Add order lookup via API. Connect support tickets to Linear or Zendesk. Route sales inquiries to the right rep based on AI scoring. Send weekly conversation analytics to a Google Sheet.

The chatbot is not the product. It is the interface to a system of workflows behind it. Each new capability you add is another workflow connected to the same WhatsApp webhook.

Start building your WhatsApp chatbot in CodeWords, or explore the integrations catalog to see what you can connect.

Contents
Ready to try CodeWords?
Get started free
Sign in
Sign in