Building Your First WhatsApp Chatbot n8n Workflow Template

n8n workflow template · 18 nodes · WhatsApp Business Cloud

Building Your First WhatsApp Chatbot is a free n8n workflow template that starts from the WhatsApp Business Cloud Trigger node and works with WhatsApp Business Cloud and OpenAI. It has 18 nodes, 11 of them AI nodes (OpenAI Chat Model, Window Buffer Memory, Vector Store Question Answer Tool and OpenAI Embeddings). The notes inside the workflow say: “Join the Discord or ask in the Forum!” To run it, you add your own credentials for OpenAI API, Whats App Trigger API and WhatsApp Business Cloud API.

At a glance

Trigger
WhatsApp Business Cloud Trigger (WhatsApp Trigger)
Nodes
18
Apps
WhatsApp Business Cloud and OpenAI
AI nodes
11
Credentials
3 types
Category
RAG, documents and vector search

Apps and integrations

  • WhatsApp Business Cloud
  • OpenAI

Node types used

  • WhatsApp Business Cloud Trigger
  • OpenAI Chat Model
  • Window Buffer Memory
  • Vector Store Question Answer Tool
  • OpenAI Embeddings
  • Manual Trigger
  • Default Data Loader
  • Recursive Character Text Splitter
  • Extract from File
  • HTTP Request
  • WhatsApp Business Cloud
  • In-Memory Vector Store
  • Switch
  • AI Agent

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Try It Out!

This n8n template builds a simple WhatsApp chabot acting as a Sales Agent. The Agent is backed by a product catalog vector store to better answer user's questions.

  • This template is in 2 parts: creating the product catalog vector store and building the WhatsApp AI chatbot.
  • A product brochure is imported via HTTP request node and its text contents extracted.
  • The text contents are then uploaded to the in-memory vector store to build a knowledgebase for the chatbot.
  • A WhatsApp trigger is used to capture messages from customers where non-text messages are filtered out.
  • The customer's message is sent to the AI Agent which queries the product catalogue using the vector store tool.
  • The Agent's response is sent back to the user via the WhatsApp node.

Need Help?

Join the Discord or ask in the Forum!

1. Download Product Brochure PDF

Read more about the HTTP Request Tool

Import your marketing PDF document to build your vector store. This will be used as the knowledgebase by the Sales AI Agent.

For this demonstration, we'll use the HTTP request node to import the YAMAHA POWERED LOUDSPEAKERS 2024 brochure (Source) and an Extract from File node to extract the text contents.

You only have to run this part once!

Run this step to populate our product catalogue vector. Run again if you want to update the vector store with a new version.

2. Create Product Brochure Vector Store

Read more about the In-Memory Vector Store

Vector stores are powerful databases which serve the purpose of matching a user's questions to relevant parts of a document. By creating a vector store of our product catalog, we'll allow users to query using natural language.

To keep things simple, we'll use the In-memory Vector Store which comes built-in to n8n and doesn't require a separate service. For production deployments, I'd recommend replacing the in-memory vector store with either Qdrant or Pinecone.

Activate your workflow to use!

To start using the WhatsApp chatbot, you'll need to activate the workflow. If you are self-hosting ensure WhatsApp is able to connect to your server.

3a. Handle Unsupported Message Types

For non-text messages, we'll just reply with a simple message to inform the sender.

Want to handle all message types?

Check out my other WhatsApp template in my creator page!

4. Sales AI Agent Responds To Customers

Learn more about using AI Agents

n8n's AI agents are powerful nodes which make it incredibly easy to use state-of-the-art AI in your workflows. Not only do they have the ability to remember conversations per individual customer but also tap into resources such as our product catalogue vector store to pull factual information and data for every question.

In this demonstration, we use an AI agent which is directed to help the user navigate the product brochure. A Chat memory subnode is attached to identify and keep track of the customer session. A Vector store tool is added to allow the Agent to tap into the product catalogue knowledgebase we built earlier.

5. Repond to WhatsApp User

Learn more about the WhatsApp Node

The WhatsApp node is the go-to if you want to interact with WhatsApp users. With this node, you can send text, images, audio and video messages as well as use your WhatsApp message templates.

Here, we'll keep it simple by replying with a text message which is the output of the AI agent.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

3. Use the WhatsApp Trigger

Learn more about the WhatsApp Trigger

The WhatsApp Trigger allows you to receive incoming WhatsApp messages from customers. It requires a bit of setup so remember to follow the documentation carefully! Once ready however, it's quite easy to build powerful workflows which are easily accessible to users.

Note that WhatsApp can send many message types such as audio and video so in this demonstration, we'll filter them out and just accept the text messages.

Nodes in this workflow

The 18 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. WhatsApp Trigger (WhatsApp Business Cloud Trigger)
  2. OpenAI Chat Model (OpenAI Chat Model)
  3. Window Buffer Memory (Window Buffer Memory)
  4. Vector Store Tool (Vector Store Question Answer Tool)
  5. Embeddings OpenAI (OpenAI Embeddings)
  6. OpenAI Chat Model1 (OpenAI Chat Model)
  7. When clicking ‘Test workflow’ (Manual Trigger)
  8. Embeddings OpenAI1 (OpenAI Embeddings)
  9. Default Data Loader (Default Data Loader)
  10. Recursive Character Text Splitter (Recursive Character Text Splitter)
  11. Extract from File (Extract from File)
  12. get Product Brochure (HTTP Request)
  13. Reply To User (WhatsApp Business Cloud)
  14. Reply To User1 (WhatsApp Business Cloud)
  15. Product Catalogue (In-Memory Vector Store)
  16. Create Product Catalogue (In-Memory Vector Store)
  17. Handle Message Types (Switch)
  18. AI Sales Agent (AI Agent)

Credentials you need

  • OpenAI API – used by Embeddings OpenAI, Embeddings OpenAI1, OpenAI Chat Model and OpenAI Chat Model1
  • Whats App Trigger API – used by WhatsApp Trigger
  • WhatsApp Business Cloud API – used by Reply To User and Reply To User1

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us