DEV Community

AgoraIntelligence
AgoraIntelligence

Posted on

Build an AI WhatsApp Customer Service Bot with n8n (No Code, 30 Minutes)

Your WhatsApp Business account receives a message at 11pm. It's a potential client asking about your services. By the time you see it tomorrow morning, they've already bought from a competitor.

This tutorial shows you how to build a 24/7 AI-powered WhatsApp customer service bot using n8n that:

  • Classifies every incoming message (urgent complaint, booking request, general info)
  • Replies automatically with AI-generated responses personalized to your business
  • Escalates to your phone via Telegram when something actually needs your attention
  • Logs everything to Google Sheets for review

No coding required. Setup time: ~30 minutes.

How It Works

The workflow has 9 nodes and follows a simple decision tree:

WhatsApp webhook → Parse message → Classify intent (GPT-4o-mini)
       ↓
   URGENT? → Yes → Telegram alert + log
       ↓ No
   Generate AI reply → Send via WhatsApp API → Log to Sheets → Respond 200
Enter fullscreen mode Exit fullscreen mode

The Intent Classification

The OpenAI node classifies each message into one of four intents:

  • URGENT — complaints, cancellation threats, problems ("the product arrived broken")
  • INFO — general questions ("what are your hours?", "do you deliver to Madrid?")
  • BOOKING — appointment requests ("I'd like to book for Friday at 5pm")
  • OTHER — anything else

This is the key logic that decides whether you get woken up or the bot handles it silently.

Step-by-Step Setup

1. WhatsApp Cloud API (Meta)

Go to developers.facebook.com, create an app, add WhatsApp product, and get:

  • Phone Number ID
  • Access Token (temporary → convert to permanent)
  • Verify Token (you invent this, e.g. my_verify_token_2026)

Set up the webhook to point to your n8n instance:

Webhook URL: https://your-n8n.com/webhook/whatsapp-bot
Subscribed fields: messages
Enter fullscreen mode Exit fullscreen mode

2. The n8n Webhook Node

Configure as POST, path: whatsapp-bot. The webhook also needs to handle GET requests for Meta's verification challenge — add a second route or use an IF node to detect the hub.challenge parameter.

3. The CONFIG Node (the only node you edit)

All settings live in one Code node at the top:

const CONFIG = {
  // WhatsApp
  wa_phone_id: "YOUR_PHONE_NUMBER_ID",
  wa_token: "YOUR_WHATSAPP_ACCESS_TOKEN",

  // Telegram escalation  
  telegram_token: "YOUR_BOT_TOKEN",
  telegram_chat_id: "YOUR_CHAT_ID",

  // Google Sheets
  sheet_id: "YOUR_SPREADSHEET_ID",
  gcp_service_account: "vcWuMisYV6Kfx8Vv", // your n8n credential ID

  // AI context — this is what makes replies feel personalized
  business_name: "Clínica Dental Sánchez",
  business_description: "Clínica dental en Madrid, servicios: limpiezas, ortodoncia, implantes. Horario L-V 9-20h, S 9-14h.",
  escalation_keywords: ["urgente", "problema", "queja", "cancelar", "devolver"],
  openai_credential_id: "bC16OOi5YkUp5C10",

  // Fallback if OpenAI fails
  fallback_reply: "Gracias por tu mensaje. Te responderemos lo antes posible en horario laboral."
};

return [{ json: CONFIG }];
Enter fullscreen mode Exit fullscreen mode

4. The AI Reply Generation

The OpenAI node that generates replies uses this prompt structure:

You are a customer service assistant for {{business_name}}.

Business context: {{business_description}}

Customer message: {{message_text}}
Message intent: {{classified_intent}}

Reply professionally in the same language as the customer's message. 
Keep it under 3 sentences. Don't make up information not in the business context.
Enter fullscreen mode Exit fullscreen mode

This is what makes the bot sound like it actually knows your business — not a generic chatbot.

5. Send the WhatsApp Reply

The HTTP Request node sends back via the Cloud API:

POST https://graph.facebook.com/v19.0/{{wa_phone_id}}/messages
Authorization: Bearer {{wa_token}}
Content-Type: application/json

{
  "messaging_product": "whatsapp",
  "to": "{{sender_phone}}",
  "type": "text",
  "text": { "body": "{{ai_reply}}" }
}
Enter fullscreen mode Exit fullscreen mode

6. The Critical Last Node: Respond 200

This is the most important node that most tutorials miss.

WhatsApp requires your webhook to respond with HTTP 200 within 20 seconds. If it doesn't, Meta marks your webhook as unhealthy and stops sending events.

Add a Respond to Webhook node at the very end of every branch (urgent AND non-urgent) that returns {"status": "ok"} with status 200.

Costs

  • n8n: $0 if self-hosted, $20/month on n8n Cloud
  • WhatsApp Cloud API: Free for the first 1,000 conversations/month (Meta's pricing)
  • OpenAI GPT-4o-mini: ~$0.00015 per message. At 100 messages/day: ~$0.46/month
  • Telegram bot: Free

Total for a small business with 100 messages/day: ~$0.46/month in AI costs.

What It Handles (and What It Doesn't)

Handles well:

  • Repeated FAQ questions (hours, pricing, location, delivery)
  • Booking confirmations
  • First contact from new customers
  • After-hours messages

Needs human review:

  • Complaints about specific orders (bot can acknowledge, but you close the ticket)
  • Anything requiring account access or personal data lookup
  • Complex negotiations

The Telegram escalation handles the "needs human review" bucket automatically.

Demo: What a Conversation Looks Like

Customer sends: "Hola, ¿tenéis cita disponible para limpieza este sábado por la mañana?"

Bot replies (in ~3 seconds): "¡Hola! Sí, tenemos citas disponibles los sábados de 9 a 14h. Para reservar, díganos su nombre y el horario preferido y lo gestionamos enseguida."

Customer sends: "El producto que compré llegó roto, exijo una solución AHORA"

Bot triggers Telegram alert to you: 🚨 URGENTE | +34612345678 | "El producto que compré llegó roto, exijo una solución AHORA"

You reply personally. The customer feels heard.

Get the Ready-Made Workflow

If you want to skip the manual setup, the complete workflow with all nodes pre-configured is available on n8nmarkets.com — search "WhatsApp Telegram AI Customer Service Agent".

It includes the workflow JSON, README with screenshots, and curl commands to test every node before going live.


Built something similar? Share your setup in the comments — especially if you've handled the webhook verification challenge in a clever way.

Top comments (0)