Are you looking to build your own WhatsApp chatbot with AI memory and smart replies using n8n? In this guide, you'll learn how to set up a working WhatsApp agent from scratch using the WhatsApp Business Cloud API, OpenRouter AI models, and n8n's low-code automation platform.
Whether you're aiming to respond to incoming messages, integrate tools like a calendar, or build a smart assistant with AI memory, this tutorial will walk you through it all.
What You'll Need Before Getting Started
Before we begin, make sure you've got the following:
- An n8n instance (self-hosted or cloud)
- Your WhatsApp Business Cloud credentials
- A verified Meta Developer Account
- An OpenRouter API key
If you don't have your WhatsApp or OpenRouter credentials set up yet, check the links in the description or read our dedicated guides:
Step 1 – Create the WhatsApp Trigger
Start your n8n workflow with a WhatsApp Trigger node. This listens for incoming messages.
- Select trigger type: message received
- Add your WhatsApp credentials (link to setup guide is in the description)
- Rename the node to Chat Received for later compatibility with memory
Step 2 – Add the AI Agent
Next, drag in your AI Agent node and connect it to the WhatsApp trigger. This agent will handle incoming messages and reply based on prompts and memory settings.
For now, set the basic system message like this:
Always reply kindly. Always end your messages with: "Greetings, Albin from Nibla."
You can tweak this to your brand voice or assistant tone.
Step 3 – Use OpenRouter Chat Model
Add the OpenRouter Chat Model node:
- Choose your model (e.g., gpt-3.5 or similar)
- Connect it to the AI Agent
- For memory, define it to remember 10 previous messages
This will help the bot keep context for natural conversation.
Step 4 – Add Memory Configuration
In your AI agent's memory field, paste the following shortcode to ensure it stores the sender's number:
{{ $('Chat Received').item.json.contacts[0].wa_id }}
Make sure your WhatsApp Trigger is named Chat Received. If it isn't, adjust the reference accordingly.
Step 5 – Send the AI's Reply Back
Now, add the Send Message & Wait for Response node. This will send the AI's reply back to the user via WhatsApp.
Configure it as follows:
- Operation: Send Message
- Phone Number ID: Use your test number from WhatsApp
- Recipient: The number used during testing
- Message Text: Output from AI Agent
You can leave the text field as an expression or dynamic reference. Then hit Save and Execute Workflow.
Step 6 – Test Your Agent
Try messaging "Hi" to your test WhatsApp number. Your workflow should:
- Trigger on your message
- Process it through the AI model
- Send back a response such as: "Hi there! How can I help you? Greetings, Albin from Nibla."
You can also test queries like:
- What is the weather in Amsterdam?
- What are best practices for SEO?
Even though the AI doesn't have real-time data access, it can provide helpful, context-aware responses.
Success! You now have a working WhatsApp AI agent using n8n and OpenRouter. With a bit more customization, you can connect this to calendar tools, booking systems, CRMs, or customer support workflows.
Final Thoughts
And that's it! You now have a working WhatsApp AI agent using n8n and OpenRouter. With a bit more customization, you can connect this to calendar tools, booking systems, CRMs, or customer support workflows.
If you found this tutorial helpful, don't forget to check out our other automation guides.
Got questions or ideas? Drop them below — I'd love to hear what you're building.
Helpful Links
Memory Shortcode Reference
For quick reference, here's the memory shortcode for your AI Agent:
{{ $('Chat Received').item.json.contacts[0].wa_id }}