A minimalistic AI-powered WhatsApp message-sending agent that understands natural language commands using Google's Gemini API and automates WhatsApp Web using Selenium.
- 🧠 Natural language understanding with Gemini API
- 📱 Automated WhatsApp Web interaction via Selenium
- 🔄 Interactive command loop
- ✅ Message confirmation before sending
- 💾 Session persistence (stays logged in)
- Python 3.8+
- Google Chrome browser
- ChromeDriver (automatically managed by Selenium)
- Gemini API Key (Get it here)
git clone https://github.com/RiyanBhargava/acm-whatsapp-ai-agent.git
cd acm-whatsapp-ai-agentpython -m venv .venvWindows:
.venv\Scripts\ActivateMac/Linux:
source .venv/bin/activateNote: You should see
(.venv)at the start of your prompt
pip install -r requirements.txtCopy the example file:
copy .env.example .envEdit .env and add your Gemini API key:
GEMINI_API_KEY=your_actual_api_key_hereGet your API key from: https://makersuite.google.com/app/apikey
python main.py- Chrome will open with WhatsApp Web
- Scan the QR code with your phone to login
- Once logged in, the session is saved (no need to scan again)
Type natural language commands:
Example 1:
You: send message to mom saying hi i am out
Processing command...
→ Contact: mom
→ Message: hi i am out
Send this message? (y/n): y
Searching for contact: mom
Sending message: hi i am out
✓ Message sent successfully!
Example 2:
You: tell John I'll meet him at 6 near the metro station
Example 3:
You: message Sarah that the meeting is postponed to tomorrow
Type any of these:
quitexitq- Press
Ctrl+C
- User Input: You type a natural language command
- Gemini Processing: The command is sent to Gemini API which extracts:
- Contact name
- Message content
- Confirmation: The agent shows what it understood and asks for confirmation
- Selenium Automation: If confirmed, Selenium automates WhatsApp Web to send the message
The agent understands various natural language patterns:
- "send message to [contact] saying [message]"
- "tell [contact] [message]"
- "message [contact] that [message]"
- "send to [contact] saying [message]"
The agent saves Chrome session data in ./chrome_profile to keep you logged in.
Edit gemini_parser.py to modify the system prompt and change how commands are interpreted.
"GEMINI_API_KEY not found"
- Make sure you created the
.envfile with your API key
WhatsApp won't load
- Ensure you have a stable internet connection
- Try clearing the
chrome_profilefolder and logging in again
Contact not found
- Make sure the contact name matches exactly as saved in WhatsApp
- The contact must exist in your WhatsApp contact list
ChromeDriver issues
- Selenium should automatically download the correct ChromeDriver
- Make sure Chrome browser is installed and up to date
ai-agent-whatsapp/
├── main.py # Main application entry point
├── gemini_parser.py # Gemini API integration for NLP
├── whatsapp_automation.py # Selenium automation for WhatsApp
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .env # Your actual API key (create this)
└── README.md # This file
- Never commit your
.envfile with the API key - The
.gitignorefile excludes sensitive files automatically - Chrome profile data is stored locally and not shared
This project is free to use for personal and educational purposes.
Feel free to fork, modify, and improve this project!
Made with ❤️ using Gemini API and Selenium