Ø THE AI SERVER ← Back to Insights
Automation · Playbook

How to Build an Autonomous AI Agent with n8n & WhatsApp (2026)

12 min read · Published September 2026 · Hands-on Architecture Guide

⚡ Quick Answer: Building an n8n WhatsApp Agent

To build an AI agent on WhatsApp without paying monthly Zapier fees, use a self-hosted n8n instance connected to Meta's WhatsApp Cloud API. Configure n8n's AI Agent Node with OpenAI or DeepSeek as the chat model, a Window Buffer Memory node to retain multi-turn context per phone number, and custom tools (Google Sheets/CRM lookup) to answer queries automatically 24/7.

Why n8n Over Closed SaaS Platforms?

Platforms like Zapier or Make charge per task execution. When your WhatsApp bot receives hundreds of incoming messages daily, monthly bills rapidly explode into hundreds of dollars. With self-hosted n8n running on an inexpensive $5 VPS (DigitalOcean/Hetzner) or local server, you unlock:

Step 1: Set Up Meta WhatsApp Cloud API

Meta provides 1,000 free service conversations per month on WhatsApp Cloud API. Here is how to configure your credentials:

  1. Navigate to developers.facebook.com and create a "Business" type app.
  2. Under "Add products to your app", click Set Up WhatsApp.
  3. Copy your Phone Number ID, WhatsApp Business Account ID, and generate a Permanent System User Access Token in Meta Business Settings.
  4. Configure your Webhook URL pointing to your n8n Webhook Node (e.g. https://n8n.yourdomain.com/webhook/whatsapp) with a custom verification token.

Step 2: Constructing the n8n AI Agent Workflow

In n8n version 1.0+, building an autonomous conversational agent requires 4 core building blocks:

1. The WhatsApp Webhook Trigger

The webhook node receives incoming JSON payloads when a customer messages your number. Extract the sender's phone number from $json.entry[0].changes[0].value.messages[0].from and the message body from messages[0].text.body.

2. The AI Agent Node

Add the AI Agent node in "Chat Agent" mode. In the system prompt, define your business persona, tone of voice, product pricing, and strict operating boundaries:

prompt — n8n system instructions
You are the AI Concierge for [Your Brand Name].
Always respond in polite, concise language suitable for mobile WhatsApp messaging.
Do not invent information. If an inquiry requires human escalation, collect their email and notify the owner.

3. Memory Buffer Node (Multi-Turn Chat Context)

Connect a Window Buffer Memory node to the AI Agent. Set the Session Key to the user's phone number. This ensures that when a client says "How much was that?" the AI recalls the previous messages in that specific thread.

4. Tools (Dynamic Knowledge & Actions)

Connect custom tools to the AI Agent node:

Step 3: Replying Back via WhatsApp API Node

Send the AI's response text back to the customer using an HTTP Request node directed to Meta's graph API:

http — whatsapp cloud api request
POST https://graph.facebook.com/v21.0/YOUR_PHONE_NUMBER_ID/messages
Headers:
  Authorization: Bearer YOUR_META_ACCESS_TOKEN
  Content-Type: application/json
Body:
{
  "messaging_product": "whatsapp",
  "to": "{{ $('Webhook').item.json.sender_number }}",
  "type": "text",
  "text": { "body": "{{ $json.output }}" }
}

Looking for a Turnkey WhatsApp AI System?

We build and deploy bespoke WhatsApp conversational AI engines tailored to restaurants, salons, retail, and real estate brands across India.

See Restaurant AI → Book Consultation →

Related Playbooks

Read more automation guides: How to Build a WhatsApp Chatbot with AI, Automating Workflows with n8n, and 15 Best AI Tools for Small Business.