Skip to content

Sonff/watsapp-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp AI Chatbot (shayan_your_friendly_bot)

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.


Features

  • 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.png file 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).

Prerequisites

  • Node.js (v18 or higher recommended)
  • NPM (Node Package Manager)
  • A WhatsApp Account (and a mobile phone to scan the QR code)

Setup & Installation

1. Clone or copy files

Ensure you have the following files in your workspace directory:

  • package.json
  • index.js
  • .env
  • .gitignore

2. Install dependencies

Run the following command to install the required packages (this will also download Chromium for Puppeteer):

npm install

3. Get a Groq API Key (Recommended - 14,400 messages/day)

  1. Go to console.groq.com.
  2. Sign up with your Google account or email (completely free).
  3. Click on API Keys in the left menu, then click Create API Key.
  4. Copy the key starting with gsk_.

4. Get a Google Gemini API Key (Optional Fallback)

  1. Go to Google AI Studio.
  2. Click on the Create API key button.
  3. Copy the generated API key starting with AIzaSy.

5. Configure Environment Variables

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_here

Running the Bot & Linking WhatsApp

1. Start the Bot in Development Mode (with auto-reload)

To run the bot in development mode where it auto-restarts on any file change:

npm run dev

2. Start the Bot in Production Mode

To run the bot in production mode:

npm start

3. Scan the QR Code to Link Device

  1. Once started, a login QR code will print in the console terminal.
  2. Additionally, a clean scanable image file named qr.png will be saved in your project root.
  3. Open your mobile phone's WhatsApp.
  4. Go to Settings -> Linked Devices -> Link a Device.
  5. Scan the QR code from qr.png (or the terminal).
  6. Once connected, qr.png will be deleted automatically and the console will log: 🚀 WhatsApp Bot is ready and listening for messages!

Cloud Hosting Notes

If you plan to deploy the bot 24/7 on a cloud platform (like Render or Railway):

  1. 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.
  2. Puppeteer (Chromium) Dependencies: Cloud platforms require system-level dependencies for Chromium to run Puppeteer headless. Use a custom Dockerfile or buildpack configured for Puppeteer.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors