RAG chatbot on WhatsApp with n8n: the complete tutorial
Published 18 July 2026 · 5 min read

A chatbot that answers on WhatsApp from your own documents — product catalogue, internal FAQ, warranty terms — is the meeting point of two mechanics we have already covered: RAG with Supabase pgvector for the knowledge, and Meta's WhatsApp Cloud API for the channel. n8n bridges the two with exactly six nodes. This tutorial assembles them one by one.
Prerequisites: an n8n instance (cloud or self-hosted, ≥ 1.60), a Supabase project with the documents table and match_documents function from the pgvector guide, an OpenAI API key, and a Meta for Developers account.
Step 1 — Create the WhatsApp app on Meta's side
- On developers.facebook.com: Create App → Business, then add the WhatsApp product to the app.
- Meta provides a test number and a Phone number ID (visible under WhatsApp → API Setup): note it down, you will need it for sending. Add your own number as a test recipient.
- Under App settings → Basic, note the App ID and App Secret (for the trigger), and generate a permanent access token via a Business Manager system user (for sending — the temporary token from API Setup expires after 24 hours).
Step 2 — The trigger: receiving messages
Add a WhatsApp Trigger node in n8n, with a WhatsApp OAuth credential (App ID + App Secret) and the messages event ticked. n8n then shows a webhook URL: paste it into WhatsApp → Configuration → Webhook in your Meta app, along with the verify token n8n proposes, and subscribe to the messages field.
Every incoming message arrives with this structure (a real Cloud API payload excerpt):
{
"messaging_product": "whatsapp",
"contacts": [{ "profile": { "name": "Camille" }, "wa_id": "33612345678" }],
"messages": [{
"from": "33612345678",
"id": "wamid.HBgLMz...",
"timestamp": "1752825600",
"text": { "body": "What is the warranty period for product X?" },
"type": "text"
}]
}
Three n8n expressions cover the entire rest of the workflow:
- the question:
{{ $json.messages[0].text.body }} - the number to reply to:
{{ $json.messages[0].from }} - the first name (for personalisation):
{{ $json.contacts[0].profile.name }}
Step 3 — The brain: AI Agent + vector store as a tool
Add an AI Agent node, prompt source Define below, with the text {{ $json.messages[0].text.body }}. Attach three sub-nodes:
- OpenAI Chat Model (
gpt-4o-mini: fast and cheap, plenty for support); - Simple Memory, session key Define below:
{{ $json.messages[0].from }}— one history per customer, essential for follow-up questions ("and for model Y?"); - Supabase Vector Store in Retrieve Documents (As Tool for AI Agent) mode, table
documents, query namematch_documents, limit 4, with an Embeddings OpenAI node (text-embedding-3-small— the same model used at ingestion time, otherwise retrieval finds nothing). Name the toolknowledge_baseand describe it: "Searches the official product documentation. Use for any factual question."
The agent's system message does the rest:
You are the WhatsApp assistant for {{company name}}.
Answer in 3 sentences maximum: WhatsApp is not a blog.
For any factual question, query the knowledge_base tool and rely
only on what it returns. If the tool returns nothing relevant,
say so honestly and suggest writing to {{support email}}.
No Markdown: plain text only, WhatsApp does not render headings.
The last line avoids the classic trap: an agent replying with **bold** and ## that render as unreadable clutter in WhatsApp.
Step 4 — Replying to the right number
Finish with a WhatsApp Business Cloud node: operation Send message, WhatsApp API credential (the permanent access token), your Phone number ID, recipient {{ $('WhatsApp Trigger').item.json.messages[0].from }} and body {{ $json.output }} (the agent's answer).
The full workflow, ready to import
The complete skeleton (six nodes, AI connections included) — paste it straight into n8n via Workflows → Import from File, then plug in your four credentials:
{
"name": "WhatsApp RAG chatbot",
"nodes": [
{ "id": "1", "name": "WhatsApp Trigger", "type": "n8n-nodes-base.whatsAppTrigger",
"typeVersion": 1, "position": [0, 0],
"parameters": { "updates": ["messages"] } },
{ "id": "2", "name": "AI Agent", "type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.7, "position": [220, 0],
"parameters": { "promptType": "define",
"text": "={{ $json.messages[0].text.body }}",
"options": { "systemMessage": "You are the company's WhatsApp assistant. Answer in 3 sentences max, plain text without Markdown. Query the knowledge_base tool for any factual question and rely only on its results." } } },
{ "id": "3", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1, "position": [140, 220],
"parameters": { "model": "gpt-4o-mini" } },
{ "id": "4", "name": "Simple Memory", "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3, "position": [300, 220],
"parameters": { "sessionIdType": "customKey",
"sessionKey": "={{ $json.messages[0].from }}" } },
{ "id": "5", "name": "Knowledge base", "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"typeVersion": 1.1, "position": [460, 220],
"parameters": { "mode": "retrieve-as-tool", "toolName": "knowledge_base",
"toolDescription": "Searches the official product documentation. Use for any factual question.",
"tableName": "documents", "topK": 4,
"options": { "queryName": "match_documents" } } },
{ "id": "6", "name": "Embeddings OpenAI", "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1.2, "position": [460, 420],
"parameters": { "model": "text-embedding-3-small" } },
{ "id": "7", "name": "Send reply", "type": "n8n-nodes-base.whatsApp",
"typeVersion": 1, "position": [460, 0],
"parameters": { "resource": "message", "operation": "send",
"phoneNumberId": "YOUR_PHONE_NUMBER_ID",
"recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
"textBody": "={{ $json.output }}" } }
],
"connections": {
"WhatsApp Trigger": { "main": [[{ "node": "AI Agent", "type": "main", "index": 0 }]] },
"AI Agent": { "main": [[{ "node": "Send reply", "type": "main", "index": 0 }]] },
"OpenAI Chat Model": { "ai_languageModel": [[{ "node": "AI Agent", "type": "ai_languageModel", "index": 0 }]] },
"Simple Memory": { "ai_memory": [[{ "node": "AI Agent", "type": "ai_memory", "index": 0 }]] },
"Knowledge base": { "ai_tool": [[{ "node": "AI Agent", "type": "ai_tool", "index": 0 }]] },
"Embeddings OpenAI": { "ai_embedding": [[{ "node": "Knowledge base", "type": "ai_embedding", "index": 0 }]] }
}
}
Test it: send a WhatsApp message to the test number from your phone. The question goes to the agent, the agent queries Supabase, and the answer — grounded in your documents — comes back into the conversation within seconds.
Three traps to know before production
- The 24-hour window: the bot can only reply freely within 24 hours of the customer's last message. Beyond that, only Meta-approved templates go through. For a support bot that replies in the moment, no impact.
- Non-text messages: voice notes, images and documents arrive with
typeother thantextand notext.body. Add an IF node on{{ $json.messages[0].type }}right after the trigger to reply with a fixed message ("Please send your question as text") rather than letting the agent fail. - Ingestion is the other half of the work: a RAG is only as good as its chunks. The full ingestion pipeline (download, chunking, metadata, upsert) is detailed in the pgvector guide — and shipped ready to import, along with the citations chatbot and the
/askAPI, in the RAG Assistant Pack.
Going further
This tutorial gives you the WhatsApp channel. The RAG Assistant Pack (€119) provides the industrialised foundation: PDF ingestion into pgvector, a chatbot that cites its sources, Notion sync and an API endpoint — four tested, documented workflows that this WhatsApp bot plugs into as-is. To understand each building block of the agent, also read Getting started with n8n's AI nodes.
FAQ
Frequently asked questions
Do I need a paid WhatsApp Business account?
Not to get started: Meta's WhatsApp Cloud API is free up to 1,000 service conversations per month, and replies to a customer message within the 24-hour window count as service conversations. You need a Meta Business account, a Meta for Developers app and a dedicated phone number (Meta's test number is enough for development).
Can the chatbot message a customer first?
Not freely: outside the 24-hour window that follows the customer's last message, WhatsApp only allows pre-approved template messages. A RAG support chatbot that answers incoming questions naturally stays within the rules: the customer always initiates.
How does the bot keep track of the conversation?
With a Simple Memory node attached to the AI Agent, using the sender's number (messages[0].from) as the session key: each customer gets their own history, and two customers writing at the same time never mix contexts.
Can I use something other than Supabase for the documents?
Yes: the AI Agent accepts any n8n vector store as a tool (Pinecone, Qdrant, PGVector, in-memory). Supabase remains our pick: free managed Postgres to start, pgvector included and the standard match_documents function, already used by the RAG Assistant Pack.
RAG Assistant Pack
€119