Over 200 million businesses use WhatsApp to communicate with customers daily, yet most lack automation, AI, or 24/7 support. This presents a massive opportunity for businesses, agencies, and automation professionals. In this guide, I’ll walk you through building an AI-powered WhatsApp chatbot using n8n that handles everything from answering questions about hours and pricing to providing menus, locations, and appointment details in real time. We’ll connect WhatsApp to n8n, integrate a large language model, feed it a business’s website and documents, add guardrails for accuracy, and launch a robust support workflow that runs on autopilot. By the end, you’ll have a chatbot that converts inquiries into paying customers, even while you sleep. Let’s dive in!
Demo: Building the WhatsApp Chatbot
Before we start chatting, we need to build the knowledge base that powers the chatbot’s responses. For this demo, I’ll use the website of a hotel I stayed at last year, which offers various rooms, amenities, and events. We’ll scrape the website’s content, bundle it into a clean format, and use it to answer customer queries.
Step 1: Scraping the Website
To begin, we trigger the workflow by providing the hotel’s URL. This initiates the scraping process, which collects all relevant information from the website and formats it into a knowledge base. This knowledge base will power the chatbot’s responses, ensuring it provides accurate information about the hotel.
Step 2: Setting Up the AI Agent
Once the knowledge base is ready, we configure the AI agent. For this example, let’s assume a customer sends a message via WhatsApp:
“I’m arriving by ferry tomorrow. Can you help me figure out how to get to the hotel?”
We define a playbook for the AI agent (named Alex, our virtual concierge) to follow:
- Analyze the Request: The agent reads the user’s message to understand their query.
- Consult the Knowledge Base: To avoid hallucinations or incorrect information, the agent performs a targeted search within the hotel’s knowledge base before responding.
- Formulate the Response: The agent crafts an accurate, concise answer based on the knowledge base, adhering to predefined rules and constraints.
- Handle Missing Information: If the knowledge base lacks specific details, the agent is programmed to respond appropriately (e.g., suggesting the customer contact the hotel directly).
- Optional Personality Customization: You can define the agent’s tone (e.g., friendly, professional) and provide example responses to ensure consistency.
The knowledge base is embedded in the system prompt, separated by a triple-dash divider and an “encyclopedia” header. After scraping the website, we copy the output into the system prompt, allowing the AI to reference it instantly. This ensures all responses are grounded in accurate, up-to-date information.
Step 3: Configuring Memory for Personalized Responses
To make the chatbot more effective, we set up a memory node to retain context from previous messages sent by the same phone number. This prevents the AI from mixing up conversations or sharing details across different customers. Here’s how we configure it:
- Define a Memory Key: We use a prefix like “AI_hotel_agent” combined with the user’s phone number to create a unique identifier for each conversation.
- Increase Context Window: We set the context window to 30 messages to provide sufficient history for each phone number.
- Extract Phone Number: From the WhatsApp message trigger, we retrieve the phone number (e.g., under contacts[0].wa_id) to ensure responses are sent to the correct user.
This setup allows the chatbot to maintain separate conversation threads for multiple customers messaging simultaneously.
Step 4: Testing the Chatbot
With the workflow configured, we test the chatbot by sending the ferry question again. The agent, powered by the Gemini 2.5 Pro model, references the knowledge base and responds with:
Hello! We’re looking forward to welcoming you once you arrive at the ferry port in Positano. You have a couple of great options to get to the hotel:
- Complimentary Shuttle: We offer a free shuttle service for our guests that runs hourly. You can catch it from the Parco Tone stop in the center of Positano for a short 10-minute ride to the hotel.
- Water Taxi Service: Alternatively, you can book a water taxi for a scenic and direct trip to the hotel.
This response aligns with the hotel’s website information, confirming the shuttle and water taxi options. The answer is accurate and well-formatted, demonstrating the power of the knowledge base.
Step 5: Sending the Response
To send the reply back to the user, we configure the “send reply” node:
- Dynamic Phone Number: Instead of hardcoding a phone number, we retrieve the wa_id from the message trigger to ensure the response goes to the correct user.
- Response Text: We pull the AI agent’s output (the formatted answer) and send it as the reply.
After executing the step, the response is successfully delivered to the user’s WhatsApp, providing clear instructions for reaching the hotel.
Step 6: Refining the Response
While the response is functional, we can improve its formatting to meet WhatsApp’s messaging standards. This involves tweaking the system prompt to ensure concise, clear, and platform-appropriate replies. A few iterations may be needed to perfect the tone and structure.
Next Steps
This AI-powered WhatsApp chatbot is a game-changer for businesses. It automates customer support, provides accurate answers, and operates 24/7, turning inquiries into conversions effortlessly. To take it further:
- Join Our Community: Get this n8n automation template for free by joining our school community (link in the description). You can download the JSON output for this workflow and adapt it for your business.
- Stay Updated: Subscribe to our YouTube channel for more AI automation breakdowns. We’ll share workflows to make your business run 20 times more efficiently, just like this one.
- Explore More: Check out our other videos for additional automation strategies and tools.
By leveraging n8n and AI, you can transform how your business handles customer interactions. Start building your chatbot today and watch it drive results!