Whatsapp Web Owner Activity Monitor
A Python-based monitoring system that tracks WhatsApp Web activity for the account user (the person who scans the QR code). Events can be sent to webhooks (N8N, etc.) or printed to console for local m
About the Project
A Python-based monitoring system that tracks WhatsApp Web activity for the account user (the person who scans the QR code). Events can be sent to webhooks (N8N, etc.) or printed to console for local monitoring.
ð¯ Features
The monitor detects and reports these events (via webhook or console):
1. ð Typing Activity
- Started Typing: Detects when the user starts typing a message
- Stopped Typing: Triggers after ~3 seconds of no typing activity
2. ð¤ Voice Recording
- Recording Started: Detects when the user starts recording a voice message
- Recording Stopped: Detects when recording ends
3. ð Connection Status
- Online: WhatsApp Web connects or connection is restored
- Lost: Connection is lost (internet disconnected, browser closed, tab closed, etc.)
4. ð Authentication Status
- QR Ready: QR code is displayed and user needs to scan to login
- Logged In: User successfully scanned QR code and logged in
4. ð¥ï¸ Flexible Output Modes
- Webhook Mode: Send events to N8N or any webhook endpoint
- Console Mode: Print events to terminal (no webhook required)
ð ï¸ Technical Stack
- Python 3.x - Core programming language
- Selenium WebDriver - Browser automation
- Chrome/Chromium - Headless browser (auto-configured)
- Requests - HTTP webhook calls
- ChromeDriver - Automatically downloaded and configured
ð Requirements
- Python 3.7 or higher
- Google Chrome or Chromium browser installed
- Internet connection
- N8N instance or any webhook endpoint (optional - can print to console instead)
ð Quick Start
Option 1: Automated Setup (Recommended)
Windows:
run.bat
Linux/Mac:
chmod +x run.sh ./run.sh
These scripts will automatically:
- Create a virtual environment
- Install all dependencies
- Check for .env configuration
- Start the monitor
Option 2: Manual Installation
1. Clone or Download
cd "WhatsApp Web Monitoring"
2. Create Virtual Environment (Recommended)
# Windows python -m venv venv venv\Scripts\activate # Linux/Mac python3 -m venv venv source venv/bin/activate
3. Install Dependencies
pip install -r requirements.txt
4. Configure Webhook URL (Optional)
If you want to send events to a webhook (N8N, etc.):
Option A: Using .env file (Recommended)
# Windows copy .env.example .env # Linux/Mac cp .env.example .env # Edit .env and set your webhook URL WEBHOOK_URL=https://your-n8n-instance.com/webhook/whatsapp-monitor
Option B: Edit config.py directly
Open config.py and modify:
WEBHOOK_URL = "https://your-n8n-instance.com/webhook/whatsapp-monitor"
If you skip this step: Events will be printed to the console instead of sent to a webhook. This is useful for testing or if you just want to monitor activity locally.
ð® Running the Monitor
Quick Start Scripts
Windows:
run.bat
Linux/Mac:
./run.sh
Manual Start
# Activate virtual environment first # Windows: venv\Scripts\activate # Linux/Mac: source venv/bin/activate python whatsapp_monitor.py
ð First Time Setup
-
Run the monitor:
# Using quick start script (recommended) run.bat # Windows ./run.sh # Linux/Mac # Or manually python whatsapp_monitor.py -
Scan QR Code:
- A Chrome window will open (or run in background if headless)
- Scan the QR code with your WhatsApp mobile app
- The session will be saved in
chrome_profile/for future runs
-
Monitor Running:
- Once logged in, the monitor starts automatically
- Events are sent to your webhook URL (if configured) or printed to console
Subsequent Runs
The monitor will use the saved session and start immediately without requiring QR code scan.
Console Mode (No Webhook)
If you don't configure a webhook URL, the monitor will run in console mode and print all events to the terminal:
python whatsapp_monitor.py
Example console output:
============================================================
ð¤ EVENT DETECTED:
Event: user_texting
Action: started
Timestamp: 1698062428915
DateTime: 2024-10-23T14:23:48
============================================================
To test console mode without running the full monitor:
python test_console_mode.py
ð¤ Webhook Payload Format
All events are sent as POST requests with JSON payload:
{ "event": "user_texting", "action": "started", "timestamp": 1698062428915, "datetime": "2024-10-23T14:23:48", "source": "whatsapp_monitor" }
Event Types
| Event | Action | Description |
|-------|--------|-------------|
| user_texting | started | User started typing |
| user_texting | stopped | User stopped typing |
| user_recording | started | User started voice recording |
| user_recording | stopped | User stopped voice recording |
| connection | online | WhatsApp Web is online |
| connection | lost | Connection lost (internet, browser closed, tab closed) |
| auth | qr_ready | QR code displayed, user needs to scan |
| auth | logged_in | User successfully logged in |
âï¸ Configuration
Edit config.py to customize behavior:
Monitoring Settings
MONITOR_INTERVAL = 0.5 # Check every 0.5 seconds TYPING_STOP_DELAY = 3.0 # Seconds before "stopped typing"
Browser Settings
HEADLESS_MODE = True # Run without visible window WINDOW_WIDTH = 1920 WINDOW_HEIGHT = 1080
Event Toggles
EVENTS_ENABLED = { "online_offline": True, "typing": True, "voice_recording": True, }
Webhook Settings
WEBHOOK_TIMEOUT = 10 WEBHOOK_RETRY_ENABLED = True WEBHOOK_RETRY_COUNT = 3
ð§ Advanced Usage
Cleanup Utility
If you encounter issues with Chrome processes or need to reset the session:
Windows:
cleanup.bat
This will:
- Kill all Chrome and ChromeDriver processes
- Remove the
chrome_profiledirectory - Allow you to start fresh with a new QR code scan
Linux/Mac:
rm -rf chrome_profile pkill -f chrome pkill -f chromedriver
Run in Headless Mode
Set in config.py:
HEADLESS_MODE = True
Run as Background Service
Windows (using NSSM):
# Install NSSM, then: nssm install WhatsAppMonitor "C:\path\to\venv\Scripts\python.exe" "C:\path\to\whatsapp_monitor.py" nssm start WhatsAppMonitor
Linux (using systemd):
Create /etc/systemd/system/whatsapp-monitor.service:
[Unit] Description=WhatsApp Web Monitor After=network.target [Service] Type=simple User=youruser WorkingDirectory=/path/to/Whatsapp Web Monitoring ExecStart=/path/to/venv/bin/python whatsapp_monitor.py Restart=always [Install] WantedBy=multi-user.target
Then:
sudo systemctl enable whatsapp-monitor sudo systemctl start whatsapp-monitor
ð Logging
Logs are written to:
- Console: Colored real-time output
- File:
whatsapp_monitor.log
Configure in config.py:
LOG_LEVEL = "INFO" # DEBUG, INFO, WARNING, ERROR FILE_LOGGING = True CONSOLE_LOGGING = True
ð Troubleshooting
ChromeDriver Issues
The system automatically downloads ChromeDriver. If issues occur:
python setup_chromedriver.py
QR Code Not Appearing
- Disable headless mode temporarily in
config.py:HEADLESS_MODE = False - Check if Chrome is installed
- Run cleanup script and try again:
# Windows cleanup.bat # Linux/Mac rm -rf chrome_profile
Webhook Not Sending
- Verify webhook URL is correct in
.envorconfig.py - Check network connectivity
- Review logs in
whatsapp_monitor.log - Test webhook URL with curl:
curl -X POST -H "Content-Type: application/json" -d '{"test":"data"}' YOUR_WEBHOOK_URL - Try console mode first (remove webhook URL) to verify events are being detected
Session Expired / Chrome Profile Issues
Run the cleanup script to reset everything:
Windows:
cleanup.bat
Linux/Mac:
rm -rf chrome_profile pkill -f chrome pkill -f chromedriver
Then restart the monitor and scan QR code again.
Voice Recording Not Detected
If voice recording detection isn't working, use the element inspector tool:
python inspect_elements.py
This will show you which selectors are being detected in real-time. Try recording a voice message and see which elements appear. You can then update the selectors in config.py if needed.
Debugging Element Selectors
Run the element inspector to see what's being detected:
python inspect_elements.py
This tool will:
- Show which elements are currently detected
- Display all voice/audio related data-testid and data-icon attributes
- Help you find the correct selectors if WhatsApp Web UI changes
- Update every 2 seconds with current status
Chrome Crashes or Hangs
- Run the cleanup script to kill all Chrome processes
- Delete the chrome_profile folder
- Restart the monitor
- See Fix Chrome Crash for detailed troubleshooting
ð Project Structure
WhatsApp Web Monitoring/
âââ whatsapp_monitor.py # Main monitoring application
âââ inspect_elements.py # Element inspector tool for debugging
âââ setup_chromedriver.py # ChromeDriver auto-setup
âââ test_console_mode.py # Test script for console mode
âââ config.py # Configuration settings
âââ requirements.txt # Python dependencies
âââ .env.example # Environment variables template
âââ .gitignore # Git ignore rules
âââ README.md # This file
âââ run.bat # Quick start script (Windows)
âââ run.sh # Quick start script (Linux/Mac)
âââ cleanup.bat # Cleanup script (Windows)
âââ docs/ # Documentation folder
â âââ QUICK_START.md # Quick start guide
â âââ CONSOLE_MODE.md # Console mode documentation
â âââ ARCHITECTURE.md # System architecture
â âââ FLOW_DIAGRAM.md # Event flow diagrams
â âââ SYSTEM_OVERVIEW.md # Detailed system overview
â âââ REQUIREMENTS_CHECKLIST.md # Feature checklist
âââ chrome_profile/ # WhatsApp session data (auto-created)
âââ drivers/ # ChromeDriver (auto-downloaded)
âââ whatsapp_monitor.log # Log file (auto-created)
ð Security Notes
- Session Data: The
chrome_profilefolder contains your WhatsApp session. Keep it secure. - Webhook URL: Contains sensitive endpoint. Use environment variables.
- HTTPS: Always use HTTPS for webhook URLs in production.
ð¤ N8N Integration Example
Create a webhook node in N8N:
- Add Webhook node
- Set HTTP Method: POST
- Set Path:
/webhook/whatsapp-monitor - Use the full URL in your
.envfile
Example N8N workflow:
Webhook â Switch (by event type) â Different actions per event
ð Quick Reference
Common Commands
# Quick start (Windows) run.bat # Quick start (Linux/Mac) ./run.sh # Manual start python whatsapp_monitor.py # Test console mode python test_console_mode.py # Debug element selectors python inspect_elements.py # Cleanup and reset cleanup.bat # Windows rm -rf chrome_profile # Linux/Mac
Configuration Files
.env- Webhook URL and environment variables (create from.env.example)config.py- All monitoring settings and selectorschrome_profile/- WhatsApp session data (auto-created)whatsapp_monitor.log- Application logs
ð Documentation
Additional documentation is available in the docs/ folder:
Getting Started
- Quick Start Guide - Get up and running in 5 minutes
- Console Mode - Running without webhook URL (print events to console)
Technical Documentation
- Architecture Diagram - System architecture and component interactions
- Flow Diagram - Event detection and webhook flow
- System Overview - Detailed architecture and how it works
- Requirements Checklist - Complete feature implementation status
ð License
This project is provided as-is for personal use.
ð Credits
Built with:
- Selenium WebDriver
- Python Requests
- Colorama
- WebDriver Manager
Note: This tool monitors your own WhatsApp Web activity. Use responsibly and in compliance with WhatsApp's Terms of Service.
Project Timeline
Technologies
External Links
Related Projects
Projects built with similar technologies.
Online Html Editor And Viewer
The Online HTML Editor and Viewer is a simple web application built with Flask that allows users to write and preview HTML code in real-time.
Qrgen
A premium, feature-rich QR Code Generator engineered with Python (Flask) and a pristine Glassmorphism frontend.
Examina Ai
Using AI, It transforms raw study materials into structured, verified examination sets with support for institutional export formats like Moodle XML.