A powerful, beginner-friendly WhatsApp AI Chatbot built with Node.js, the whatsapp-web.js library, and dual AI engine support: Groq API (Llama 3.3) and Google Gemini API (gemini-2.0-flash-lite).
The bot acts as a warm, friendly conversational assistant. It can chat, answer questions, explain code, write stories, and translate languages, and it understands almost every global language.
- Dual AI Engine Support:
- Groq Llama 3.3 (Primary): Extremely fast, intelligent, and comes with a massive free tier of 14,400 messages per day!
- Google Gemini (Secondary Fallback): Auto-falls back to Gemini if Groq encounters issues or rate limits.
- Multilingual Support: Converses fluently in Hindi, Urdu, English, Spanish, Arabic, and dozens of other languages.
- Warm & Friendly Persona: Custom system prompts instruct the AI to behave as a friendly companion.
- Simulated Typing Status: Simulates typing indicators (
typing...) under the bot's contact name before responding to mimic human behavior. - Simple Image QR Login: Generates a clean, scanable
qr.pngfile directly in the root directory for a hassle-free scanning experience inside the IDE. - Session Persistence: Saves the session state locally under
.wwebjs_auth/so you only have to scan the QR code once. - Robust Redundancy: If both AI keys are missing, the bot falls back gracefully to a friendly static echo bot instead of crashing.
- Graceful Shutdown: Cleans up and stops the browser instance gracefully on process termination signals (
SIGINT,SIGTERM).
- Node.js (v18 or higher recommended)
- NPM (Node Package Manager)
- A WhatsApp Account (and a mobile phone to scan the QR code)
Ensure you have the following files in your workspace directory:
package.jsonindex.js.env.gitignore
Run the following command to install the required packages (this will also download Chromium for Puppeteer):
npm install- Go to console.groq.com.
- Sign up with your Google account or email (completely free).
- Click on API Keys in the left menu, then click Create API Key.
- Copy the key starting with
gsk_.
- Go to Google AI Studio.
- Click on the Create API key button.
- Copy the generated API key starting with
AIzaSy.
Open the .env file in the root of the project and populate your keys:
GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_hereTo run the bot in development mode where it auto-restarts on any file change:
npm run devTo run the bot in production mode:
npm start- Once started, a login QR code will print in the console terminal.
- Additionally, a clean scanable image file named
qr.pngwill be saved in your project root. - Open your mobile phone's WhatsApp.
- Go to Settings -> Linked Devices -> Link a Device.
- Scan the QR code from
qr.png(or the terminal). - Once connected,
qr.pngwill be deleted automatically and the console will log:🚀 WhatsApp Bot is ready and listening for messages!
If you plan to deploy the bot 24/7 on a cloud platform (like Render or Railway):
- Volume Mounts: Make sure to attach a persistent volume/disk to the directory
.wwebjs_auth/so the logged-in session remains saved across container redeployments and restarts. - Puppeteer (Chromium) Dependencies: Cloud platforms require system-level dependencies for Chromium to run Puppeteer headless. Use a custom Dockerfile or buildpack configured for Puppeteer.