Skip to content

Repository files navigation

WhatsApp Autoreply Bot

A sophisticated WhatsApp automation bot that analyzes chat behavior and responds intelligently using OpenAI's GPT models.

Features

  • 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

Architecture

  • bot.py - Main bot logic with improved error handling and reliability
  • config.py - Configuration management system
  • logger.py - Comprehensive logging system
  • utils.py - Utility functions and helper classes
  • openai.py - OpenAI client configuration (secure, no hardcoded keys)
  • get_cursor.py - Utility for finding screen coordinates
  • requirements.txt - Python dependencies
  • .env.example - Environment variables template

Setup

  1. Install Dependencies:

    pip install -r requirements.txt
  2. Configure Environment:

    • Copy .env.example to .env
    • Set your OpenAI API key: OPENAI_API_KEY=your_key_here
    • Adjust other configuration values as needed
  3. Run the Bot:

    python bot.py

Configuration

The bot is highly configurable through environment variables:

  • OPENAI_API_KEY - Your OpenAI API key (required)
  • SENDER_NAME - Name of the sender to respond to
  • SCAN_INTERVAL - How often to check for new messages (seconds)
  • LOG_LEVEL - Logging level (INFO, DEBUG, etc.)
  • Screen coordinates for automation (configurable)

Security Improvements

  • ✅ API keys moved to environment variables
  • ✅ Comprehensive .gitignore for sensitive files
  • ✅ Input validation and sanitization
  • ✅ No hardcoded credentials

Reliability Improvements

  • ✅ Comprehensive error handling
  • ✅ Retry mechanisms for failed operations
  • ✅ Message deduplication
  • ✅ Graceful shutdown handling
  • ✅ Dynamic waiting instead of fixed delays

Recent Updates

  • 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

Usage Notes

  1. Ensure WhatsApp Web is open and the target chat is visible
  2. The bot uses screen coordinates - adjust them in the config if needed
  3. Use get_cursor.py to find the correct coordinates for your setup
  4. Monitor the logs for any issues or errors
  5. Press Ctrl+C to stop the bot gracefully

Requirements

  • Python 3.8+
  • WhatsApp Web running in a browser
  • OpenAI API key
  • Screen automation permissions

Disclaimer

This bot automates interactions with WhatsApp Web. Use responsibly and in accordance with WhatsApp's terms of service.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages