I Built a WhatsApp Chatbot + AI Agent in n8n for Small Businesses (free template)

How to build a WhatsApp chatbot and AI agent that can handle customer questions about hours, pricing, menus, locations, and appointments in real time.

I built a WhatsApp chatbot and AI agent that can handle customer questions about hours, pricing, menus, locations, and appointments in real time. This guide shows the full approach I use: scrape a business website into a concise knowledge base, feed that knowledge into an LLM via n8n, add guardrails to avoid hallucinations, and wire WhatsApp Business API so the agent replies to real customers.

Join our AI Automation Community to download the n8n template used here and get support building this for your business.

What you will learn

  • How to scrape and normalize a business website into a single LLM-ready document I call the business encyclopedia and knowledge-base.
  • Why I choose a single system-prompt encyclopedia over a multi-service RAG pipeline for many small-business use cases.
  • How to connect WhatsApp Business Cloud to n8n and wire incoming messages to an AI agent that consults the encyclopedia before replying.
  • How to add memory per phone number so conversations stay isolated per customer.
  • Practical configuration tips and production guardrails to reduce errors and bad replies.

System overview: the four building blocks

The full workflow breaks down into four parts:

  1. Scrape and extract — take a homepage URL and gather every page of relevant text into markdown.
  2. Build the business encyclopedia — aggregate and format every page into a deterministic document the agent will consult.
  3. WhatsApp connection — create WhatsApp Business Cloud credentials and wire triggers and send actions into n8n.
  4. AI agent and guardrails — set a system prompt, include the encyclopedia, configure memory per phone number, and send replies.

Step 1: Scrape a business website into structured markdown

Start by feeding the business homepage URL into a mapping node that returns every internal URL. I use a community node that integrates with Firecrawl, a scraping API optimized for LLM work. Firecrawl can return text content in markdown format, which keeps token usage low compared to raw HTML.

Initial scraping request

Key choices at this stage:

  • Exclude media files such as large galleries to save tokens and keep the encyclopedia focused on text.
  • Keep pages that contain policy information, menus, amenity details, and anything that customers ask about.
  • For each page, request the markdown output so you get clean, readable text for later prompts.

Step 2: Normalize and aggregate into a single encyclopedia

After scraping, run a simple data cleanup pipeline: filter out errors, remove duplicates, and aggregate all page items into one large text field. Add structured metadata for each page such as title, description, and source URL. Then join items using clear separators so the resulting file is both human readable and easy for an LLM to parse.

Why format this into an encyclopedia rather than a raw bundle of pages? A deterministic structure removes ambiguity. The agent will have a consistent format to search and reference when answering questions.

LLM prompt to generate company knowledge base

Prompt and output shape

Design your encyclopedia prompt with these prime directives:

  • Information integrity — preserve facts exactly as found.
  • No hallucinations — avoid inventing details not present in the source content.
  • Deterministic structure — same headings and sections across runs.
  • Source traceability — include the URL for any fact that might require a direct link back to the page.

When the LLM compiles the encyclopedia, expect a table of contents, clear section headings (amenities, rooms, dining, transfers), and page-level references. Store this output and use it as part of the agent system prompt.

Step 3: Model selection and design decision (Knowledge-base vs RAG)

There is a choice between two main architectures:

  • System-prompt encyclopedia — deliver the whole business encyclopedia in the agent’s system prompt so the model can reference it directly.
  • RAG pipeline with vector store — chunk content, index in a vector database, retrieve relevant chunks per query, and feed them to the model.

My recommendation for most small-business chatbots is to start with the encyclopedia approach. Reasons:

  • Fewer moving parts to manage. You avoid an external vector store, reranker services, and chunking problems.
  • Less surface for failures. You rely on a single LLM call instead of multiple networked services.
  • If you use a model with a large context window, such as Gemini 2.5 Pro or an equivalent, you can fit a large business encyclopedia without hitting token limits.

RAG has benefits for very large sites or when you need fine-grained chunk retrieval. But RAG increases complexity, and chunking mistakes can lead to hallucinations. Start simple, then add retrieval later when scale demands it.

Expanded knowledge base prompt

Step 4: Connect WhatsApp Business Cloud to n8n

Next, set up two credential flows in the WhatsApp Business Cloud developer portal: one for receiving hooks and one for sending messages. In short:

  1. Create an app in the Facebook Developers dashboard and select a Business app type.
  2. Grab the app ID and app secret for the inbound trigger credential in n8n.
  3. Generate an access token and obtain the WhatsApp Business Account ID for the send actions credential.
  4. Whitelist any test numbers you will use during development, or add production numbers before launch.
Create meta business suite app

In n8n, add a WhatsApp Business Cloud trigger node configured with client ID and client secret so the workflow listens for incoming messages. Create a separate credential for the send action to avoid permission issues.

Step 5: Build the WhatsApp AI agent and connect the encyclopedia

Design the agent’s system prompt around a friendly and professional concierge persona with a clear playbook. Key items to include in the system prompt:

  • Agent role and tone (concise, courteous, helpful).
  • Mandatory step: consult the business encyclopedia before answering.
  • When quoting details, include the source URL if available.
  • What to do when information is missing: provide a short apology, offer contact or reservation options, and ask a clarifying question if needed.
  • Limit response length for WhatsApp readability and format responses into short paragraphs or bullet lists.
WhatsApp AI Agent

Insert the full encyclopedia body below a clear divider in the system prompt. That ensures the LLM always sees configuration rules first and then the reference material it must use.

Step 6: Configure memory per phone number

Memory must be isolated per customer. Use a memory key that combines a fixed prefix and the WhatsApp contact identifier. This prevents one customer’s conversation from leaking into another’s session.

Setup AI Agent memory

Set a reasonable context window for stored messages, such as the last 20–30 interaction items. This lets the agent reference previous questions and reservations without growing the memory indefinitely.

Step 7: Testing, formatting, and production tips

Run a series of test messages from allowed numbers and inspect full logs in n8n. During testing, watch for:

  • Bad request errors from the WhatsApp API when a number is not on the allowlist.
  • Formatting issues where the LLM returns long blocks of text. Tune the system prompt to produce shorter, WhatsApp-friendly outputs.
  • Hallucinations. If the agent makes up details, tighten the encyclopedia directives and require source references for any factual claim.
WhatsApp node config

Formatting tips for WhatsApp

  • Use short paragraphs and numbered instructions for directions or policies.
  • For menus or hours, return bullet lists and link to the source page when relevant.
  • Respect WhatsApp character limits and avoid long paragraphs that force scrolling.

Guardrails and error handling

Guardrails reduce risk and build trust with users. Implement these checks:

  • If the encyclopedia has conflicting statements, prefer the most recent date or state uncertainty and provide the source link.
  • If the agent lacks the exact answer, ask a clarifying question before committing to an action.
  • Log every outgoing message and include a fallback human handoff path if the agent cannot answer after two attempts.

Next Steps

Building an AI-powered WhatsApp chatbot in n8n requires a few deliberate choices: scrape and normalize content into a clean encyclopedia, prefer a single-model system prompt when possible, and wire WhatsApp credentials correctly. With memory per phone number and strong prompt directives, you get a reliable assistant that answers customer questions and helps convert inquiries into bookings or sales.

Join AI Automation Mastery to get the free n8n template, the system prompt, and support implementing this workflow for your business.

More AI Tutorials

The Facebook Ad Thief Clone Competitor Ads with AI n8n Nano Banana
The Facebook Ad Thief Clone Competitor Ads with AI n8n Nano Banana How to build an AI automation that's able to analyze the best performing live ads that your competitors are running on Facebook and Instagram.
YouTube
I Built a Gmail AI Agent for 24/7 Customer Support n8n Template
I Built a Gmail AI Agent for 24/7 Customer Support n8n Template How to build an AI Gmail chatbot agent for local businesses using n8n that is able to respond to customer questions and inquiries around the clock, 24/7
YouTube
How I Generate Unlimited Ad Creative with Nano Banana and n8n Using Gemini 2.5 Flash Image
How I Generate Unlimited Ad Creative with Nano Banana and n8n Using Gemini 2.5 Flash Image How to use Google's Nano Banana to generate infinite ad creatives that feature your product in the hands of influencers.
YouTube
How to Connect WhatsApp to n8n (AI Workflow Tutorial)
How to Connect WhatsApp to n8n (AI Workflow Tutorial) How to connect WhatsApp to n8n so you can power AI agents and automations that send and receive messages.
YouTube
Put Real Products and People into AI Video Ads (Veo 3 Full Tutorial)
Put Real Products and People into AI Video Ads (Veo 3 Full Tutorial) Learn how to use canvas prompting to bring real people and real products into AI generated videos.
YouTube
I Built a Fully-Automated Podcast (with AI + n8n + ElevenLabs)
I Built a Fully-Automated Podcast (with AI + n8n + ElevenLabs) How to build a podcast fully researched, written, and narrated by AI.
YouTube