/14 MIN READ

WhatsApp Business API automation with n8n: production guide

WhatsAppn8nAIAPI

WhatsApp is the most valuable channel in LATAM, Southern Europe, India, and much of Africa. Automating it well — not just "chatbot on a website" well — is one of the highest-ROI things a modern business can do. This guide walks the exact stack we deploy for clients: Meta Cloud API + n8n + an LLM + your CRM.

What you need before writing a single node

  • A Meta Business Manager account (verified).
  • A phone number not currently used on personal WhatsApp.
  • A WhatsApp Business Account (WABA) inside Meta Business.
  • An n8n instance with a public HTTPS URL (self-hosted on a VPS or n8n Cloud).
  • An LLM provider (OpenAI, Anthropic, or a self-hosted model via OpenRouter).

Cloud API vs a BSP: pick your path

Meta Cloud API is free (you only pay per conversation) and gives you full control. BSPs like 360dialog, Twilio, or MessageBird sit on top and add UI, templates management, and support — at 2–4× the per-message cost. For most technical teams: go direct with Cloud API. For non-technical teams that need a nice UI for template creation: pay the BSP tax.

The full architecture

Meta Cloud API (webhook)
   │
   ▼
n8n Webhook node
   │
   ├─▶ Postgres (log message)
   ├─▶ AI Agent node (context + tools)
   │     ├─▶ CRM lookup tool
   │     ├─▶ Calendar tool
   │     └─▶ Knowledge base (pgvector)
   │
   └─▶ HTTP Request → Cloud API (reply)

Step 1: configure the Meta webhook

In Meta Business > WhatsApp > Configuration, set the callback URL to your n8n webhook (e.g. https://n8n.yourdomain.com/webhook/wa-inbound) and a verify token you invent. Subscribe to "messages" events. n8n's Webhook node handles both the verification GET and the incoming POSTs.

// n8n Function node — handle Meta webhook verification
const mode = $input.item.json.query['hub.mode'];
const token = $input.item.json.query['hub.verify_token'];
const challenge = $input.item.json.query['hub.challenge'];
if (mode === 'subscribe' && token === $env.META_VERIFY_TOKEN) {
  return [{ json: { statusCode: 200, body: challenge } }];
}
return [{ json: { statusCode: 403 } }];

Step 2: parse the incoming message

Meta's payload is deeply nested. Extract the phone, message body, and message type in one Set node so the rest of the workflow stays clean.

// Fields to extract in a Set node
from = {{ $json.body.entry[0].changes[0].value.messages[0].from }}
text = {{ $json.body.entry[0].changes[0].value.messages[0].text.body }}
type = {{ $json.body.entry[0].changes[0].value.messages[0].type }}
phoneNumberId = {{ $json.body.entry[0].changes[0].value.metadata.phone_number_id }}

Step 3: the AI Agent node

Wire an AI Agent node with a system prompt describing the agent's role, connect an OpenAI or Anthropic chat model, and attach tools: a CRM lookup HTTP node, a knowledge base retriever (pgvector), and a calendar booking node. Add a Postgres Memory node keyed on the phone number so the agent remembers prior turns.

Step 4: send the reply

// HTTP Request node → https://graph.facebook.com/v20.0/{{phoneNumberId}}/messages
// Headers: Authorization: Bearer {{ $env.META_TOKEN }}
// Body:
{
  "messaging_product": "whatsapp",
  "to": "{{ $json.from }}",
  "type": "text",
  "text": { "body": "{{ $json.agentReply }}" }
}

The gotchas nobody warns you about

The 24-hour window

You can only send free-form messages within 24h of the user's last message. After that you must use pre-approved template messages. Design flows so critical follow-ups happen inside the window, and use templates for re-engagement.

Template approval takes 1–72h

Never launch a campaign that depends on a template you submitted the same day. Meta reviews templates manually. Design templates without promotional language on the first pass; you can always add urgency later.

Rate limits scale with quality

New numbers start at 250 conversations/24h. They tier up automatically if your quality rating stays high. One spam complaint drops you a tier. Warm up gradually.

Handle media (images, audio, docs)

Incoming media only arrives as an ID. You must call the Media API to download it, then re-upload if you want to reply with it. Cache aggressively — Meta media URLs expire in 5 minutes.

Cost breakdown for 10k conversations/month

  • Meta conversation fees (mix of utility + marketing, LATAM pricing): ~$180–$350.
  • n8n self-hosted on Hetzner CX22: $6.
  • OpenAI GPT-4.1 mini at ~4k tokens/conversation avg: ~$40.
  • Postgres (Supabase free tier is fine at this scale): $0.
  • Total: ~$230–$400/month for a fully autonomous agent handling 10k real conversations.

Going live checklist

  • Verify business, approve display name.
  • Submit at least 2 utility templates and 1 marketing template before launch day.
  • Add a human-handoff path (a tool that pings your team on Slack/Telegram).
  • Log every message to Postgres — you'll need it when Meta asks about a complaint.
  • Set up Langfuse or a simple dashboard to track cost and reply latency.
  • Add opt-out handling: any message containing "stop" or "unsubscribe" flips a flag in your CRM.

Want us to design, build, and operate your WhatsApp AI agent end-to-end? We deliver in 3–6 weeks.

Start on WhatsApp

Want to apply this in your business without losing weeks?

Talk to us on WhatsApp