
n8n WhatsApp Cloud API Workflow: Build a Support Flow Step by Step
Step-by-step n8n WhatsApp Cloud API workflow: receive messages, answer with AI inside clear limits, log every conversation and hand off to a person.
Want to apply this in your company?
Book a call with Juan →n8n WhatsApp Cloud API Workflow: Build a Support Flow Step by Step
To build a support flow with n8n and the WhatsApp Cloud API, you need four blocks: a webhook that receives messages from Meta, a step that decides whether the AI may answer, a record of everything that comes in and goes out, and a clear path for handing the conversation to a person. n8n orchestrates, the Cloud API carries the messages, and the AI is used only where judgment is needed, always within limits on data, actions and steps.
Key takeaways
- n8n receives the Cloud API webhook, but the flow is only reliable if it validates the source, discards duplicates and acknowledges Meta quickly.
- The AI should be one step with restricted input, a defined knowledge base and validated output, not the center of the flow.
- Log every message, decision and handoff reason in a table you own, not only in the n8n execution history.
- Handoff needs objective triggers and a summary for whoever takes over the conversation.
- Start with one real flow and one agreed metric, and expand only after that.
What is the minimum architecture for a support flow in n8n?
Before you open the n8n editor, sketch the path of a customer message from arrival to reply. A minimal design that works for most support operations has these blocks:
- Entry: the webhook receives the event from the Cloud API and confirms receipt.
- Validation and normalization: check the source, separate messages from status events and reduce the payload to a few fields.
- Deduplication and state: check whether the message was already processed and whether the conversation is with the AI or with a human.
- Decision: deterministic rules first (business hours, urgency words, message type), AI second.
- Reply: the AI produces structured output, a node validates it, and only then does n8n send.
- Logging: every step writes to a table or database the team can query.
- Handoff: when a trigger fires, the AI steps aside and a person is notified with context.
The rule of thumb is that anything that can be decided without AI should be decided without AI. That makes the flow cheaper, more predictable and easier to audit. The AI keeps the work that truly needs language interpretation, such as understanding the customer's question and drafting an answer from an approved knowledge base.
How do you set up the Cloud API and the webhook in n8n?
What follows combines official documentation and implementation practice. For exact field names, permissions and screens, always rely on Meta's documentation, which changes over time.
On the Meta side, you need an app with the WhatsApp product, a registered phone number, a business account and, to operate at real scale, business verification. It is also advisable to generate a long-lived access token tied to a system user instead of relying on the temporary testing token. That token and the app secret are credentials: store them in the n8n credential vault, never inside code nodes or chat messages.
On the n8n side, there are two common ways to receive events: the WhatsApp Trigger node, which handles webhook registration for you, and a generic Webhook node, which gives you more control over the raw body and headers. If you want to validate the request signature, the control of the generic node is usually useful. In either case, three precautions apply:
- Use the production webhook URL, not the test URL, and keep the workflow active.
- Subscribe only to the fields the flow needs, usually messages and their statuses.
- Keep the webhook verify token different from any other password.
If your company has not been through verification yet, the guide to Meta business verification for the WhatsApp API covers the process. Here the focus is the flow.
How do you receive messages without duplicating or losing events?
The Cloud API payload is nested and carries both new messages and status updates (sent, delivered, read, failed) in the same webhook. If the flow treats everything as a customer message, the AI will reply to a read receipt. The first node after the webhook should therefore separate the two types and end status events early, storing them only if you want to track delivery.
Then normalize. For each message, extract a small, stable set of fields:
- message ID
- contact phone number and profile name
- message type (text, audio, image, button, location)
- text content, when there is any
- event time
Three problems come up often. The first is duplicates: webhook providers usually resend events when they do not get a timely confirmation, and Meta is no exception. Use the message ID as a key and discard anything already seen. This is the same idea as idempotency in payment APIs, and the documentation of payment providers on webhook delivery, signatures and retries is a good conceptual reference even though the provider is different.
The second is response time. Acknowledge receipt quickly and only then process the slow part, which is the call to the AI model. If the webhook stays open waiting for the model, Meta may resend the event and you will send double replies. The third is the signature: Meta signs request bodies with the app secret, and checking that signature stops anyone who discovers your URL from injecting fake messages into your flow. Confirm the header and algorithm in Meta's documentation, and check whether your n8n version exposes the raw body for that calculation.
For failures and reprocessing, the article on n8n error handling and retries explains how to set up queues, retries and alerts so the flow does not fail silently.
How do you answer with AI without losing control?
The AI reply is the part that attracts the most attention and the one that needs the most limits. Treat the customer's message as untrusted input: it may contain disguised instructions, out-of-scope requests or data that should not circulate. Layered defenses against this are described in the prompt injection protection guide, and they fit well in an n8n flow.
In practice, the limits live in five places:
- Context: send the model only the latest messages of the conversation and the knowledge base passages relevant to the question, not the entire history or customer records the answer does not need.
- Approved base: the AI answers from content the company has reviewed (hours, policies, process steps). If the answer is not there, the path is handoff, not improvisation.
- Structured output: ask the model for an object with fields such as intent, reply text, confidence level and a flag saying a human is needed. A following node validates the format before anything is sent.
- Actions: the AI does not cancel orders, grant discounts, promise deadlines or change records. If it ever has to execute something, make it a narrow action with human approval.
- Step budget: limit attempts, time and reply length, and define how many consecutive answers the AI may give without the customer's question being resolved.
For the validation layer, the article on guardrails for AI agents shows how to check input, output and action. Anthropic's engineering writing on building effective agents also supports the choice to prefer simple, predictable flows over open-ended autonomous agents when the path is already known.
Audio and image messages deserve an explicit decision. If the flow does not handle those types, the right response is to ask the customer to write or to forward the conversation to a person, rather than letting the model guess. If it does handle them, you need to know where the content goes and how it is stored.
What should you log for each conversation?
The n8n execution history helps with debugging, but it does not replace a support record. It can be purged, it is not designed for business queries and it mixes technical data with personal data. Create your own table (a structured spreadsheet, a relational database or the CRM, depending on the company's maturity) and record, for each message:
- conversation ID and message ID
- time received and time answered
- type and summary of the content received
- decision made (answered, asked for clarification, handed off) and the reason
- version of the prompt and knowledge base used
- reply sent and delivery result
- who took over, when there was a handoff, and the outcome
This record serves three purposes: investigating a wrong answer, adjusting the flow with evidence and, if needed, demonstrating how data was handled. From an LGPD standpoint, define the purpose, keep the minimum necessary and set a retention period. If your model provider processes data outside Brazil, the article on international data transfer under LGPD when using AI providers explains what to check. For official guidance, the starting point is the ANPD website.
It is also good practice to mask what the AI does not need to see, such as personal ID numbers and payment data, before sending text to the model.
When and how should you hand off to a person?
Handoff is what makes the flow safe, so it should have written rules, not just the model's impression that the conversation is getting difficult. Objective triggers that tend to work:
- the customer explicitly asks for an agent
- complaint, billing, cancellation, legal or health topics
- low confidence in the answer, or a question not covered by approved documentation
- the same question repeated after one or two replies
- technical failure in sending or in the model
- signs of frustration, urgency or a threat of a public complaint
When a trigger fires, n8n has to do four things in sequence. First, mark the conversation as under human responsibility, with a flag per phone number or conversation, so new messages no longer go through the AI. Second, notify the team in the channel where they already work, with a short summary: who the customer is, what they asked, what the AI already answered and why it handed off. Third, tell the customer honestly that a person will continue, with a response expectation the company can meet. Fourth, define who returns the conversation to the AI, if that makes sense.
Timing matters. Outside business hours, the message to the customer should say when they will hear back, and the queue must be visible the next morning. The article on after-hours customer service with AI covers this design in more detail. Also remember that the Cloud API limits free-form replies to a window after the customer's last message. Company-initiated contact depends on approved templates and consent, which is the subject of the guide to WhatsApp outbound messages, templates and opt-in.
How do you go live with a controlled pilot?
The method we apply follows four moves: map, limit, pilot and hand over. Mapping means describing current support and measuring a baseline. Limiting means deciding which data and actions the flow may touch. Piloting means running one real flow, with logging and an agreed metric. Handing over means defining how conversations pass to people and how the operation is delivered to the team, who then decide whether to expand, adjust or stop.
A pilot plan in steps:
- Step 1: pick a single type of request, such as questions about hours, order status or required documents.
- Step 2: pull the latest conversations of that type, group the questions and write the approved answers.
- Step 3: define the success metric before you start, for example the share of questions resolved without intervention and the quality as perceived by the team.
- Step 4: configure the Cloud API, webhook, validation and deduplication, and test with internal numbers.
- Step 5: add the AI step with a limited knowledge base and structured output.
- Step 6: implement logging and handoff, and rehearse the triggers with deliberately difficult conversations.
- Step 7: release to a small group of customers, review conversations daily during the first week and adjust.
- Step 8: gather the team, compare with the baseline and decide whether to expand, adjust or stop.
Illustrative scenario: a small clinic wants to reduce repetitive messages about exam preparation. The flow receives the question, identifies the exam by rule and by AI, replies with the preparation text approved by the clinical lead and logs the conversation. If the customer mentions a symptom, a medication or a clinical doubt, the flow does not answer: it hands off to reception with a summary and tells the customer. The AI never interprets results or advises on treatment. The value is in having the limit defined beforehand, not in how much the model can say.
To compare with other support contexts, the guide on how to integrate AI into your company's WhatsApp widens the picture, and the article on AI customer support: what to automate and what to keep human helps you decide what to automate and what to keep with people.
Frequently asked questions
Do I need code to use n8n with the WhatsApp Cloud API?
Much of the flow can be built with ready-made nodes, such as the WhatsApp trigger, the send node, filters and tables. Code usually enters at two points: validating the webhook signature and normalizing the payload. Both are small and worth the effort.
Can the AI answer any customer question on its own?
It is not recommended. It should answer only what the approved knowledge base covers and within a defined scope, and hand off the rest. Questions involving money, health, contracts or complaints should go to a person, and the decision to hand off should come from written rules, not only from the model.
Is the n8n history enough as a support record?
Usually not. It serves technical debugging, can be deleted and does not organize information for the team to query. Keep your own table with the decision, reason, prompt version and outcome, and set a retention period according to the purpose and LGPD.
How do I stop the flow from replying twice to the same message?
Use the message ID as a deduplication key and confirm the webhook receipt before calling the model. Record the ID as soon as processing starts, so a resent event is discarded. This also reduces the risk of double replies when the model is slow.