Why n8n – and when not
A large share of our own chatbots run in n8n today: AI chat on websites, conversations over the WhatsApp Cloud API, replies to Facebook and Instagram comments, Telegram bots, and booking events that notify staff. We run them for our own sites and for clients such as beauty salons and a furniture-assembly service. Our in-house WhatsApp messaging tool is built on n8n, the Cloud API and MySQL as well.
n8n fits when the bot has to look things up in your own systems, such as a price list, a booking calendar or a CRM, and when someone is willing to maintain a workflow. It fits badly when several colleagues need a shared inbox with assignment and reporting; a ready-made chat tool saves more time there, see the comparison. Running n8n itself (server, updates, backups) has its own guide at n8n-hosting.best-choice.dk.
The flow in six steps
- Verification (GET). When you save the webhook URL in Meta’s app settings, Meta calls it with
hub.mode,hub.verify_tokenandhub.challenge. The workflow echoes the challenge if your token matches. - The message arrives (POST) on the same URL, and the webhook keeps the raw body exactly as sent.
- The signature is checked. Meta signs the body with your app secret (HMAC-SHA256) and sends the result in
X-Hub-Signature-256. Meta’s own wording is that you do not have to validate it, but you should. A wrong or missing signature gets 403. - Respond 200 straight away. Only then does the workflow do the slow part.
- Drop duplicates by message id. Meta retries for up to 7 days when it does not get a 200, which can deliver the same message more than once. n8n’s Remove Duplicates node remembers 10,000 values by default.
- Send the AI reply through the Graph API to the customer’s number, with a short AI disclosure in each reply.
WhatsApp Trigger node or a plain webhook?
n8n ships a WhatsApp Trigger node. It is quick to set up, but read the small print: WhatsApp allows only one webhook per app, so the test and production URLs overwrite each other, and publishing the workflow does not subscribe the app to your WhatsApp Business account. The node’s documentation does not mention signature checks.
So we use a plain Webhook node with the Raw Body option and check the signature ourselves. Every Meta webhook in our n8n has an HMAC check, and requests without a valid signature get 403. In the same pass we moved hard-coded bot tokens out of the URLs of 36 HTTP nodes in 12 workflows into credentials and environment variables.
Why the raw body? The signature is computed over the exact bytes Meta sent. JSON that has been parsed and serialised again is not guaranteed to be the same bytes, and then the check fails on genuine messages.
The workflow file
Import the file below in n8n (Workflows → Import from file). It expects four environment variables, WA_APP_SECRET, WA_VERIFY_TOKEN, GRAPH_VERSION and WA_PHONE_NUMBER_ID, plus FAQ_TEXT holding your facts. The Code node needs permission to use the Node.js crypto module: set NODE_FUNCTION_ALLOW_BUILTIN=crypto, because n8n disables module imports by default. Two Header Auth credentials carry the keys, one for OpenAI and one for WhatsApp. Each project uses its own OpenAI key and the cheapest model that does the job.
The WhatsApp request body is built with JSON.stringify, never by gluing strings together. That lesson came from a salon reminder workflow: 12 of 207 SMS were never sent while every run showed success, because a backslash in a service name broke the hand-built JSON.
The heart of it is the Code node that checks the signature before anything else happens:
const crypto = require('crypto');
// Meta signs the raw body with the app secret (HMAC-SHA256)
const raw = await this.helpers.getBinaryDataBuffer(0, 'data');
const got = String($input.first().json.headers['x-hub-signature-256'] || '');
const want = 'sha256=' + crypto.createHmac('sha256', $env.WA_APP_SECRET).update(raw).digest('hex');
// Constant-time compare; wrong signature = reject, no parsing
const ok = got.length === want.length && crypto.timingSafeEqual(Buffer.from(got), Buffer.from(want));
if (!ok) return [{ json: { ok: false } }];
const body = JSON.parse(raw.toString('utf8'));
// Status updates (delivered/read) carry no messages and stop here
const msg = body.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
return [{ json: { ok: true, id: msg?.id ?? null, from: msg?.from ?? null,
text: msg?.type === 'text' ? msg.text.body : null } }];
The full workflow, one node per line, ready to import:
{
"name": "WhatsApp chatbot with HMAC check",
"nodes": [
{"name": "Verification (GET)", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [0, -200], "webhookId": "wa-get", "parameters": {"httpMethod": "GET", "path": "whatsapp", "responseMode": "responseNode", "options": {}}},
{"name": "Token OK?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [220, -200], "parameters": {"conditions": {"options": {"caseSensitive": true, "typeValidation": "loose"}, "combinator": "and", "conditions": [{"leftValue": "={{ $json.query['hub.verify_token'] }}", "rightValue": "={{ $env.WA_VERIFY_TOKEN }}", "operator": {"type": "string", "operation": "equals"}}]}, "options": {}}},
{"name": "Return challenge", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [440, -260], "parameters": {"respondWith": "text", "responseBody": "={{ $json.query['hub.challenge'] }}", "options": {}}},
{"name": "Reject 403 (GET)", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [440, -140], "parameters": {"respondWith": "noData", "options": {"responseCode": 403}}},
{"name": "WhatsApp webhook (POST)", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [0, 100], "webhookId": "wa-post", "parameters": {"httpMethod": "POST", "path": "whatsapp", "responseMode": "responseNode", "options": {"rawBody": true}}},
{"name": "Check signature", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [220, 100], "parameters": {"jsCode": "const crypto = require('crypto');\n// Meta signs the raw body with the app secret (HMAC-SHA256)\nconst raw = await this.helpers.getBinaryDataBuffer(0, 'data');\nconst got = String($input.first().json.headers['x-hub-signature-256'] || '');\nconst want = 'sha256=' + crypto.createHmac('sha256', $env.WA_APP_SECRET).update(raw).digest('hex');\n// Constant-time compare; wrong signature = reject, no parsing\nconst ok = got.length === want.length && crypto.timingSafeEqual(Buffer.from(got), Buffer.from(want));\nif (!ok) return [{ json: { ok: false } }];\nconst body = JSON.parse(raw.toString('utf8'));\n// Status updates (delivered/read) carry no messages and stop here\nconst msg = body.entry?.[0]?.changes?.[0]?.value?.messages?.[0];\nreturn [{ json: { ok: true, id: msg?.id ?? null, from: msg?.from ?? null,\n text: msg?.type === 'text' ? msg.text.body : null } }];"}},
{"name": "Signature OK?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [440, 100], "parameters": {"conditions": {"options": {"caseSensitive": true, "typeValidation": "loose"}, "combinator": "and", "conditions": [{"leftValue": "={{ $json.ok }}", "rightValue": "", "operator": {"type": "boolean", "operation": "true", "singleValue": true}}]}, "options": {}}},
{"name": "Reject 403", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [660, 260], "parameters": {"respondWith": "noData", "options": {"responseCode": 403}}},
{"name": "Respond 200 at once", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.1, "position": [660, 40], "parameters": {"respondWith": "noData", "options": {"responseCode": 200}}},
{"name": "Is it text?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [880, 40], "parameters": {"conditions": {"options": {"caseSensitive": true, "typeValidation": "loose"}, "combinator": "and", "conditions": [{"leftValue": "={{ $json.text }}", "rightValue": "", "operator": {"type": "string", "operation": "notEmpty", "singleValue": true}}]}, "options": {}}},
{"name": "New messages only", "type": "n8n-nodes-base.removeDuplicates", "typeVersion": 2, "position": [1100, 40], "parameters": {"operation": "removeItemsSeenInPreviousExecutions", "logic": "removeItemsWithAlreadySeenKeyValues", "dedupeValue": "={{ $json.id }}", "options": {}}},
{"name": "OpenAI reply", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1320, 40], "onError": "continueRegularOutput", "credentials": {"httpHeaderAuth": {"id": "openai-key", "name": "OpenAI (the project's own key)"}}, "parameters": {"method": "POST", "url": "https://api.openai.com/v1/responses", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ model: 'gpt-6-luna', max_output_tokens: 300, input: $json.text, instructions: 'You answer WhatsApp messages for a Danish small business. Reply in the language the customer writes in, short and polite. Use ONLY these facts: ' + $env.FAQ_TEXT + ' If the answer is not in the facts, reply exactly [HANDOFF].' }) }}", "options": {"timeout": 20000}}},
{"name": "Build reply", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [1540, 40], "parameters": {"jsCode": "// The model answers [HANDOFF] when the facts do not cover the question\nconst out = ($json.output || []).find(o => o.type === 'message');\nconst answer = (out?.content?.[0]?.text || '').trim();\nconst reply = !answer || answer.includes('[HANDOFF]')\n ? \"Thanks! A colleague will reply to you here in the chat.\"\n : answer + '\\n\\n' + \"– AI assistant. Type 'human' to reach a person.\";\nreturn [{ json: { to: $('Check signature').first().json.from, reply } }];"}},
{"name": "Send via Cloud API", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1760, 40], "credentials": {"httpHeaderAuth": {"id": "wa-token", "name": "WhatsApp Cloud API token"}}, "parameters": {"method": "POST", "url": "=https://graph.facebook.com/{{ $env.GRAPH_VERSION }}/{{ $env.WA_PHONE_NUMBER_ID }}/messages", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ messaging_product: 'whatsapp', to: $json.to, type: 'text', text: { body: $json.reply } }) }}", "options": {}}}
],
"connections": {
"Verification (GET)": {"main": [[{"node": "Token OK?", "type": "main", "index": 0}]]},
"Token OK?": {"main": [[{"node": "Return challenge", "type": "main", "index": 0}], [{"node": "Reject 403 (GET)", "type": "main", "index": 0}]]},
"WhatsApp webhook (POST)": {"main": [[{"node": "Check signature", "type": "main", "index": 0}]]},
"Check signature": {"main": [[{"node": "Signature OK?", "type": "main", "index": 0}]]},
"Signature OK?": {"main": [[{"node": "Respond 200 at once", "type": "main", "index": 0}], [{"node": "Reject 403", "type": "main", "index": 0}]]},
"Respond 200 at once": {"main": [[{"node": "Is it text?", "type": "main", "index": 0}]]},
"Is it text?": {"main": [[{"node": "New messages only", "type": "main", "index": 0}]]},
"New messages only": {"main": [[{"node": "OpenAI reply", "type": "main", "index": 0}]]},
"OpenAI reply": {"main": [[{"node": "Build reply", "type": "main", "index": 0}]]},
"Build reply": {"main": [[{"node": "Send via Cloud API", "type": "main", "index": 0}]]}
},
"settings": {"executionOrder": "v1"}
}
The model’s instructions are in English while the reply follows the customer’s language; that is a standing rule for us. If the model answers [HANDOFF], the customer is told a colleague will reply. Add your own node to alert staff, for example in Telegram.
What does it cost to run?
Meta charges only for business messages that are actually delivered. When a customer writes, a 24-hour customer service window opens in which the bot may reply freely; outside it you can send approved templates only. Each number gets 1,000 free service messages a month, and from 1 October 2026 service messages beyond that are charged. Denmark sits in the “Rest of Western Europe” region. The per-category rates are in Meta’s rate-card files; we converted them to kroner on the WhatsApp page.
Self-hosted n8n costs only the server. The AI part is a small line item if the model gets only your FAQ and a short output cap. The largest cost is the time spent keeping facts and workflow up to date.
What we ran into with n8n
- Execution history can eat itself. One workflow firing every 50 seconds used up the whole 10,000-execution history limit, leaving every other workflow with roughly 3 days of history. The database grew to 547 MB, 417 MB of it execution data. The fix was to stop saving successful runs for that one workflow.
- The AI Agent node can forget the previous node. In an n8n 1.x release the agent lost the previous node’s output after a tool call, so
$('Node').itemstopped resolving. Use.first()or.all()[$itemIndex]. - Models disappear. On 27 October 2026 we moved all our workflows to current OpenAI models after deprecated ones stopped answering; by 11 November 111 nodes ran on the new model.
- Nobody notices failures at night. Our own agents run daily operational checks: workflows are backed up every day and kept for 30 days, and a scan looks for deprecated AI models. A daily check also catches drift between the website prompt and the WhatsApp prompt.
Customer photos are a story of their own: they expire quickly at Meta and must be copied to your own storage on arrival. The code for that is on the WhatsApp page.
Our test of the file
On 20 November 2026 we imported the Danish version of the file into a fresh, throw-away n8n install on the current official image, with a fake app secret and fake keys. Sending pointed at a local test receiver instead of Meta. The result:
- Verification with the right token returned the challenge; a wrong token got 403.
- A message with a wrong or missing signature got 403. A correctly signed message got 200 straight away.
- The same message sent twice produced one reply to the customer.
- When the AI call failed on the fake key, the customer got the “a colleague will reply” message instead of silence.
The first version failed. We had the wrong operation name in Remove Duplicates; n8n imported the file without a single warning, yet the duplicate went straight through. So always send the same test message twice before going live, and start with your own test number at Meta. This test did not run against Meta’s live API or OpenAI.
Sources
- Meta – WhatsApp Business Platform pricing — charged per delivered message, 24-hour window, 1,000 free service messages, change on 1.10.2026, checked 20.11.2026
- Meta – Webhooks: Getting started —
X-Hub-Signature-256, SHA256 with the app secret, checked 20.11.2026 - Meta – WhatsApp webhooks — retries for up to 7 days, duplicates, 3 MB, checked 20.11.2026
- n8n – Webhook node — Raw Body, respond modes, test vs production URL, checked 20.11.2026
- n8n – WhatsApp Trigger — one webhook per app, account subscription, checked 20.11.2026
- n8n – node environment variables —
NODE_FUNCTION_ALLOW_BUILTIN, checked 20.11.2026 - n8n – Remove Duplicates — remove items processed in previous executions, checked 20.11.2026
Questions about WhatsApp and n8n
Can n8n send WhatsApp messages for free?
n8n does not charge for messages, but Meta does. Replies within 24 hours of the customer’s message are service messages, and the first 1,000 a month per number are free.
Do we have to check Meta’s signature?
You should. Without it, anyone who knows the URL can push fake messages into your bot. The check needs the raw body and your app secret.
Why does the workflow return 200 before the AI reply is ready?
Because Meta retries when it gets no 200. A slow AI call could otherwise bring the same message in several times.
Can we use the WhatsApp Trigger node instead?
Yes, for a quick trial. Remember there is only one webhook per app, so the test and production URLs overwrite each other.
Fixed price, no commitment
Get a fixed price for your chatbot
Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.
- A fixed price before we start
- An answer by e-mail, no calls
- Your details are used only to answer you