A sophisticated WhatsApp automation bot that analyzes chat behavior and responds intelligently using OpenAI's GPT models.
- Intelligent Chat Analysis: Uses OpenAI to analyze chat patterns and respond as the user
- Robust Error Handling: Comprehensive error handling and retry mechanisms
- Security First: Environment variables for API keys, no hardcoded credentials
- Configurable: Easy configuration through environment variables and config files
- Logging: Detailed logging for monitoring and debugging
- Graceful Shutdown: Proper signal handling for clean exits
- Duplicate Prevention: Message deduplication to avoid repeated responses
- Dynamic Detection: Configurable screen coordinates for different setups
bot.py- Main bot logic with improved error handling and reliabilityconfig.py- Configuration management systemlogger.py- Comprehensive logging systemutils.py- Utility functions and helper classesopenai.py- OpenAI client configuration (secure, no hardcoded keys)get_cursor.py- Utility for finding screen coordinatesrequirements.txt- Python dependencies.env.example- Environment variables template
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
- Copy
.env.exampleto.env - Set your OpenAI API key:
OPENAI_API_KEY=your_key_here - Adjust other configuration values as needed
- Copy
-
Run the Bot:
python bot.py
The bot is highly configurable through environment variables:
OPENAI_API_KEY- Your OpenAI API key (required)SENDER_NAME- Name of the sender to respond toSCAN_INTERVAL- How often to check for new messages (seconds)LOG_LEVEL- Logging level (INFO, DEBUG, etc.)- Screen coordinates for automation (configurable)
- ✅ API keys moved to environment variables
- ✅ Comprehensive .gitignore for sensitive files
- ✅ Input validation and sanitization
- ✅ No hardcoded credentials
- ✅ Comprehensive error handling
- ✅ Retry mechanisms for failed operations
- ✅ Message deduplication
- ✅ Graceful shutdown handling
- ✅ Dynamic waiting instead of fixed delays
- Complete rewrite of bot logic with modern Python practices
- Added configuration management system
- Implemented comprehensive logging
- Enhanced security and error handling
- Added message tracking to prevent duplicates
- Improved OpenAI integration with proper error handling
- Ensure WhatsApp Web is open and the target chat is visible
- The bot uses screen coordinates - adjust them in the config if needed
- Use
get_cursor.pyto find the correct coordinates for your setup - Monitor the logs for any issues or errors
- Press Ctrl+C to stop the bot gracefully
- Python 3.8+
- WhatsApp Web running in a browser
- OpenAI API key
- Screen automation permissions
This bot automates interactions with WhatsApp Web. Use responsibly and in accordance with WhatsApp's terms of service.