WhatsApp + OpenAI: instant replies with chat memory
Your WhatsApp inbox gets busy, then messy. Someone asks about shipping, another wants a refund, a third follows up on yesterday’s question, and suddenly you’re scrolling old chats and copying the same answers again.
This hits support leads first, but e-commerce owners and small agency teams feel it too. WhatsApp AI replies shouldn’t sound random, forget context, or go silent when you’re away.
This workflow turns WhatsApp messages into fast, consistent replies powered by OpenAI, with chat memory stored in Postgres/Supabase so follow-ups stay coherent. You’ll see what it does, how it behaves inside Meta’s 24-hour window, and what you need to run it.
How This Automation Works
The full n8n workflow, from trigger to final output:
n8n Workflow Template: WhatsApp + OpenAI: instant replies with chat memory
flowchart LR
subgraph sg0["WhatsApp Flow"]
direction LR
n0@{ icon: "mdi:robot", form: "rounded", label: "AI Agent", pos: "b", h: 48 }
n1@{ icon: "mdi:wrench", form: "rounded", label: "list_links", pos: "b", h: 48 }
n2@{ icon: "mdi:brain", form: "rounded", label: "OpenAI Chat Model", pos: "b", h: 48 }
n3["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/whatsapp.svg' width='40' height='40' /></div><br/>WhatsApp Trigger"]
n4["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>cleanAnswer"]
n5@{ icon: "mdi:wrench", form: "rounded", label: "get_page", pos: "b", h: 48 }
n6["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>24-hour window check"]
n7@{ icon: "mdi:swap-horizontal", form: "rounded", label: "If", pos: "b", h: 48 }
n8["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/whatsapp.svg' width='40' height='40' /></div><br/>Send Pre-approved Template M.."]
n9["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/whatsapp.svg' width='40' height='40' /></div><br/>Send AI Agent's Answer"]
n10@{ icon: "mdi:memory", form: "rounded", label: "Postgres Users Memory", pos: "b", h: 48 }
n7 --> n4
n7 --> n8
n0 --> n6
n5 -.-> n0
n1 -.-> n0
n4 --> n9
n3 --> n0
n2 -.-> n0
n6 --> n7
n10 -.-> n0
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n3 trigger
class n0 ai
class n2 aiModel
class n1,n5 ai
class n10 ai
class n7 decision
class n4,n6 code
classDef customIcon fill:none,stroke:none
class n3,n4,n6,n8,n9 customIcon
The Problem: WhatsApp Support Breaks Under Volume
WhatsApp is great for customers because it’s quick. For you, it becomes a never-ending stream of “just one more question.” The hard part isn’t answering once. It’s answering consistently across multiple people, across multiple days, with the right tone, without missing a message when the team is pulled into something else. And when a customer follows up, you have to remember what you already told them, or you risk contradicting yourself. That’s how simple support turns into churn, refunds, and stress.
The friction compounds. A few tiny delays and inconsistencies create a support experience that feels sloppy, even if your product is excellent.
- You end up retyping the same “shipping times” and “return policy” answers all week.
- Follow-up questions get confusing because nobody remembers what was promised in the last message.
- If your website changes, your canned replies go out of date fast and you don’t notice until a customer complains.
- After-hours messages pile up, so your team starts the next morning already behind.
The Solution: Real-Time WhatsApp Replies, Powered by OpenAI + Memory
This n8n workflow listens for new WhatsApp messages, cleans up the incoming text, and sends it to an OpenAI-powered conversational agent. When the agent needs information, it can fetch live page content from your site (think policies, FAQs, product pages) instead of relying on outdated snippets. Each turn of the conversation is stored in Postgres/Supabase, then replayed back into the next prompt, so the assistant remembers context and doesn’t “reset” every time. Finally, it replies inside WhatsApp automatically, using a free-form message when it’s allowed, and switching to a reopen template when Meta requires it. The result feels like a calm, consistent support rep that never loses the thread.
The workflow starts when a customer messages your WhatsApp Business number. OpenAI generates a reply with help from your live website content and the stored conversation memory. Then n8n sends the right type of WhatsApp response based on the 24-hour service window, so you stay compliant without thinking about it.
What You Get: Automation vs. Results
| What This Workflow Automates | Results You’ll Get |
|---|---|
|
|
Example: What This Looks Like
Say you get about 30 WhatsApp questions a day. Manually, even a “quick” reply is usually 5 minutes once you’ve checked the order status, copied policy wording, and re-read earlier messages, which is about 2.5 hours daily. With this workflow, the customer message triggers instantly, the agent pulls the right info from your site, and the reply goes out automatically (you mostly spend time only on edge cases). Even if you still review a handful of chats, you’re typically getting around 2 hours back each day.
What You’ll Need
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- WhatsApp Business Cloud to receive and send WhatsApp messages.
- OpenAI for generating accurate, natural replies.
- Supabase or Postgres for chat memory storage and replay.
- Meta permanent access token (get it from Meta Developers → WhatsApp).
- OpenAI API key (get it from the OpenAI dashboard).
- Supabase/Postgres connection string (get it from your project settings).
Skill level: Intermediate. You’ll paste API keys, set a domain variable, and confirm your WhatsApp webhook is pointing to the right n8n URL.
Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).
How It Works
A customer messages your WhatsApp number. The WhatsApp Business Cloud trigger catches the inbound message instantly and passes the text into the workflow.
The message is cleaned up and prepared for the assistant. n8n normalizes the response text so the agent receives consistent input, even if customers send emojis, line breaks, or short fragments.
OpenAI generates a reply with live context. The conversational agent can fetch relevant page text from your website using HTTP requests (policies, FAQs, product details), then combines that with stored chat memory from Postgres/Supabase so it answers like it’s continuing a real conversation.
The workflow sends the correct WhatsApp response type. It checks the 24-hour customer care window, then either sends a free-form reply or a reopen template if the window has expired.
You can easily modify the domain being crawled and the system prompt tone based on your needs. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the WhatsApp Incoming Trigger
This workflow starts when a new WhatsApp message arrives, using the configured trigger.
- Add the WhatsApp Incoming Trigger node to your canvas.
- Set Updates to
messages. - Credential Required: Connect your whatsAppTriggerApi credentials.
Step 2: Connect AI Services and Memory
The AI agent uses OpenAI for responses and Postgres for conversation memory.
- Open OpenAI Chat Engine and select the model
gpt-4o-mini. - Credential Required: Connect your openAiApi credentials in OpenAI Chat Engine.
- Open Postgres Chat Memory and set Table Name to
message_history. - Set Session Key to
={{ $json.contacts[0].wa_id }}and Session ID Type tocustomKey. - Credential Required: Connect your postgres credentials in Postgres Chat Memory.
OpenAI Chat Engine is connected as the language model for Conversational Agent—ensure credentials are added to OpenAI Chat Engine, not the agent.
Step 3: Set Up the Conversational Agent and Tools
The agent receives WhatsApp text, uses tools to read your website, and prepares answers.
- Configure Conversational Agent with Text set to
={{ $json.messages[0].text.body }}. - In Conversational Agent options, set System Message to the full instruction block provided in the node, including your company name and domain.
- Enable Return Intermediate Steps and keep Has Output Parser enabled.
- Configure Link Lister Tool with URL
https://lemolex.app.n8n.cloud/webhook/list-linksand body fieldsurlandauth-token(set[CONFIGURE_YOUR_TOKEN]). - Configure Page Text Fetcher with URL
https://lemolex.app.n8n.cloud/webhook/get_textand body fieldsurlandauth-token(set[CONFIGURE_YOUR_TOKEN]).
Link Lister Tool, Page Text Fetcher, and Postgres Chat Memory are connected as AI tools/memory for Conversational Agent—add any required credentials to their parent services, not to the tools themselves.
Step 4: Apply Conversation Window Logic and Response Cleanup
Responses are routed based on the 24-hour WhatsApp messaging window and cleaned for formatting.
- In Conversation Window Check, keep the provided JavaScript to compute
withinWindowfrom WhatsApp Incoming Trigger timestamps. - Configure Window Conditional to evaluate
={{ $json.withinWindow }}as true. - In Normalize Response Text, keep the JavaScript that removes formatting and converts markdown links to plain text.
Step 5: Configure WhatsApp Responses
If the user is within the 24-hour window, the agent reply is sent; otherwise a template is used to reopen the session.
- In Dispatch Agent Reply, set Operation to
sendand Text Body to={{ $json.answer }}. - Set Recipient Phone Number to
={{ $('WhatsApp Incoming Trigger').item.json.contacts[0].wa_id }}in both Dispatch Agent Reply and Send Reopen Template. - Set Phone Number ID to your WhatsApp business number ID in both nodes (replace
[YOUR_ID]). - Credential Required: Connect your whatsAppApi credentials in both Dispatch Agent Reply and Send Reopen Template.
- Set Template in Send Reopen Template to
hello_world|en_USor your approved template.
⚠️ Common Pitfall: Leaving [YOUR_ID] in Phone Number ID will cause WhatsApp send failures.
Step 6: Test & Activate Your Workflow
Run a manual test to confirm the agent can read the message, search the website, and send a WhatsApp reply.
- Click Execute Workflow and send a WhatsApp message to your business number.
- Verify Conversational Agent outputs a response and Normalize Response Text returns
answer. - Confirm either Dispatch Agent Reply or Send Reopen Template sends a message based on the 24-hour window.
- When results are correct, toggle the workflow to Active for production use.
Common Gotchas
- WhatsApp Business Cloud credentials can expire or lack the right permissions. If things break, check your Meta Developers dashboard token status and webhook subscriptions first.
- If your workflow relies on external page fetching, response times vary and some sites block aggressive crawling. If the agent suddenly answers vaguely, check the HTTP Request nodes for 403/timeout errors and reduce the pages you fetch.
- Default AI prompts are honestly too generic for support. Add your brand voice, refund rules, and escalation behavior in the system prompt early or you’ll be editing replies forever.
Frequently Asked Questions
About 15 minutes if your API keys are ready.
No. You’ll mostly paste credentials and adjust a prompt. The only “code” parts are already in the workflow.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs (often a few cents per conversation) plus your database hosting if you’re not on a free tier.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
Yes, but you’ll swap the WhatsApp trigger and reply nodes. Keep the Conversational Agent, OpenAI Chat Model, and Postgres Chat Memory as-is, then replace “WhatsApp Incoming Trigger” with a Telegram trigger and replace “Dispatch Agent Reply” with a Telegram send-message node. Common tweaks include changing the system prompt tone, limiting which website pages get fetched, and adding an escalation branch to a human inbox.
Most of the time it’s an expired or replaced permanent token in your Meta Developers account. Update the token in n8n, then confirm the webhook is still subscribed to the right WhatsApp events. Also check that your phone number is connected to the correct app, because it’s easy to test with one number and deploy with another. If you’re sending messages outside the 24-hour window, your free-form replies can be rejected, which makes it look like the integration is “down” when it’s really a policy rule.
If you self-host, there’s no fixed execution limit (it depends on your server). On n8n Cloud, capacity depends on your plan and task usage, but most small teams can handle a normal support inbox comfortably. The bigger scaling constraint is usually WhatsApp rate limits and how much website content you’re fetching per message.
Often, yes. This workflow benefits from branching logic (the 24-hour window check), tool-style HTTP fetching to pull live site text, and true chat memory in Postgres, which is awkward to build in simpler “two-step” tools. n8n also gives you a clean path to self-hosting if your message volume grows, which can matter when you don’t want every extra conversation to increase your bill. That said, Zapier or Make can be fine for basic autoresponders with no memory and no window compliance logic. If you want help choosing, Talk to an automation expert.
Set it up once and your WhatsApp inbox stops being a fire drill. The workflow handles the repetitive support questions, and your team can focus on the few conversations that actually need a human.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.