An AI-powered WhatsApp auto-reply bot built with Python, Playwright, and Groq AI.
The project is being developed step-by-step to understand how browser automation, message processing, AI APIs, and project architecture work together.
The current version can:
✅ Open WhatsApp Web using Playwright
✅ Maintain a persistent WhatsApp session
✅ Read messages from the currently opened chat
✅ Extract message metadata and text
✅ Identify the latest message
✅ Ignore messages that should not receive a reply
✅ Generate an AI response using Groq
✅ Maintain conversation history for AI responses
✅ Send the generated response back to WhatsApp
The following features are still under development:
- Automatically selecting chats
- Continuously monitoring for new messages
- Preventing duplicate replies
- Better error handling
- Logging and reliability improvements
Start ↓ 🌐 Open WhatsApp Web ↓ 💬 Select / Open Chat ↓ 📥 Read Messages ↓ 🔎 Find Latest Message ↓ 🧠 Reply Logic ↓ ❓ Should Reply? ↓ 🤖 Groq AI ↓ ✍️ Generate Response ↓ 📤 Send Response
ai-auto-reply-bot/ │ ├── 01_basic_chatbot/ │ ├── chatbot.py │ └── README.md │ ├── bot/ │ ├── init.py │ ├── config.py │ ├── groq_api.py │ ├── reply_logic.py │ └── whatsapp.py │ ├── tools/ │ ├── .env ├── .gitignore ├── main.py └── README.md
- 🐍 Python
- 🎭 Playwright
- 🤖 Groq API
- 🔐 python-dotenv
- 📋 Pyperclip
- 🌿 Git
- 🐙 GitHub
git clone https://github.com/Luckyy05/Ai-auto-reply-bot.git cd Ai-auto-reply-bot
python -m venv .venv
Activate it on Windows:
.venv\Scripts\Activate.ps1
pip install playwright groq python-dotenv pyperclip
Install the Playwright browser:
playwright install chromium
Create a .env file in the project root:
GROQ_API_KEY=your_api_key_here
Replace your_api_key_here with your actual Groq API key.
Do not commit the .env file to GitHub.
The bot uses a persistent Playwright browser profile.
The session is stored locally in:
whatsapp_profile/
On the first run, you may need to scan the WhatsApp Web QR code.
After that, the saved session can be reused.
Do not commit whatsapp_profile/ to GitHub.
Run:
python main.py
The bot will:
- Open WhatsApp Web.
- Reuse the saved WhatsApp session if available.
- Wait for you to open the desired chat.
- Read the latest message.
- Decide whether a reply is needed.
- Generate a response using Groq AI.
- Send the response to WhatsApp.
- Close the browser.
The main entry point of the project.
It is responsible for connecting all components together and controlling the overall flow.
Handles WhatsApp Web automation using Playwright.
Responsibilities include:
- Starting WhatsApp Web
- Maintaining the browser session
- Reading messages
- Finding the latest message
- Sending messages
Contains the logic that decides whether the bot should reply.
For example, it can ignore:
- Messages sent by the bot's own account
- Empty messages
- Very long messages
- Common messages such as
ok,okay,good morning, andgood night
Handles communication with the Groq API.
It is responsible for:
- Sending user messages to the AI
- Generating responses
- Maintaining conversation history
Contains project configuration such as WhatsApp UI-related settings and other constants used by the project.
This project is also being used as a practical Python project to learn:
- Python project structure
- Modules and packages
- APIs
- Environment variables
- Browser automation
- Playwright
- AI integration
- Conversation history
- Git and GitHub
- Debugging and incremental development
The project currently requires the user to manually open/select the WhatsApp chat before the bot processes the message.
The WhatsApp session is stored locally using a persistent Playwright profile so that WhatsApp Web does not need to be logged in every time.
The local session folder should never be committed to GitHub.
This project is intended for learning and experimentation with Python, browser automation, and AI APIs.
Use WhatsApp automation responsibly and in accordance with WhatsApp's terms and applicable policies.
.env .venv/ pycache/ *.pyc whatsapp_profile/
Delete these files:
bot/gemini_api.py tools/get_position.py tools/check_whatsapp_ui.py
For whatsapp_profile:
DO NOT delete the local folder from your PC.
Only remove it from Git tracking:
git rm -r --cached whatsapp_profile
First check the current status:
git status
Check the changes:
git diff
Check for formatting errors:
git diff --check
Stage the changes:
git add README.md .gitignore bot tools
Then commit:
git commit -m "chore: clean project and update README"
Finally push:
git push
Keep whatsapp_profile/ on your computer.
It contains the saved WhatsApp Web session.
It should be ignored by Git and should NOT be uploaded to GitHub.