Skip to content

    WhatsApp Chatbot Integration

    Follow one customer message from WhatsApp to your webhook, through your bot’s decision and back as a reply. See what Meta, NotifyTech AI and your own code each handle, with the code for every step.

    Stops From Message to Reply
    6
    Characters in One Text Message
    4096
    Business Days to Go Live
    1–3

    Meta’s developer docs read 20 October 2026

    • NotifyTech AI Team
    • 8 min read
    • Integration Guide

    A chatbot is a loop

    A customer writes, Meta tells your server, your code decides what to do, and a reply goes back. This guide follows one message around that loop and shows the code at each stop, so you can see where your work starts and where Meta’s and ours ends.

    Chatbots run on the official WhatsApp Business API. WhatsApp’s Terms bar automated messaging on its personal service, so a bot on a regular number is not an option.

    How does a message get answered?

    A customer messages your number, Meta posts a notification to your webhook, your code decides what to do, and the reply goes back through the API. That is six stops. Meta handles the first two, and you write the code at the rest.

    1. A customer writes to your official WhatsApp number. That opens the 24-hour customer service window, or resets it if it was already open.

      Rule: The window runs for 24 hours from the customer’s latest message.

      Source: Meta, Send messages

    2. Meta posts a JSON notification to your webhook URL. It can sign the payload with your app secret so you can check it came from Meta.

      Rule: Answer every notification with 200 OK. If you do not, Meta retries with decreasing frequency for up to 7 days, and retries can duplicate a notification.

      Source: Meta, Set up webhooks

    3. It acknowledges first, then loops over entry, changes and value.messages, skips any message id it has handled, and passes text messages on.

      Rule: Acknowledge first and work after, so a slow reply never looks like a failed delivery.

      Source: Our advice

    4. It matches a known question, asks one clarifying question, or hands the chat to a person.

      Rule: One text message holds up to 4096 characters.

      Source: Meta, Text messages

    5. Your code calls the API and the message goes to the customer on WhatsApp. Inside the window it can be plain text. Outside it, it must be an approved template, which the sample below uses.

      Rule: You can only message users who have opted in.

      Source: Meta, Send messages

    6. Events such as message.delivered and message.failed come back to your endpoint by webhook, with a signature header.

      Rule: Check the signature before you trust an event.

      Source: NotifyTech AI developer page

    You write code here Someone else runs this stop

    Receive Meta’s notification

    Example written for this guide, in Meta’s webhook format

    // Example in Meta's webhook format (not a NotifyTech AI endpoint)
    const express = require('express');
    const app = express();
    app.use(express.json());
    
    const seen = new Set(); // use a database in production
    
    // Meta verifies your URL once with a GET
    app.get('/webhook', (req, res) => {
      const mode = req.query['hub.mode'];
      const token = req.query['hub.verify_token'];
      if (mode === 'subscribe' && token === process.env.VERIFY_TOKEN) {
        return res.status(200).send(req.query['hub.challenge']);
      }
      res.sendStatus(403);
    });
    
    // Every event arrives as a POST
    app.post('/webhook', (req, res) => {
      res.sendStatus(200); // acknowledge first, work after
      for (const entry of req.body.entry ?? []) {
        for (const change of entry.changes ?? []) {
          for (const msg of change.value.messages ?? []) {
            if (seen.has(msg.id)) continue; // retries can repeat a message
            seen.add(msg.id);
            if (msg.type === 'text') decide(msg.from, msg.text.body);
          }
        }
      }
    });

    This is Meta’s format for incoming messages. Which events a provider forwards to your own endpoint is up to the provider: for NotifyTech AI, ask us for the inbound event format when you request API keys.

    What does your endpoint receive?

    Meta sends one GET to verify your URL, then a POST for every event. A text message arrives as JSON: the sender is in from, the words in text.body, inside entry, changes and value.messages. Answer 200 OK, then do the work.

    • Verify the URL once

      Meta sends a GET with hub.mode, hub.verify_token and hub.challenge. If the token matches the one you entered in the App Dashboard, answer with the challenge value.

    • Loop over the nesting

      One notification can hold several entries and changes. Read entry, then changes, then value.messages, and check the message type before you read text.body. The same endpoint also receives other event types.

    • Answer 200 OK, then work

      Reply 200 OK before any slow work. Meta retries failed notifications with decreasing frequency for up to 7 days, so a slow or failing endpoint can receive the same event again.

    • Ignore what you have already handled

      Keep the id of every message you have answered and skip repeats, so a retry never sends a second reply. A database does this better than the in-memory set in the example.

    • Check the signature

      Meta signs each notification with SHA256 in the X-Hub-Signature-256 header, using your app secret. Validating it is optional, and Meta says you should.

    What should the bot do with it?

    Answer what you can match, ask once when you cannot, and hand over to a person when the customer asks or the second try fails. Keep replies short: one text message holds up to 4096 characters.

    Common questions
    List the questions customers ask most, from your own support history, and write one answer for each.
    Fallback
    When the bot does not understand, say so, offer the main options and ask once more.
    Handoff
    Decide when a person takes over: when the customer asks, after a second miss, and for anything about money or a complaint.
    Reply length
    One text message holds up to 4096 characters. Put the point first; a shorter reply is easier to read on a phone.
    Privacy
    Ask only for what you need, and say how you will use it.

    The rules for what to ask and when to hand over are your design choices, not Meta’s. The 4096-character figure is Meta’s.

    When can the bot reply?

    Inside the 24-hour customer service window the bot can send free-form text, and each new customer message resets the window. After it closes, only an approved template can restart the conversation, and only for people who opted in.

    • Inside the window: free-form text

      While the 24-hour window is open the bot can answer in plain text, with no template. A new message from the customer resets the 24 hours.

    • After it closes: an approved template

      Meta reviews each message template. Most clear in a few hours to 1–2 business days, and Meta’s review sets the pace. A template is how a bot starts a conversation or writes after the window.

    • Opt-in comes first

      You can only message people who have opted in to hear from you. Keep a record of how each contact agreed.

    • Charges are Meta’s, and they changed

      Meta bills some message types per delivery, separately from your plan, and changed how it bills on 1 October 2026. Read Meta’s pricing page for the current rules.

    How does it hand over to a person?

    The conversation moves to your team’s inbox in NotifyTech AI. What that inbox offers depends on the plan, and so does whether your own code can use the API: Starter, Growth or Scale.

    Starter
    Inbox: 1:1 Live Chat. 1 login. The REST API and webhooks are not included.
    Growth
    Inbox: Shared Multi-Agent. 5 logins. REST API and webhooks: 100 requests / min.
    Scale
    Inbox: Priority Routing & SLA Controls. 20 logins. REST API and webhooks: full api & webhooks.

    Pick the plan by who has to answer after the bot and whether your own software has to read the chats. The pricing page lists every limit.

    See what each plan includes

    What should you test before you switch it on?

    Send your bot the messages that break bots: a photo, the same message twice, a question it cannot answer, a request for a person, and a reply after the window has closed. Then check that each one ends the way you meant.

    1. Send or do this

      Send a photo or a voice note

      You should see

      The bot says it reads text only, or hands the chat to a person. It does not crash.

      Why

      Notifications carry other message types, and only text has text.body.

      Source: Meta, Set up webhooks

    2. Send or do this

      Send the same message twice, fast

      You should see

      One reply.

      Why

      Retries can duplicate a notification, so repeated message ids must be ignored.

      Source: Meta, Set up webhooks

    3. Send or do this

      Ask something it does not know

      You should see

      One clarifying question, then the main options.

      Why

      A bot that guesses or goes silent loses the customer.

      Source: Our advice

    4. Send or do this

      Ask for a person

      You should see

      The chat appears in your team inbox.

      Why

      Handoff is the way out of every dead end.

      Source: Our advice

    5. Send or do this

      Write back after 24 hours

      You should see

      The bot sends an approved template, not free text.

      Why

      Free-form text is only allowed while the window is open.

      Source: Meta, Send messages

    Most numbers go live in 1–3 business days, and our team helps with templates Mon–Sat, 9–7 IST. You can build and test your handler while approvals are in progress.

    Frequently Asked Questions

    Common questions about wiring a chatbot to WhatsApp

    1. WhatsApp’s Terms of Service prohibit “bulk messaging, auto-messaging, auto-dialing, and the like” and non-personal use unless WhatsApp authorises it, and the Business App has no API for your own software. Chatbots run on the WhatsApp Business API through a provider such as NotifyTech AI. Check the current Terms; this is not legal advice.

    References & Further Reading

    Meta’s and WhatsApp’s own pages behind this guide, read 20 October 2026

    • Set up webhooks (Meta)

      The notification format for incoming messages, and how Meta retries delivery for up to 7 days.

      Read the Guide
    • Webhooks getting started (Meta)

      The verification request and how payloads are signed with your app secret.

      Read the Guide
    • Send messages (Meta)

      The 24-hour customer service window, free-form messages and templates, and the opt-in rule.

      Read the Guide
    • Text messages (Meta)

      The text message body and its 4096-character limit.

      Read the Docs
    • WhatsApp Business API pricing (Meta)

      How Meta charges per message, and the changes it has announced.

      View Pricing
    • WhatsApp Terms of Service

      The rules on non-personal use and on bulk or automated messaging.

      Read the Terms

    Put the loop to work

    Official API plans with a team inbox for handoff. Our team helps with setup Mon–Sat, 9–7 IST, and most numbers go live in 1–3 business days.

    We use cookies to improve your experience.

    By accepting, you agree to our cookie policy and analytics tracking.