How to Build a WhatsApp Chatbot Grounded in Your Website Content

How to build a WhatsApp chatbot that answers from your own website content: the WhatsApp Business Platform, a working webhook, grounded answers, human handover, consent and data handling.

A WhatsApp chatbot grounded in your website content answers customers’ questions on WhatsApp using only what your site says, with links to the relevant pages, and hands over to a person when it cannot help. It is built on Meta’s WhatsApp Business Platform: incoming messages arrive at your webhook, your server retrieves matching passages from your content, a language model writes a short answer from them, and your server sends the reply through the WhatsApp Cloud API. For Indian businesses, where customers already expect to message on WhatsApp, it is one of the most useful places to put this kind of assistant.

Architecture

  1. Customer messageArrives from WhatsApp at your webhook.
  2. RetrieveFind matching passages from your website content.
  3. AnswerA model writes a short reply from those passages only.
  4. ReplySent through the WhatsApp Cloud API with a page link.
  5. Hand overTo a person when confidence is low or the customer asks.

The retrieval part is the same as for a website chatbot; see building a RAG chatbot on your website content.

Step 1: set up the WhatsApp Business Platform

  • Create a Meta business account and a WhatsApp Business app in Meta’s developer dashboard, and register a phone number.
  • Configure a webhook URL and a verify token, and subscribe to message events.
  • Note the platform’s rules: businesses can reply freely within a 24-hour window after the customer’s last message; messages outside that window need pre-approved templates. Check Meta’s current pricing for messages.

Step 2: the webhook

This Node.js (Express) example verifies the webhook and replies to text messages. The answer function is where your retrieval and model call go.

import express from "express";
const app = express();
app.use(express.json());

// Meta calls this once to verify the webhook
app.get("/whatsapp", (req, res) => {
  if (req.query["hub.mode"] === "subscribe" &&
      req.query["hub.verify_token"] === process.env.WA_VERIFY_TOKEN) {
    return res.send(req.query["hub.challenge"]);
  }
  res.sendStatus(403);
});

// Incoming messages
app.post("/whatsapp", async (req, res) => {
  res.sendStatus(200);                              // acknowledge quickly
  const msg = req.body?.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
  if (!msg || msg.type !== "text") return;

  const reply = await answerFromWebsite(msg.text.body);   // retrieval + model
  await fetch(`https://graph.facebook.com/v20.0/${process.env.WA_PHONE_ID}/messages`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.WA_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      messaging_product: "whatsapp",
      to: msg.from,
      type: "text",
      text: { body: reply },
    }),
  });
});

app.listen(3000);

Use the Graph API version your app is configured for. In production, also verify the request signature Meta sends, and process messages in a queue so slow model calls do not delay the acknowledgement.

Step 3: answer only from your content

  • Retrieve the best passages for the question, with a similarity threshold.
  • Instruct the model to answer only from those passages, in two or three sentences suited to a chat, and to include the link to the source page.
  • If nothing passes the threshold, reply that you will connect them with the team, and hand over.

Step 4: human handover

Let customers type a word such as “agent” to reach a person, and hand over automatically for complaints, payments, cancellations and anything the bot is not sure about. Show the conversation history to the person who takes over.

  • Only message people who have contacted you or opted in, as WhatsApp’s policies require.
  • Tell customers they are talking to an automated assistant and how to reach a person.
  • Store conversations securely, keep them only as long as needed, and handle them under the Digital Personal Data Protection Act, 2023.
  • Never ask for card details, passwords or OTPs in the chat.

Step 6: improve from the conversations

Questions the bot could not answer are gaps in your website content. Review them weekly and add answers to the relevant pages, which improves the bot, your search visibility and AI answers at the same time.

Frequently asked questions

Can we use the WhatsApp Business app instead of the platform?

The app is for manual use and simple automated greetings. Custom chatbots need the WhatsApp Business Platform.

Can the bot reply in Hindi or Marathi?

Many language models handle Indian languages. Test answer quality in each language, and keep source content available in those languages where possible.

What does it cost?

Costs include WhatsApp messaging charges set by Meta, model usage and hosting. Check Meta’s current pricing for India.

Sources

  1. Meta for Developers, WhatsApp Cloud API documentation (webhooks and messages)
  2. WhatsApp Business Messaging Policy
  3. Digital Personal Data Protection Act, 2023