This project is a lightweight conversational AI agent built in n8n, powered by OpenRouter's Gemini 2.5 Pro model.
It receives WhatsApp messages via webhook, processes them with an AI model, and responds in real-time.
🔧 Ideal for building WhatsApp bots, virtual companions, or basic assistants without writing a backend server.
- ✅ Accepts incoming WhatsApp messages (via POST request)
- 🧠 Extracts the message content and sender
- 🗣 Uses Gemini 2.5 Pro (via OpenRouter) to generate responses
- 🔁 Sends the AI-generated message back through the webhook
You can run n8n locally using Docker with persistent data by mounting your .n8n directory.
docker run -it --rm -p 5678:5678 -v C:\Users\gamin\.n8n:/home/node/.n8n n8nio/n8n **add your path🚀 Access the Editor
http://localhost:5678-
Webhook Node (
/webhook/whatsapp)- Receives POST request from your WhatsApp provider (like Meta, Twilio, or Baileys)
- Payload contains message content (
body) and sender info (from)
-
Extract Message
- A function node that pulls out:
message.bodymessage.from
- A function node that pulls out:
-
Basic LLM Chain
- Uses a predefined instruction:
"You are a helpful AI companion" - Sends message text to Gemini 2.5 via the next node
- Uses a predefined instruction:
-
OpenRouter Chat Model
- Gemini 2.5 Pro (via OpenRouter)
- Processes and replies with conversational text
-
Return AI Reply
- Captures AI output and formats it into a response object
-
Respond to Webhook
- Sends the response back to your WhatsApp bridge (or direct client)
This is a local WhatsApp chatbot built using Node.js It connects to WhatsApp Web via a QR code and responds with AI-generated messages using OpenAI or OpenRouter.
git clone https://github.com/Varadscript/whatsapp-ai-agent.git
cd whatsapp-ai-agent/WhatsApp-Bot- Install Dependencies
npm install🚀 Run the WhatsApp Bot
node bot.jsnode bot.js ✅ First-Time Setup When you run the bot for the first time, it will open a QR code in your terminal.
📱 Scan the QR code using your WhatsApp mobile app:
Go to WhatsApp > Linked Devices > Link a Device
Once scanned, the session will be saved inside the tokens/ folder — no need to scan again next time.
🤖 AI Integration The AI_Bot.json file contains the AI prompt or personality config
Make sure your bot.js is connected to:
OpenAI API key OR
OpenRouter API key
🧪 Example Message Flow User sends: “Hi, who are you?”
Bot replies: “I'm your friendly AI assistant. How can I help you today?”
