WhatsApp has over 2 billion users worldwide, and in many markets it's the primary way customers communicate with businesses. If you're still manually answering every inquiry, scheduling every appointment, and qualifying every lead by hand — you're leaving money and time on the table.
In this guide, I'll walk you through building WhatsApp automation workflows with n8n, the open-source workflow automation platform. We'll cover architecture, common patterns, and a complete lead qualification workflow with real code.
I'm Achiya Cohen, founder of Achiya Automation where we build business automation solutions — from WhatsApp bots to full CRM integrations and workflow automation — for businesses in Israel. After deploying dozens of these systems, here's what I've learned.
Why n8n for WhatsApp Automation?
There are plenty of automation tools out there — Zapier, Make, custom code. Here's why n8n stands out for WhatsApp workflows specifically:
Open-source and self-hosted. Your WhatsApp messages contain customer data — names, phone numbers, conversations. With n8n self-hosted, that data stays on your infrastructure. No third-party SaaS reading your customers' messages.
Visual workflow builder. WhatsApp automation logic gets complex fast. Branching based on message content, time-based follow-ups, multi-step conversations — n8n's visual canvas makes this manageable and debuggable.
Native JavaScript support. When you need custom logic (and you will), n8n lets you drop into JavaScript or Python right inside the workflow. No external functions or Lambda deployments needed.
Queue mode for reliability. n8n supports queue-based execution with Redis, meaning incoming WhatsApp messages won't get dropped during traffic spikes.
200+ integrations. Connect WhatsApp to your CRM, database, Google Sheets, Slack, email — whatever your stack looks like.
Architecture Overview
Here's the high-level architecture for a WhatsApp automation system:
┌─────────────┐ webhook ┌─────────┐ ┌───────────┐
│ WhatsApp │ ───────────────> │ n8n │ ──> │ Database │
│ API Layer │ <─────────────── │ Workers │ ──> │ (Postgres)│
└─────────────┘ send message └─────────┘ └───────────┘
│
├──> CRM (HubSpot, etc.)
├──> Notifications (Slack, Email)
└──> Analytics
WhatsApp API Layer — This can be the official WhatsApp Business API (via a BSP like 360dialog or Twilio), or a community/unofficial solution like WAHA. Note: WAHA is an unofficial, community-driven WhatsApp API — it's not endorsed or supported by Meta. Choose based on your compliance requirements and use case.
n8n — The brain. Receives webhooks from the WhatsApp API, processes messages, runs business logic, and sends responses back.
Database — Stores conversation state, customer data, and interaction history. PostgreSQL is the natural choice since n8n already uses it internally.
Common Automation Patterns
1. Smart Auto-Replies
The simplest starting point. Route incoming messages based on content:
// n8n Function node — classify incoming message
const message = $input.first().json.body.toLowerCase();
const keywords = {
pricing: ['price', 'cost', 'how much', 'pricing', 'quote'],
hours: ['hours', 'open', 'when', 'schedule', 'time'],
support: ['help', 'issue', 'problem', 'broken', 'bug'],
};
for (const [category, words] of Object.entries(keywords)) {
if (words.some(word => message.includes(word))) {
return [{ json: { category, originalMessage: message } }];
}
}
return [{ json: { category: 'unknown', originalMessage: message } }];
Then use a Switch node to branch into different response paths.
2. Appointment Booking
A multi-step conversation flow:
- Customer says "I want to book"
- Bot presents available time slots (pulled from Google Calendar API)
- Customer selects a slot
- Bot confirms and creates the calendar event
- Sends a reminder 24 hours before
The key challenge here is conversation state. n8n doesn't natively track multi-step conversations, so you need a state store:
// Save conversation state to database
const phone = $input.first().json.from;
const state = {
phone,
step: 'awaiting_slot_selection',
availableSlots: $input.first().json.slots,
updatedAt: new Date().toISOString(),
};
// Use n8n's Postgres node to upsert this
return [{ json: state }];
3. Lead Qualification
Ask a series of qualifying questions, score the lead, and route accordingly. We'll build this one out fully below.
4. Follow-Up Sequences
Use n8n's Cron trigger or Wait node to send timed follow-ups:
- Day 1: "Thanks for your inquiry! Here's more info..."
- Day 3: "Did you have any questions?"
- Day 7: "We have a special offer this week..."
The Wait node is your friend here — it pauses execution for a specified duration, then continues the workflow.
Full Example: Lead Qualification Workflow
Let's build a complete workflow that:
- Receives a WhatsApp message
- Checks if we're in an active qualification flow
- Asks qualifying questions
- Scores the lead
- Saves to CRM
- Notifies the sales team
Step 1: Webhook Receiver
Set up a Webhook node in n8n to receive incoming messages from your WhatsApp API. The payload typically looks like:
{
"from": "972501234567",
"body": "Hi, I'm interested in your service",
"timestamp": "2026-03-12T10:30:00Z"
}
Step 2: Conversation State Check
// Function node — check conversation state
const phone = $input.first().json.from;
// Query your state table (via a preceding Postgres node)
const existingState = $('Postgres Query').first().json;
if (!existingState || !existingState.step) {
// New conversation — start qualification
return [{
json: {
phone,
step: 'ask_business_type',
isNew: true,
responses: {},
}
}];
}
// Existing conversation — continue from where we left off
return [{
json: {
...existingState,
latestMessage: $input.first().json.body,
}
}];
Step 3: Qualification Questions
Use a Switch node on the step field, then handle each step:
// Function node — process response and determine next step
const state = $input.first().json;
const message = state.latestMessage;
const flow = {
ask_business_type: {
responseKey: 'businessType',
nextStep: 'ask_team_size',
nextMessage: 'How many people are on your team? (1-5, 6-20, 20+)',
},
ask_team_size: {
responseKey: 'teamSize',
nextStep: 'ask_current_solution',
nextMessage: 'Are you currently using any automation tools? (yes/no)',
},
ask_current_solution: {
responseKey: 'currentSolution',
nextStep: 'complete',
nextMessage: null, // Will be handled by scoring
},
};
const currentFlow = flow[state.step];
if (!currentFlow) return [{ json: state }];
state.responses[currentFlow.responseKey] = message;
state.step = currentFlow.nextStep;
state.replyMessage = currentFlow.nextMessage;
return [{ json: state }];
Step 4: Lead Scoring
// Function node — score the qualified lead
const responses = $input.first().json.responses;
let score = 0;
// Team size scoring
const sizeScores = { '20+': 30, '6-20': 20, '1-5': 10 };
score += sizeScores[responses.teamSize] || 10;
// Already using automation — higher intent
if (responses.currentSolution?.toLowerCase() === 'yes') {
score += 20; // Knows the space, ready to switch
} else {
score += 10; // Needs education, but still interested
}
const tier = score >= 40 ? 'hot' : score >= 25 ? 'warm' : 'cold';
return [{
json: {
...responses,
phone: $input.first().json.phone,
score,
tier,
qualifiedAt: new Date().toISOString(),
}
}];
Step 5: CRM + Notification
After scoring, use n8n's built-in nodes:
- HTTP Request node to push to your CRM (HubSpot, Pipedrive, etc.)
- Slack or Email node to notify your sales team with lead details
- WhatsApp reply to thank the customer and set expectations
// Compose the final reply based on tier
const tier = $input.first().json.tier;
const replies = {
hot: "Thanks for the info! You sound like a great fit. A team member will reach out within the hour.",
warm: "Thanks! I'm sending you some resources that might help. We'll follow up soon.",
cold: "Thanks for reaching out! Here's a link to our FAQ that covers the basics: ...",
};
return [{ json: { reply: replies[tier] } }];
Tips and Best Practices
Handle errors gracefully. WhatsApp messages fail silently. Always add error handling branches in your workflows. n8n's "Error Trigger" workflow is essential — set it up to alert you when any workflow fails.
Rate limit your responses. Don't fire back instantly on every message. A 1-2 second delay feels more natural and avoids triggering spam detection.
Store raw messages. Log every incoming and outgoing message to your database. You'll need this for debugging, analytics, and compliance.
Use conversation timeouts. If a user doesn't respond to a qualification question within 24 hours, reset the conversation state. Stale states cause confusing experiences.
Test with a dedicated number. Never test automation on a production WhatsApp number. One bad loop can spam hundreds of customers.
Keep flows modular. Break complex bots into sub-workflows in n8n. One workflow for qualification, one for booking, one for follow-ups. Connect them via workflow triggers.
Monitor execution history. n8n keeps execution logs — review them regularly. They're your best debugging tool and will reveal edge cases you didn't anticipate.
Wrapping Up
WhatsApp automation with n8n gives you the flexibility of code with the accessibility of a visual builder. Start with simple auto-replies, build confidence, and gradually add complexity — lead qualification, booking flows, CRM integrations.
The key insight from building these systems: the bot doesn't need to handle everything. The best WhatsApp automations handle the repetitive 80% and hand off the complex 20% to humans — with full context.
If you're building something similar or want to compare notes, feel free to reach out. Happy automating.
Found this useful? Follow me for more automation content. You can also check out achiya-automation.com for real-world business automation examples — WhatsApp bots, CRM integrations, and more.
Top comments (0)