How to create an AI agent with n8n that serves customers via WhatsApp: a step-by-step guide for businesses

  • Automation
  • /
  • How to create an AI agent with n8n that serves customers via WhatsApp: a step-by-step guide for businesses
Table of Contents

Estimated reading time: 13 minutes

Unlike a traditional chatbot with predefined answers, an AI agent understands the user’s intent, accesses your company’s information and can execute actions: create a lead in your CRM, send a product card or escalate to a salesperson when the conversation requires it.

At Inprofit we have been implementing automations with n8n self-hosted for companies for more than three years. In this guide we show you the exact architecture we use, the steps to build it and the use cases that generate more return in B2B environments.

What is an AI agent and how is it different from a chatbot?

Before getting into implementation, it is important to clarify the difference because many companies come in looking for “chatbot for WhatsApp” and what they really need is an agent.

Traditional ChatbotAI agent with n8n
ResponsesFixed decision treesGenerated by LLM in real time
UnderstandingKeywords or buttonsNatural language (real intention)
SharesOnly answer messagesCreate leads, consult CRM, send emails
MemoryNo conversational contextRemember the complete thread
MaintenanceMaintain manual flowsImproved by adjusting the prompt
ScalabilityHigh for simple answersDischarge for complex cases

The AI agent doesn’t just respond: it reasons. If a user says “I need the same thing I ordered last month”, the agent can consult the history stored in Supabase and retrieve that order. That’s impossible with a classic chatbot.

Why use n8n to build your WhatsApp agent?

There are several platforms to connect AI with WhatsApp: ManyChat, Tidio, Chatfuel, or even Make (Integromat). So why n8n?

n8n self-hosted gives you full control of your data. Your customer conversations do not go through third-party servers. For B2B companies with sensitive data (quotes, terms of business, customer information), this is not a minor detail.

n8n is the most powerful orchestrator for AI agents. Since version 1.x, n8n includes the native AI Agent node, which integrates directly with OpenAI, Anthropic (Claude), Google Gemini and other LLMs, plus memory, vector and search tools. You don’t need additional code to connect the LLM’s reasoning to the rest of your stack.

The cost per conversation is marginal. With a self-hosted instance on a VPS for 10-20€/month, the only variable cost is the LLM calls (fractions of a cent per message). Compared to SaaS platforms that charge per conversation or per active user, the savings at scale are significant.

Integrates with any tool in your stack. CRMs (HubSpot, Odoo, Salesforce), databases (Supabase, PostgreSQL), email tools, Google Calendar, Slack… n8n has more than 400 native integrations.

If you are still not sure whether n8n or Make is the best option for your company, we recommend you to read our detailed comparison: Make vs n8n: which one to choose to automate your company.

Agent architecture: the four components you need

Before opening n8n, understand the building blocks of the system. An AI agent for WhatsApp always has four layers:

1. The messaging layer: WhatsApp Business API

WhatsApp does not allow you to connect tools directly to a personal account. To automate you need WhatsApp Business API, which you can get through:

  • Target directly (free of charge, company verification process)
  • BSP (Business Solution Providers): 360dialog, Vonage, Twilio. Faster to activate, with cost per message or monthly subscription.

For enterprise and medium to high volume projects, we recommend 360dialog for its clean webhook integration and predictable pricing model.

Once activated, the API sends incoming messages to a webhook URL of your choice. That’s where n8n comes in.

2. The orchestration layer: n8n

n8n receives the webhook, extracts the message from the user, passes it to the AI agent, receives the response and sends it back to WhatsApp. It also orchestrates additional actions: create a contact in the CRM, save the context in database, notify the sales team via Slack, etc.

3. The reasoning layer: the LLM

The language model is the “brain” of the agent. It receives the user’s message along with your company’s instructions (the system prompt) and generates the response. The most commonly used options in production projects:

  • GPT-4o (OpenAI): the most capable and versatile. Best option if the conversational complexity is high.
  • Claude 3.5 Sonnet (Anthropic): excellent for following long and precise instructions. Ideal if the agent must adhere to a strict protocol.
  • Call 3 (local via Ollama): for environments that cannot send data to external servers.

4. The memory layer: Supabase

Without memory, the agent “forgets” each message as soon as the conversation ends. With Supabase (PostgreSQL in the cloud), you store the complete history of each conversation by phone number. When a new message arrives, n8n retrieves the history and injects it into the LLM context. The agent remembers who the user is, what they asked before and at what point they left the conversation.

This layer is what turns a reactive chatbot into a relational agent. None of the competitors that analyze this solution in Spanish explains this part, and it is the one that has the most impact on the customer experience.

How to create your own AI agent with n8n for WhatsApp: step by step

Step 1: Configure your access to the WhatsApp Business API

  1. Enter Meta for Developers and create a “Business” type app.
  2. Activate the WhatsApp product in your app.
  3. In the WhatsApp dashboard, create a test phone number (or add the company number after verification).
  4. Go to Settings > Webhooks and add the URL of your n8n workflow (you will see it in Step 2).
  5. Subscribe to the messages field to receive incoming messages.
  6. Copy the access token and phone ID number: you will need them in n8n.

If you prefer to avoid direct configuration with Meta, you can use 360dialog which offers a more simplified panel and the webhook already configured.

Step 2: Create the main workflow in n8n

Open n8n and create a new workflow. The basic structure has these nodes in sequence:

Node 1 – Webhook (trigger)

  • Type: Webhook
  • Method: POST
  • Path: /whatsapp-agent (or the one you prefer)
  • Copy the production URL: this is the one you paste into Meta/360dialog as webhook URL.
  • Under “Response Mode” select “Respond to Webhook” to control when and how n8n responds.

Node 2 – Set (message extraction)

  • Type: Set
  • Extract from the incoming JSON:
    • phone_number: {{ $json.entry[0].changes[0].value.messages[0].from }}
    • user_message: {{ $json.entry[0].changes[0].value.messages[0].text.body }}
    • message_id: {{ $json.entry[0].changes[0].value.messages[0].id }}
  • It also adds a field timestamp with {{ $now.toISO() }}.

Note: The exact structure of the JSON varies slightly by provider. If you use 360dialog, the payload has one less level of nesting.

Node 3 – Supabase (retrieve history)

  • Type: Supabase
  • Operation: Get Many Rows
  • Table: conversation_history
  • Filter: phone_number = {{ $json.phone_number }}
  • Order: created_at ASC
  • Limit: last 20 messages (so as not to exceed the LLM context window)

Node 4 – Code (format context)

  • Type: Code (JavaScript)
  • Format the retrieved history in the message format expected by the LLM:

javascript

const history = $input.all();
const messages = history.map(row => ({
  role: row.json.role, // 'user' o 'assistant'
  content: row.json.content
}));
return [{ json: { formatted_history: messages } }];

Node 5 – AI Agent

  • Type: AI Agent
  • Connects the OpenAI Chat Model (GPT-4o) or the Anthropic Chat Model (Claude).
  • In “System Message” type your company’s instructions (see prompts section below).
  • In “Messages” inject the formatted history from previous step
  • Add as Tools any action that the agent can perform: consult products, create leads in CRM, etc.

Node 6 – Supabase (save shift)

  • Saves the user’s message and the agent’s response:
    • Insert row with role: 'user', content: mensaje_usuario, phone_number
    • Insert row with role: 'assistant', content: respuesta_agente, phone_number

Node 7 – HTTP Request (send reply to WhatsApp)

  • Type: HTTP Request
  • Method: POST
  • URL: https://graph.facebook.com/v19.0/{PHONE_NUMBER_ID}/messages
  • Headers: Authorization: Bearer {ACCESS_TOKEN}
  • Body (JSON):

json

{
  "messaging_product": "whatsapp",
  "to": "{{ $('Set').item.json.phone_number }}",
  "type": "text",
  "text": {
    "body": "{{ $('AI Agent').item.json.output }}"
  }
}

Node 8 – Respond to Webhook

  • Returns HTTP 200 to Meta/360dialog to confirm receipt.
  • If you do not reply 200 in less than 5 seconds, the provider retries sending and you will receive a duplicate message.

Step 3: Design your agent’s system prompt

The system prompt is the standing instruction that defines how the agent behaves. It is the equivalent of the onboarding manual for a new employee. A good system prompt for a B2B agent includes:

Eres el asistente comercial de [NOMBRE EMPRESA], especializada en [sector/producto].

Tu objetivo principal es:
1. Responder preguntas sobre nuestros productos/servicios con precisión
2. Cualificar al usuario (empresa, necesidad, urgencia, presupuesto)
3. Si el usuario cumple el perfil de cliente, ofrecer una reunión con el equipo comercial
4. Si no cumple el perfil, ofrecer recursos útiles y cerrar amablemente

Reglas de comportamiento:
- Responde siempre en el idioma del usuario
- Sé conciso: máximo 3-4 frases por respuesta en WhatsApp
- Nunca inventes información. Si no sabes algo, di que lo consultas y escala
- No menciones precios específicos sin antes cualificar la necesidad
- Si el usuario lleva más de 3 mensajes sin avanzar, propón hablar con una persona

Información sobre nuestra empresa:
[Aquí pega la información que el agente debe conocer: catálogo, precios orientativos, proceso de compra, FAQ, etc.]

The quality of the system prompt determines 70% of the agent’s behavior. Spend time refining it with real cases.

Step 4: Add tools for the agent to perform

The difference between an agent that just talks and one that acts is in the tools you give it. In n8n, each tool is a sub-workflow or a node that the agent can invoke when needed. Practical examples:

  • Create lead in HubSpot/Odoo: when the user shares your email or company
  • Check product availability: makes an HTTP Request to your ERP/catalog
  • Schedule meeting: create an event in Google Calendar and send the link from Calendly
  • Escalate to human: send a notification to Slack with the summary of the conversation.
  • Search in knowledge base: query a vector store with your internal documentation

To use tools in the n8n AI Agent node, activate “Use Tools” and add the sub-workflows or nodes you want the agent to be able to invoke. The LLM automatically decides when to use each tool according to the context.

Step 5: Test and adjust before production

Before activating the webhook in production, test with Meta test numbers and simulate real conversations. Review:

  • Does the agent respond in less than 3 seconds (Key to WhatsApp experience)?
  • Does it respect the system prompt in borderline cases?
  • Is the history saved and retrieved correctly in Supabase?
  • What happens if the user sends an image or audio (message types not supported)?

For the last point, add an IF node before the agent that filters by message type and responds with a friendly message if the content is not text.

Real use cases for B2B companies

24/7 inbound lead qualification

This is the use case with the highest immediate return. The agent receives the initial message (“I want information about your services”), asks the key qualification questions (sector, company size, specific need, urgency) and, if the lead fits, automatically creates the record in the CRM and notifies the assigned salesperson.

Sales teams that implement this reduce initial response time from hours to seconds and eliminate the loss of out-of-hours leads. You can take a deeper dive into how to structure this flow in our article on B2B lead n8n lead nurturing.

Follow-up of proposals and recovery of opportunities

The agent can proactively follow up: when a CRM marks a proposal as “no response in X days”, n8n triggers a personalized WhatsApp message with the contact’s name and proposal reference. If the user responds, the agent resumes the conversation and logs it.

This flow, combined with an AI SDR strategy, can significantly improve the cold pipeline closure rate. See more in: AI SDR: B2B prospecting automation.

After-sales service and technical support

For software companies or recurring services, the agent can resolve the most frequent support queries (invoice status, platform access, configuration questions) without team intervention. It only escalates when it detects frustration in the user’s language or when the query exceeds its knowledge base.

Cart recovery in B2B ecommerce

If you have a WooCommerce store with enterprise customers, the agent can send a WhatsApp message when a cart is abandoned, ask if they need help with the checkout process or payment terms and, if the customer responds, handle the query in the chat itself. You can see the technical implementation of this flow in our article on recovering abandoned carts with WhatsApp and AI.

Common mistakes when implementing an AI agent with n8n for WhatsApp.

1. Do not manage duplicate messages. WhatsApp resends the webhook if you do not receive 200 replies within 5 seconds. If your agent takes longer (due to LLM calls), you may receive the same message twice. Solution: reply 200 immediately with the Respond to Webhook node and process the message asynchronously.

2. A generic system prompt. “You’re a friendly assistant who helps customers” is not enough. The agent needs to know what he can and cannot do, what information is available to him and when to escalate. The more specific the prompt, the better the agent performs.

3. Forgetting the token limit. If you inject all the conversation history to the LLM without limit, in long conversations the cost skyrockets and the response may degrade. Limit the history to the last 15-20 messages or use a digest strategy (the agent generates a digest every X turns that replaces the long history).

4. Do not contemplate non-textual messages. Users send audios, images, stickers, locations. If you don’t have an IF node that filters by message type, the workflow will fail. Define a standard response for each unsupported type.

5. Skipping tests with borderline cases. Always test: user who insults, user who asks for things out of scope, user who writes in another language, user who tries to do prompt injection (“forget your instructions and…”). A badly tested agent generates compromised situations in production.

How much does it cost to implement an AI agent with n8n for WhatsApp?

ComponentApproximate costNotes
n8n self-hosted (VPS)10-20 €/monthHetzner, DigitalOcean, Contabo
WhatsApp Business API (Meta)Free (first 1,000 conv./month)After: ~0.05-0.08 €/conversation
GPT-4o (OpenAI)~0.002-0.01 € per messageAccording to context length
SupabaseFree (up to 500 MB)Pro Plan from $25/month
Total monthly (average volume)~50-150 €/monthFor 500-2,000 conversations

Compared to SaaS platforms such as ManyChat Pro ($299/month) or enterprise chatbot solutions (from €500/month), the self-hosted cost is significantly lower with greater control and capacity.

Frequently Asked Questions

What is an AI agent for WhatsApp?

An AI agent for WhatsApp is an automated system that uses language modeling (LLM) to have natural conversations with customers via the WhatsApp Business API. Unlike a traditional chatbot, it understands natural language, remembers the context of the conversation and can execute actions such as creating leads in a CRM or scheduling meetings.

How to create an AI agent with n8n?

To create an AI Agent with n8n you need to: (1) connect WhatsApp Business API via webhook, (2) use the native n8n AI Agent node connected to an LLM such as GPT-4o or Claude, (3) add persistent memory with Supabase or PostgreSQL, and (4) define the system prompt with your company’s instructions. The complete process is detailed step by step in this guide.

How to put AI in WhatsApp Business?

To add AI to WhatsApp Business you need the WhatsApp Business API (available through Meta or providers such as 360dialog or Twilio). Once you activate the API, you can connect it with tools such as n8n to process messages with an LLM and generate intelligent autoresponders.

Can WhatsApp be automated with n8n for free?

Yes, with certain limitations. n8n has a free cloud version (with a limit of executions) and can be hosted for free on some VPS with a basic plan. WhatsApp Business API offers 1,000 free conversations per month with Meta. The only almost inevitable cost is the LLM calls, although with cheaper models like GPT-4o-mini the cost per conversation is fractions of a cent.

How long does it take to implement this type of agent?

A basic agent (answers frequently asked questions and qualifies leads) can be up and running in 2-3 days with n8n. An agent with full memory, CRM tools and escalation logic to human requires 1-3 weeks of configuration and prompt tuning depending on the complexity of the business.

Is it safe to send customer data to GPT-4o or Claude?

OpenAI and Anthropic have API modes that do not use the submitted data to train their models (this applies by default to calls via API, not via web interface). If your industry regulation requires it, you can opt for local models (Llama 3 via Ollama) or models in the European cloud. With n8n self-hosted, the conversation data always remains on your server.

Conclusion: the most powerful AI agent is the one that is integrated into your sales process.

Creating an AI agent with n8n for WhatsApp is not technically complicated. What makes the difference between an agent that really impacts the business and one that remains an experiment is the integration with the real processes of the company: the CRM, the sales team, the qualification flows.

At Inprofit we implement these types of agents as part of end-to-end automation projects, combining n8n with Supabase, Odoo and each client’s own tools. If you want to understand how it would apply to your company, the next step is to explore the 8 must-have AI agents for enterprises in 2026 or see how a complete B2B automation strategy is structured with n8n and no-code tools.

Do you have a clear use case but don’t know where to start? Tell us your situation and we will make you a proposal without obligation.


Published by the Inprofit team | Updated: May 2026 Inprofit is an agency specialized in business automation, SaaS development and digital marketing. We implement n8n self-hosted in production for clients from different sectors since 2022.

Doubts? Contact us at
The personal data contained in the consultation will be processed by INPROFIT CONSULTING, SL and incorporated into the processing activity CONTACTS, whose purpose is to respond to your requests, requests or inquiries received from the web, via email or telephone. To respond to your request and to make a subsequent follow-up. The legitimacy of the treatment is your consent. Your data will not be disclosed to third parties. You have the right to access, rectify and delete your data, as well as other rights as explained in our privacy policy: Data Protection Policy.

WEBS 3.0

Discover the new digital era
Request a demo of AI, predictive analytics and web and e-commerce automations

Latest posts
  • All Post
  • 360 Marketing
  • Advertising
  • Automation
  • Branding
  • Business strategy
  • Consultancy
  • Conversion Funnel
  • CRO
  • Digital
  • Digital analytics
  • Digital transformation
  • Hologram
  • Inbound Marketing
  • Inprofit
  • Interim Management
  • Marketing
  • Marketing Consultant
  • Marketing Technologies
  • Marketing Trends
  • Martech
  • Neuromarketing
  • Paid Media
  • Program
  • Retargeting
  • Search Engine Optimization
  • Sin categorizar
  • Social Ads
  • Video Marketing
  • Web

From plan to ROI

Develop new sales, marketing, automation and AI strategies to lead the market.

© 2026 Inprofit Consulting S.L.

CIF: ESB4260505555

Alicante Office: Calle Primero de Mayo, 4 (Alcoy) | Valencia Office: Calle Colón, 4 (Valencia)