An open API service indexing awesome lists of open source software.

https://github.com/codedbyasim/whatsapp-bot

A smart WhatsApp bot with tone-aware replies in Roman Urdu, group management tools, and LLM-powered features via Google Gemini API + Flask.
https://github.com/codedbyasim/whatsapp-bot

chatbot flask gemini-api nodejs python whatsapp-bot

Last synced: 3 months ago
JSON representation

A smart WhatsApp bot with tone-aware replies in Roman Urdu, group management tools, and LLM-powered features via Google Gemini API + Flask.

Awesome Lists containing this project

README

          

# 🌟 Tone-Aware WhatsApp Bot πŸ€–

A **sophisticated WhatsApp bot** designed to enhance group interactions and automate tasks.
It features **tone-aware replies**, **Roman Urdu language generation**, **group management commands**, and integrates a **Python Flask server** for advanced Large Language Model (LLM) capabilities using **Google’s Gemini API**.

---

## ✨ Features

### 🎭 Tone & Fun

βœ” Tone-aware replies (funny, chill, serious) in Roman Urdu
βœ” `!joke` β†’ Sends a short joke
βœ” `!fact` β†’ Provides an interesting fact
βœ” `!roast @user` β†’ Light-hearted roast for a tagged user
βœ” `!quote` β†’ Motivational or funny quote

### πŸ‘₯ Group Management

βœ” `!tagall` or `!tag [message]` β†’ Tags all group members
βœ” `!spam [@user] "" ` β†’ Sends a message multiple times (max 20)
βœ” `Stop @[BotName]` β†’ Stops spam (only by initiator)

### πŸ›  Utilities

βœ” `!mood` β†’ Analyzes recent group messages & reports mood
βœ” `!news` β†’ Fetches & summarizes today’s top 5 news (Roman Urdu, News API key required)
βœ” `!help` β†’ Shows available commands

### 🌸 Auto Reactions

* Replies with 🌸 to "Good morning" and "Good night"
* Detects spam & roasts the sender

---

## πŸ—οΈ Architecture

**Hybrid setup:**

* **Node.js (main.js):** Handles WhatsApp communication, commands, and orchestrates requests
* **Python (hf_inference_server.py):** Runs a Flask server connected to **Google Gemini API** for LLM-powered tasks

---

## πŸš€ Quick Start

### 1. Clone Repository

```bash
git clone https://github.com/codedbyasim/WhatsApp-Bot
cd WhatsApp-Bot
```

### 2. Install Dependencies

**Node.js:**

```bash
npm install
```

**Python:**

```bash
pip install Flask requests python-dotenv
```

### 3. Configure Environment Variables

Create a file named `.env` in the project root:

```ini
FIREBASE_PROJECT_ID=
FIREBASE_CLIENT_EMAIL=
FIREBASE_PRIVATE_KEY_PATH=
FIREBASE_STORAGE_BUCKET=

BOT_ID="1234567874@s.whatsapp.net"

# Authorized WhatsApp IDs
REHAN_ID=69510287589385@lid
SAAD_ID=12345678902@s.whatsapp.net
ASIM_ID=1234567878@s.whatsapp.net

# Target group/contact JID
CODE_ON_REMOTEJ_ID=120363403535865809@g.us

# Servers & APIs
PYTHON_INFERENCE_URL=http://localhost:5000
GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
NEWS_API_KEY="YOUR_NEWS_API_KEY"
```

---

## πŸƒ Running the Bot

### Start Python Server

```bash
python hf_inference_server.py
```

(Starts Flask server on `http://localhost:5000`)

### Start Node.js Bot

```bash
node main.js
```

Scan the QR code in your terminal using **WhatsApp > Linked Devices**.
If successful, you’ll see:

```
WhatsApp connection opened successfully!
```

---

## πŸ’¬ Example Usage

* `!help`
* `!joke`
* `!roast @SomeUser`
* `!tagall "Meeting in 5 minutes!"`
* `Good morning` β†’ 🌸

---

## πŸ›  Troubleshooting

❌ **Unauthorized to use this command**
β†’ Ensure your WhatsApp ID is in `.env` under allowed users

❌ **Gemini API key is None**
β†’ Check `.env` and restart `hf_inference_server.py`

❌ **Bot looping on "Good morning"**
β†’ Update to latest `main.js` (bot ignores its own messages)

---

## 🀝 Contributing

Want to improve this bot? Fork the repo and submit a PR!
Some ideas for contributions:

* Add new fun commands (`!riddle`, `!shayari`)
* Add tone categories (angry, sarcastic, polite)
* Improve group management features

---

## πŸ“„ License

This project is licensed under the **ISC License**.