how to build a WhatsApp AI agent with n8n and OpenAI
By Catalina Jaramillo · AI Commerce & Revenue Operations Consultant · 2026-11-20
You can launch a self‑servicing WhatsApp AI agent by wiring the WhatsApp Business API, n8n automation, and OpenAI's language model. The workflow captures leads, replies instantly, and pushes data to any CRM without losing prospects.
What accounts and tools do I need?
The core components are a WhatsApp Business API provider, an n8n instance (cloud or self‑hosted), an OpenAI API key, and a CRM that accepts inbound webhooks.
- WhatsApp Business API – choose a provider that offers a sandbox for testing (e.g., Twilio, MessageBird).
- n8n – install on a VPS or use n8n.cloud; ensure HTTPS and a static URL.
- OpenAI – create an API key on platform.openai.com with GPT‑4 access.
- CRM – any system with a REST endpoint (HubSpot, Zoho, Salesforce, or a custom DB).
- Optional: a domain with SSL for webhook callbacks.
How do I design the n8n workflow?
The workflow is a linear chain that receives a WhatsApp message, sends it to OpenAI, returns the AI answer, and records the interaction in the CRM.
- Trigger node: HTTP/Webhook node listening to the WhatsApp provider's inbound messages.
- Parse node: JSON node extracts sender ID, message text, and timestamp.
- AI node: HTTP Request node calls OpenAI’s chat/completions endpoint with the message as user input.
- Response node: Send back the AI text to the WhatsApp provider using its outbound API.
- CRM node: Another HTTP Request node posts lead data (phone, message, AI reply, status) to the CRM.
- Error handling: Add a SplitInBatches node with a fallback message for API failures.
Carolina, Catalina's AI agent, reviews your business, shows which system solves it and what it would cost. If there is a fit, she books a call with Catalina.
Tell Carolina about your case →How do I connect WhatsApp Business API to n8n?
WhatsApp providers push inbound messages to a webhook URL you define. n8n must expose a public HTTPS endpoint that matches the provider’s expectations.
- Create a webhook URL in n8n (e.g., https://mydomain.com/webhook/whatsapp).
- In the provider dashboard, set this URL as the inbound webhook.
- Configure the provider to send the message payload in JSON; map fields in n8n’s Parse node.
- For outbound replies, use the provider’s “messages” endpoint, supplying the recipient’s WhatsApp ID and the AI‑generated text.
- Test with the provider’s sandbox phone number before going live.
How does OpenAI generate the reply?
OpenAI receives the user message, optional context, and a system prompt that defines the agent’s tone and scope.
- System prompt example: “You are a friendly sales assistant for a boutique e‑commerce brand. Answer briefly, suggest next steps, and never ask for personal data.”
- Pass the user message as the ‘user’ role in the chat completion request.
- Set temperature to 0.2 for consistent, factual answers.
- Limit max_tokens to 150 to keep replies short and cost‑effective.
- Log the request‑response pair for quality monitoring.
How do I push leads to a CRM without losing them?
After the AI reply, the workflow records the interaction as a lead record. The CRM receives a unique identifier, the phone number, the original question, and the AI answer.
- Create a “Lead” object in the CRM with fields: phone, source (WhatsApp), last_message, ai_reply, status (new).
- Use the CRM’s upsert endpoint so repeated contacts update the same record instead of creating duplicates.
- Add a “next_action” field based on keywords (e.g., “schedule demo” → create a task for a human sales rep).
- Set up a notification webhook from the CRM to alert a sales rep when a high‑value keyword appears.
- Periodically run a cleanup job in n8n to archive leads older than 90 days.
Common pitfalls and how to avoid them
Many projects stall because of missing error handling, ambiguous prompts, or compliance gaps.
- Never rely on a single API call; add retries with exponential back‑off for both WhatsApp and OpenAI.
- Validate phone numbers before sending to the CRM to avoid malformed records.
- Keep the system prompt concise; overly broad prompts lead to off‑topic answers.
- Monitor OpenAI usage daily; unexpected token spikes can increase costs quickly.
- Respect GDPR/CCPA – store only consented phone numbers and provide an opt‑out keyword.
How Catalina would approach the project
Catalina starts with a strategic diagnosis to map the exact sales funnel, then designs a lightweight n8n prototype that can be measured against baseline metrics.
- Diagnostic (USD 490) – review current lead capture, define conversation intents, and set success KPIs (response time, lead conversion).
- Design – outline the workflow, choose the WhatsApp provider, craft system prompts, and map CRM fields.
- Pilot – build the end‑to‑end flow for a single product line, run it for two weeks, and compare lead quality before and after.
- Metrics – track inbound volume, AI‑handled percentage, and CRM conversion rate; adjust prompts or routing rules as needed.
- Implementation – after a successful pilot, scale the workflow, add multi‑agent routing, and set up a monthly optimization retainer (USD 1 000 – 2 000).
FAQ
Do I need a developer to set up n8n and OpenAI?
No. n8n’s visual editor lets a technically‑savvy marketer configure the nodes, and the OpenAI request is a simple HTTP call. However, a basic understanding of webhooks and JSON is helpful.
How much does the WhatsApp Business API cost?
Providers charge per message (typically $0.005 – $0.015) and a small monthly fee for the phone number. The exact amount depends on the provider you choose.
Can the AI agent handle multiple languages?
Yes. Include the desired language in the system prompt or detect the language in the Parse node and route the request to the appropriate OpenAI model.
What if the AI gives a wrong answer?
Add a fallback node that detects low confidence (e.g., short or irrelevant replies) and forwards the conversation to a human agent via the CRM task queue.
Is there demand for this solution?
9 of 120 public requests that Carolina analyzed in the last 30 days specifically ask for a WhatsApp AI agent built with n8n and OpenAI.
Carolina, Catalina's AI agent, reviews your business, shows which system solves it and what it would cost. If there is a fit, she books a call with Catalina.
Tell Carolina about your case →