AI Development

How to Build a WhatsApp AI Chatbot for Your Business

November 30, 2026 · 11 min read

How to Build a WhatsApp AI Chatbot for Your Business

WhatsApp is where many customers already talk to friends, family and, increasingly, businesses. A WhatsApp AI chatbot lets you answer questions, take bookings, share order updates and qualify leads in that same chat, 24 hours a day, in the customer's own language. Building one is now straightforward with Meta's WhatsApp Cloud API and a modern language model, but the rules changed in 2026, and getting them wrong can get your number restricted. This guide explains what a business chatbot on WhatsApp can do, Meta's current policies, the architecture, working webhook code, costs and a launch checklist.

What a WhatsApp AI Chatbot Can Do

  • Answer FAQs: opening hours, delivery times, returns, pricing ranges and policies, grounded in your own documents.
  • Handle bookings: check availability, book, reschedule and send reminders for clinics, salons, restaurants and trades.
  • Track orders: look up order status from your e-commerce or ERP system using the customer's phone number.
  • Qualify leads: ask a few questions and pass hot prospects to sales with a summary.
  • Collect information: photos of damaged items, documents or meter readings, which multimodal models can read.
  • Hand over to people: transfer to a human agent with context when the request is complex or the customer asks.

Meta's 2026 Rules on AI Chatbots

In October 2025 Meta updated the WhatsApp Business Solution Terms to stop AI companies from using the business platform to distribute general-purpose assistants, the kind of open-ended chatbot whose main product is the AI itself. The rule applied to new AI providers immediately and to existing ones from 15 January 2026 (TechCrunch). Crucially, businesses using AI to serve their own customers, such as a retailer's support assistant, are not the target and remain allowed.

The policy has attracted regulators. The European Commission opened an antitrust investigation in December 2025, Italy's competition authority ordered interim measures, and Meta exempted users in Italy and Brazil. In 2026 Meta replaced the outright ban with a fee framework for third-party general-purpose assistants, which the Commission challenged again in April 2026 (PPC Land). The practical advice for a normal business is simple: build a focused assistant for your own products and services, keep it on topic and check the current terms before launch.

What You Need Before You Start

  1. A Meta business portfolio (Business Manager) and, for higher limits, business verification.
  2. A WhatsApp Business Platform number using the Cloud API, either directly with Meta or through a business solution provider such as Twilio. A number registered on the platform cannot be used in the normal WhatsApp or WhatsApp Business app at the same time.
  3. A Meta app with the WhatsApp product, a permanent access token for a system user and the app secret.
  4. A public HTTPS endpoint for your webhook.
  5. An AI model and your knowledge base: policies, product data and FAQs the bot will rely on.
  6. A privacy notice and opt-in process for any messages you start.

How It Works

When a customer messages your number, Meta sends the message to your webhook as JSON. Your server verifies that the request really came from Meta, looks up the customer and conversation history, asks the AI model for a reply using your instructions and retrieved knowledge, and sends the answer back through the Graph API. Anything the AI should not handle, such as complaints, refunds above a limit or medical questions, is routed to a person.

Build the Webhook: Working Node.js Code

The Express app below handles Meta's one-time webhook verification, checks the X-Hub-Signature-256 header on every message so forged requests are rejected, acknowledges deliveries quickly and sends a reply through the Cloud API. Your AI logic plugs in as the generateReply function. It includes a self-test that simulates Meta, so you can run it without an account:

// whatsapp-bot.mjs - minimal WhatsApp Cloud API webhook with signature checks and an AI reply.
// Setup: npm install express (Node.js 18+ provides fetch and crypto)
import express from "express";
import crypto from "node:crypto";

const GRAPH = `https://graph.facebook.com/${process.env.GRAPH_API_VERSION ?? "v24.0"}`; // use the current version

export function createApp({ verifyToken, appSecret, accessToken, phoneNumberId, generateReply, fetchFn = fetch }) {
  const app = express();
  // Keep the raw body: Meta signs the exact bytes it sends.
  app.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf; } }));

  // 1. Webhook verification: Meta calls this once when you register the URL.
  app.get("/webhook", (req, res) => {
    const ok = req.query["hub.mode"] === "subscribe" && req.query["hub.verify_token"] === verifyToken;
    return ok ? res.status(200).send(req.query["hub.challenge"]) : res.sendStatus(403);
  });

  // 2. Incoming messages: check the signature, acknowledge fast, then reply.
  app.post("/webhook", async (req, res) => {
    const expected = "sha256=" + crypto.createHmac("sha256", appSecret).update(req.rawBody ?? "").digest("hex");
    const given = req.get("x-hub-signature-256") ?? "";
    if (given.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
      return res.sendStatus(401);
    }
    res.sendStatus(200); // Meta retries slow or failed deliveries, so answer first
    const msg = req.body?.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
    if (!msg || msg.type !== "text") return;
    const reply = await generateReply(msg.from, msg.text.body); // your AI + business logic
    await fetchFn(`${GRAPH}/${phoneNumberId}/messages`, {
      method: "POST",
      headers: { Authorization: `Bearer ${accessToken}`, "Content-Type": "application/json" },
      body: JSON.stringify({ messaging_product: "whatsapp", to: msg.from, type: "text", text: { body: reply } }),
    });
  });
  return app;
}

// Self-test: node whatsapp-bot.mjs --test (no Meta account needed)
if (process.argv[2] === "--test") {
  const sent = [];
  const app = createApp({
    verifyToken: "my-verify-token", appSecret: "test-secret", accessToken: "test-token", phoneNumberId: "123",
    generateReply: async (_from, text) => `You asked: ${text} We are open 9am to 5pm.`,
    fetchFn: async (url, init) => { sent.push({ url, body: JSON.parse(init.body) }); return { ok: true }; },
  });
  const server = app.listen(0);
  const base = `http://localhost:${server.address().port}/webhook`;
  const verify = await fetch(`${base}?hub.mode=subscribe&hub.verify_token=my-verify-token&hub.challenge=42`);
  console.log("verify:", verify.status, await verify.text());
  const payload = JSON.stringify({ entry: [{ changes: [{ value: { messages: [
    { from: "447700900123", type: "text", text: { body: "Opening hours?" } }] } }] }] });
  const signature = "sha256=" + crypto.createHmac("sha256", "test-secret").update(payload).digest("hex");
  const headers = { "Content-Type": "application/json" };
  const good = await fetch(base, { method: "POST", headers: { ...headers, "X-Hub-Signature-256": signature }, body: payload });
  const forged = await fetch(base, { method: "POST", headers: { ...headers, "X-Hub-Signature-256": "sha256=forged" }, body: payload });
  await new Promise((r) => setTimeout(r, 100)); // let the background reply finish
  console.log("signed:", good.status, "forged:", forged.status);
  console.log("reply to", sent[0]?.body.to, "->", sent[0]?.body.text.body);
  server.close();
}

Our test run returned the challenge (status 200, body 42) for verification, accepted the correctly signed message, rejected the forged one with status 401 and sent the reply to the customer's number. In production, store tokens in environment variables or a secrets manager, process messages through a queue so slow AI calls never block webhook responses, and de-duplicate by message ID because Meta may deliver the same event more than once. Meta's Graph API is versioned, so set GRAPH_API_VERSION to a current version from Meta's changelog. Our API security best practices apply to every webhook you expose.

Adding the AI Brain

  • Ground every answer. Retrieve the relevant policy or product data and instruct the model to answer only from it, the approach explained in our RAG vs fine-tuning guide. This avoids the invented promises described in our article on AI hallucinations.
  • Use tools for live data. Order status, stock and appointments should come from your systems through function calls, never from the model's memory.
  • Keep memory per customer. Store recent messages by phone number so the bot follows the conversation, but summarise or expire old history.
  • Add guardrails. Block off-topic requests, prompt injection and personal data leaks, and keep replies short and on brand; see our guide to AI guardrails.
  • Make handover easy. "Talk to a person" should always work, and the human agent should see the AI's summary. Our comparison of AI chatbots vs human support helps you decide where to draw the line.

If you would rather not write code, the same flow can be assembled visually with WhatsApp and AI nodes, as shown in our guide to n8n automation.

WhatsApp Messaging Rules You Must Follow

  • The 24-hour customer service window: after a customer messages you, you can reply freely for 24 hours. Outside that window, you can only send pre-approved message templates.
  • Templates: business-initiated messages such as reminders, shipping updates or promotions use templates that Meta reviews, in categories such as marketing, utility and authentication.
  • Opt-in: you need the customer's permission before you start conversations with them, and you must honour opt-outs.
  • Quality ratings: if many users block or report your messages, Meta can lower your messaging limits or restrict your number.
  • Data protection: conversations contain personal data, so apply the principles in our guide to data privacy laws for developers, including retention limits and clear notices.

What a WhatsApp AI Chatbot Costs

There are three cost layers, all of which vary by country and volume, so treat these as estimates:

  1. Meta's messaging fees: Meta charges per delivered template message, with rates that depend on the category and the recipient's country; replies within an open customer service window are generally free. Check the current WhatsApp pricing for your markets.
  2. AI model usage: a short support conversation usually costs a fraction of a cent to a few cents in model fees, depending on the model and how much context you send; our guide to LLM cost shows how to calculate it.
  3. Development and hosting: a focused bot with retrieval, two or three integrations and human handover is typically a few weeks of development, plus modest hosting. Provider platforms add monthly fees but save build time.

Build, Buy or No-Code?

OptionBest forTrade-offs
Custom build on the Cloud APIUnique workflows, deep integrations, data controlMost development effort; you own maintenance
Business solution provider platformFast launch with inbox, analytics and supportMonthly fees; less flexibility
No-code automation (for example n8n)Simple flows and prototypesHarder to scale complex logic and testing

If the chatbot becomes a product you sell to other businesses, plan it like any SaaS from day one, as covered in our guide to building an AI SaaS product.

Common Mistakes to Avoid

  • Letting the bot make promises. Refunds, discounts and delivery guarantees should come from rules in your systems, not from the model's judgement.
  • Messaging people who did not opt in. Unwanted marketing templates lead to blocks and reports, which lower your quality rating and messaging limits.
  • Ignoring retries. Webhooks can arrive twice; without de-duplication customers receive double replies.
  • Writing essays. WhatsApp is read on phones, so keep replies to a few short lines and use interactive reply buttons or list messages for choices.
  • Hiding the human. A bot that traps people in loops damages trust faster than no bot at all.
  • Skipping monitoring. Review a sample of conversations weekly and watch your quality rating in Meta's tools.

Launch Checklist

  • The assistant's scope is your own products and services, in line with Meta's current terms.
  • Webhook signatures are verified, tokens are stored securely and events are de-duplicated.
  • Answers come from approved knowledge and live systems, with citations logged for review.
  • Human handover works in business hours, and the bot sets expectations out of hours.
  • Templates are approved, opt-ins are recorded and opt-outs are honoured.
  • You have tested 100 or more real questions, including other languages, typos and abuse.
  • Dashboards track resolution rate, handovers, costs and customer feedback.

Frequently Asked Questions

Can I build a WhatsApp chatbot for free?

You can build and test with Meta's Cloud API and a test number at low cost, but production use involves Meta's template message fees, AI model costs and hosting. Replies inside the 24-hour window are generally free from Meta.

Is it allowed to use ChatGPT or Claude in a WhatsApp business chatbot?

Businesses can use AI models to power assistants that serve their own customers. Meta's 2026 rules target AI providers offering general-purpose assistants through the platform, not businesses using AI for support, but always check the current terms.

What is the WhatsApp 24-hour rule?

After a customer messages you, you have 24 hours to reply with free-form messages. After that, you can only contact them using pre-approved templates, and only if they have opted in.

Do I need a business solution provider?

No. You can connect directly to Meta's Cloud API. Providers add convenience, such as shared inboxes, analytics and support, in exchange for fees.

Can a WhatsApp AI chatbot understand voice notes and images?

Yes, if you add speech-to-text and a multimodal model. Your webhook receives media IDs, downloads the files through the API and passes them to the AI.

How long does it take to build a WhatsApp AI chatbot?

A focused bot with FAQs, one or two integrations and human handover typically takes two to six weeks, including Meta setup, testing and template approval.

Launch Your WhatsApp Assistant With Us

We build WhatsApp AI chatbots that follow Meta's rules, connect to your real systems and hand over smoothly to your team. From appointment booking to order tracking, contact our team to scope your chatbot, or explore more AI automation ideas for small businesses.

Want this built for you?

Our team offers Website Deploy On Vercel — get a free quote.

View Services