3 WhatsApp + n8n Workflow Varieties — Ready to Import and Run
The One Template, Three Jobs
Every workflow in this post starts from the same webhook trigger. OpenWA receives a WhatsApp message, forwards it to n8n, and the IF nodes decide what happens next.
The three branches handle completely different scenarios:
1. A specific person gets a private AI assistant
2. Anyone in a group can summon the AI with @agent
3. Multiple keywords route to multiple handlers
All three share the same base stack: OpenWA as the WhatsApp gateway, Ollama running llama3.2:3b locally for AI, a 30-message memory buffer so the conversation doesn't reset every reply, and n8n's HTTP Request node sending the AI's response back through OpenWA.
The Stack That Powers All Three
OpenWA runs at http://openwa-api:2785 inside your Docker network. This is not localhost:2785 — if you're debugging why n8n can't reach OpenWA, the hostname is almost always the problem.
Ollama serves llama3.2:3b at http://localhost:11434 on your machine. No API key, no data leaving your server, no cost per message.
Simple Memory stores the last 30 messages per session. The session key is the WhatsApp chatId — so personal chats and group chats have separate memory automatically.
Variety 1: The Personal AI Chat Bot
Use when: One person — you, a cofounder, a specific client — gets a private WhatsApp AI assistant that remembers your conversation.
The IF node fires when body.data.contact.pushName equals the name you've configured. Everyone else is silently ignored.
The three mistakes I made the first time:
Wrong pushName. WhatsApp has two names per contact — the display name in your phone's contact list, and pushName which comes from the sender's WhatsApp profile. I configured my cofounder's contact name in my phone. The IF never fired. Check the webhook payload to find the actual pushName value.
Same memory for everyone. The template uses body.data.chatId as the session key. If you want the AI to remember conversations with multiple people separately, you're already covered — each person has a different chatId.
No system prompt customization. The default "You are a helpful assistant" produces generic, forgettable responses. The first thing I changed: "You are a product photography assistant. When asked about lighting or gear, recommend specific setups with approximate budget ranges." The bot went from useless to actually useful overnight.
Variety 2: The Group @agent Bot
Use when: You want to drop an AI bot into a WhatsApp group and let anyone in the group ask it questions — but not have it reply to every single message and create chaos.
The IF node fires when body.data.isGroup == true AND the message body contains "@agent". Everything else passes through silently.
"@agent" is your activation token. Someone types "@agent what's the status of my order?" and the bot responds. They type "thanks" and nothing happens. No loop, no spam, no annoyance.
The three mistakes I made:
Responding in every group. Without the "@agent" filter, the bot fires on every group message — including its own previous responses. You get an infinite loop within three messages.
Boring group prompts. Groups are noisy — multiple people are reading. I changed the system prompt to: "Keep responses short. Direct answers without preamble. Format lists with numbers. If you're unsure, say so briefly." Engagement went up immediately.
30-message memory in a busy group. In an active group, that's 30 messages from 15 different people with significant gaps between them. The AI was getting confused mid-conversation. I dropped the buffer to 10 messages. Context improved noticeably.
Variety 3: The Keyword Router
Use when: One group, multiple functions. You want @order to trigger an order-status handler, @help to trigger a help workflow, and @status to trigger something else — all from the same group, all from the same bot.
The pattern replaces the single Simple Agent with a chain of IF nodes or a Switch node, each checking for a different keyword.
Two gotchas I hit:
Keyword collision. If someone types "@orders" and your keyword is "@order", most routing logic won't match. Use distinct keywords. A good pattern: use the "@agent" prefix as a namespace. "@agent order", "@agent status", "@agent help" — clean separation between bot commands and regular chat.
The fallback branch. Without a fallback, unmatched messages go nowhere — no response, no feedback. Add a default branch that tells the user which keywords are valid.
Prerequisites (Same for All Three)
1. OpenWA running and accessible from n8n's Docker network — see OpenWA Docker Setup
2. n8n credential for OpenWA set up — see Connecting n8n to OpenWA
3. The n8n webhook registered in OpenWA — in the OpenWA dashboard → Webhooks → Add Webhook. URL: https://n8n.yourdomain.com/webhook/wa-webhook. Event: message.received
4. Ollama running locally with llama3.2:3b pulled:
curl -fsSL https://ollama.ai/install.sh | sh
ollama pull llama3.2:3b
5. The Ollama credential in n8n. Base URL: http://localhost:11434. No API key required.
The Workflow JSON
Copy the JSON below, then in n8n: Workflows → three dots menu → Import from JSON → paste → import.
This template covers Variety 1 and Variety 2 with one gate. Should the bot reply? passes a direct message from your named contact, or a group message that contains @agent. Everything else is ignored. Your settings (OpenWA URL, contact name, mention keyword, system prompt) live in one Bot settings node. For Variety 3, put a Switch node after the gate.
{
"name": "WhatsApp AI Bot: personal chat + group @agent (OpenWA + Ollama)",
"nodes": [
{
"parameters": {
"content": "## Reply to WhatsApp messages with a local AI agent using OpenWA and Ollama\n\n**Who it's for:** anyone who wants a WhatsApp AI assistant without paying for the Meta Cloud API, and without sending chats to a cloud LLM.\n\n**How it works**\n1. [OpenWA](https://github.com/rmyndharis/OpenWA), a free self-hosted WhatsApp API gateway, posts every incoming message to the webhook.\n2. **Should the bot reply?** passes only two kinds of message: a direct message from the contact you name, or a group message that contains your mention keyword (default `@agent`). Everything else is ignored, so the bot never floods a group.\n3. An AI Agent answers with a local Ollama model and remembers the last 30 messages per chat.\n4. The reply goes back to the same chat through OpenWA's `send-text` endpoint.\n\n**Setup**\n1. Run OpenWA and connect a WhatsApp session (scan the QR code).\n2. Run Ollama and pull a model: `ollama pull llama3.2:3b`.\n3. Fill in **Bot settings**: OpenWA URL, the contact's WhatsApp profile name (`pushName`, not the name saved in your phone), the mention keyword and the system prompt.\n4. Create a **Header Auth** credential: name `X-API-Key`, value = your OpenWA API key. Select it in **Send reply via OpenWA**. Select your Ollama credential in **Ollama chat model**.\n5. In OpenWA \u2192 Webhooks, add this workflow's production webhook URL for the `message.received` event, then activate the workflow.\n\nFull step-by-step guide (Docker, tunnel, webhooks): [abhishekrajpurohit.in](https://abhishekrajpurohit.in/blog/complete-guide-self-hosting-n8n-openwa-whatsapp-api)",
"height": 820,
"width": 460,
"color": 1
},
"id": "8b095b9c-9890-4a10-af04-24997d00b4bd",
"name": "Overview",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-480,
-80
]
},
{
"parameters": {
"content": "## 1. Receive and filter\nWebhook from OpenWA, your settings, and the reply gate.",
"height": 420,
"width": 660,
"color": 7
},
"id": "58764b41-3b84-4e3b-a3cf-dc8a1153b2be",
"name": "Step 1",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
0,
160
]
},
{
"parameters": {
"content": "## 2. Generate the reply\nLocal Ollama model with per-chat memory.",
"height": 560,
"width": 420,
"color": 7
},
"id": "248f5cd2-78bb-49d1-9d71-f6f5bd03bd42",
"name": "Step 2",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
700,
160
]
},
{
"parameters": {
"content": "## 3. Send it back\nPOST to OpenWA send-text.",
"height": 420,
"width": 300,
"color": 7
},
"id": "54fce74c-c9c1-4fa4-9ea5-9d60eccd77c9",
"name": "Step 3",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
1160,
160
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "wa-webhook",
"options": {}
},
"id": "e27fd98d-e8f1-4485-9a54-832d531a723f",
"name": "Receive WhatsApp message",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
60,
340
],
"webhookId": "191913a8-511e-4cd0-9418-1db18069c22b"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "76da82cf-df57-4552-990b-04e6da77a558",
"name": "openwaBaseUrl",
"value": "http://openwa-api:2785",
"type": "string"
},
{
"id": "6a30d48f-01b3-448b-b675-216446439b81",
"name": "allowedContactName",
"value": "YourContactName",
"type": "string"
},
{
"id": "573736ee-8c63-422c-95c8-862cc30d8bcb",
"name": "mentionKeyword",
"value": "@agent",
"type": "string"
},
{
"id": "33dae449-4f9f-42d1-8470-0b3304af59ba",
"name": "systemPrompt",
"value": "You are a helpful assistant replying on WhatsApp. Keep answers short and direct. Use numbered lists for steps. If you are unsure, say so.",
"type": "string"
}
]
},
"includeOtherFields": true,
"options": {}
},
"id": "ad52ad92-858d-4057-a6bc-eff3edc183b4",
"name": "Bot settings",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
260,
340
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose",
"version": 2
},
"conditions": [
{
"id": "254e0a11-59c1-4855-b343-596d716e7626",
"leftValue": "={{ $json.body.data.isGroup !== true && $json.body.data.contact?.pushName === $json.allowedContactName }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
},
{
"id": "fc87d657-3596-430c-9a34-09e0b643cf13",
"leftValue": "={{ $json.body.data.isGroup === true && String($json.body.data.body || '').includes($json.mentionKeyword) }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "or"
},
"looseTypeValidation": true,
"options": {}
},
"id": "03b18476-46f0-4245-809b-1c856e1cc7e2",
"name": "Should the bot reply?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
460,
340
]
},
{
"parameters": {
"promptType": "define",
"text": "={{ $json.body.data.body }}",
"options": {
"systemMessage": "={{ $json.systemPrompt }}"
}
},
"id": "05816bd5-2b36-400a-a3ad-e16abc6f97ab",
"name": "AI agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [
760,
340
]
},
{
"parameters": {
"model": "llama3.2:3b",
"options": {}
},
"id": "ea821e70-dd40-49c9-8369-b375b74ba86a",
"name": "Ollama chat model",
"type": "@n8n/n8n-nodes-langchain.lmChatOllama",
"typeVersion": 1,
"position": [
740,
580
]
},
{
"parameters": {
"sessionIdType": "customKey",
"sessionKey": "={{ $('Receive WhatsApp message').item.json.body.data.chatId }}",
"contextWindowLength": 30
},
"id": "b74115f2-29b2-4ac1-b722-4e670b95331d",
"name": "Chat memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"typeVersion": 1.3,
"position": [
920,
580
]
},
{
"parameters": {
"method": "POST",
"url": "={{ $('Bot settings').item.json.openwaBaseUrl }}/api/sessions/{{ $('Receive WhatsApp message').item.json.body.sessionId }}/messages/send-text",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ chatId: $('Receive WhatsApp message').item.json.body.data.chatId, text: $json.output }) }}",
"options": {}
},
"id": "3e214463-c8c9-4e22-83b9-3d68d9f7b651",
"name": "Send reply via OpenWA",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1240,
340
]
}
],
"connections": {
"Receive WhatsApp message": {
"main": [
[
{
"node": "Bot settings",
"type": "main",
"index": 0
}
]
]
},
"Bot settings": {
"main": [
[
{
"node": "Should the bot reply?",
"type": "main",
"index": 0
}
]
]
},
"Should the bot reply?": {
"main": [
[
{
"node": "AI agent",
"type": "main",
"index": 0
}
],
[]
]
},
"AI agent": {
"main": [
[
{
"node": "Send reply via OpenWA",
"type": "main",
"index": 0
}
]
]
},
"Ollama chat model": {
"ai_languageModel": [
[
{
"node": "AI agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Chat memory": {
"ai_memory": [
[
{
"node": "AI agent",
"type": "ai_memory",
"index": 0
}
]
]
}
},
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"meta": {
"templateCredsSetupCompleted": false
}
}
After importing, you must re-select credentials: open the Send reply via OpenWA node → Authentication → select a Header Auth credential with name X-API-Key and your OpenWA API key as the value. Open the Ollama chat model node → select your Ollama credential. Credentials are stored by ID and won't resolve in a different n8n instance.
In Bot settings, change YourContactName to the actual pushName from your webhook payload, and edit the system prompt.
Importing and Activating
1. Copy the JSON above
2. In n8n → Workflows → three dots menu → Import from JSON
3. Paste and import
4. Re-select credentials in every node that has a key icon
5. Activate the workflow
The import step trips up everyone the first time. The workflow loads, you test it, and it fails silently. It's almost always a credential mismatch. Check every node with a key icon.
The Real Constraint
The stack is not the hard part. Ollama, OpenWA, n8n, the webhook, the memory buffer — these are solved problems with documented solutions. The hard part is deciding what you actually want to automate.
A bot that answers questions is fun for a week. A bot that maintains your team's shared calendar, tracks orders, and escalates failures to Telegram — that takes planning. The workflow varieties in this post are the building blocks. The specific system prompt, the data sources you connect, and the feedback loop when the AI gets something wrong — that's where the real work is.
The good news: you only need one variety to start. Pick the simplest one that matches your actual use case. Ship it. Let people use it. Fix what breaks. That's the only process that actually works.
Series: ← Connecting n8n to OpenWA | ← Back to overview
Related Posts
Rather have this built for you?
I set up WhatsApp and n8n automation for small businesses: reply bots, order updates and lead capture, handed over with backups and a known monthly cost. Fixed packages from ₹15,000.
See packages and pricingAlso built on WhatsApp: WhatsApp CRM · AI receptionist · lead management · real estate CRM
Built something similar or want to talk through the architecture? Get in touch.