This project implements an AI-powered chatbot that interacts with WhatsApp Web. It uses OpenAI's GPT-3.5 model to generate responses and PyAutoGUI for automating interactions with the WhatsApp Web interface.
- OpenAI Chat Completion Script
- WhatsApp Web Automation Script
- Mouse Position Tracker
- Integrates with WhatsApp Web to read and respond to messages
- Uses OpenAI's GPT-3.5 model to generate context-aware responses
- Automates mouse and keyboard actions to interact with the WhatsApp Web interface
- Includes a utility to track mouse positions for setup
Before you begin, ensure you have met the following requirements:
- Python 3.6+
- pip (Python package manager)
- Google Chrome browser
- WhatsApp Web account
- OpenAI API key
- Clone this repository:
git clone https://github.com/yourusername/whatsapp-ai-chatbot.git
- Navigate to the project directory:
cd whatsapp-ai-chatbot
- Install the required packages:
pip install openai pyautogui pyperclip
- OpenAI API Key: Replace
"Your OpenAI API Key"
in both script files with your actual OpenAI API key. - Screen Coordinates: You may need to adjust the hardcoded screen coordinates in the WhatsApp Web automation script to match your screen resolution and browser window position.
- Open Google Chrome and log into WhatsApp Web.
- Ensure the WhatsApp Web window is positioned correctly on your screen.
- Run the WhatsApp Web automation script:
python whatsapp_automation.py
- The script will continuously monitor for new messages and respond when appropriate.
To help with setting up the correct screen coordinates, use the mouse position tracker:
- Run the mouse position tracker script:
python mouse_tracker.py
- Move your mouse to the desired positions on the WhatsApp Web interface and note the coordinates.
- Update the coordinates in the WhatsApp Web automation script accordingly.
- The script clicks on the Chrome icon to focus the WhatsApp Web window.
- It selects and copies the latest chat messages.
- The chat history is analyzed to determine if the last message is from the target sender.
- If so, the OpenAI API is used to generate a response based on the chat history.
- The response is pasted into the WhatsApp Web input field and sent.
- Modify the system prompts in the OpenAI API calls to change the bot's personality or behavior.
- Adjust the sleep times in the automation script to match your system's performance and network speed.
- openai: For interacting with OpenAI's GPT models.
- pyautogui: For automating mouse and keyboard actions.
- pyperclip: For cross-platform clipboard operations.
- If the automation is not clicking on the correct positions, re-run the mouse position tracker and update the coordinates.
- Ensure that your WhatsApp Web is logged in and the chat window is open before running the script.
- If you encounter OpenAI API errors, check your API key and quota.
This project automates interactions on WhatsApp Web and uses AI to generate responses. Please consider the following:
- Ensure you have permission from your chat partners to use an AI bot.
- Be aware of WhatsApp's terms of service regarding automated interactions.
- The AI may generate unexpected or inappropriate responses. Use with caution.
- This tool should not be used for spamming or any malicious purposes.
The authors are not responsible for any misuse of this software or violations of terms of service.
Contributions, issues, and feature requests are welcome. Feel free to check the issues page if you want to contribute.
This project is licensed under the MIT License - see the LICENSE file for details.