WhatsApp CLI ๐ฑ
WhatsApp CLI cross-platform tool with browser automation, session persistence, real-time group monitoring, and an interactive terminal interface.
A powerful Python-based CLI tool for automating WhatsApp Web interactions using Playwright. This tool provides both a standalone interactive terminal and an importable Python module for integration with larger projects.
โจ Features
- ๐ Interactive Terminal: Beautiful CLI interface with command autocomplete
- ๐ฑ WhatsApp Web Automation: Full browser automation via Playwright
- ๐ Session Persistence: Save authentication to avoid repeated QR scanning
- ๐ Group Management: List, monitor, and send messages to groups
- ๐ Real-time Listening: Monitor group messages in real-time
- ๐จ Rich Output: Colorful, formatted terminal output
- ๐ง Configurable: Environment-based configuration with interactive prompts
- ๐ฆ Importable Module: Use as a library in your Python projects
- ๐ Cross-platform: Works on Linux, macOS, and Windows
๐ Requirements
- Python โฅ 3.10
- Poetry (for dependency management)
- Chromium browser (installed automatically by Playwright)
โก Quick Start (No pre-installation required)
Step 1: Clone the repository
git clone https://github.com/alexcolls/whatsapp-cli.git
cd whatsapp-cli
Step 2: Run the installer
./run.sh
That's it! The script will:
- Detect if WhatsApp CLI is installed
- Launch the interactive installer if needed
- Let you choose between System, Development, or Both installation
- Handle all dependencies automatically
- Run the CLI when ready
Installation Modes
๐ System Installation (Recommended)
- Installs globally as
whatsapp-cli command
- Available system-wide, run from anywhere
- Easier to use for daily tasks
./install.sh --system
# Then use: whatsapp-cli
๐ ๏ธ Development Installation
- Installs locally with Poetry
- Perfect for testing and development
- Keeps everything isolated
./install.sh --dev
# Then use: ./run.sh
๐ฅ Both Modes (System + Development)
- Installs both system-wide command AND local development
- Use
whatsapp-cli anywhere for daily use
- Use
./run.sh for development and testing
- Best of both worlds!
./install.sh --both
# Then use: whatsapp-cli (system) OR ./run.sh (dev)
๐ Dry-run Mode
./install.sh --dry-run # Test without installing
๐ More details in QUICKSTART.md
๐ Installation Options
Automated Installation (Recommended)
Use the installation script for guided setup:
./install.sh # Interactive mode (choose 1/2/3)
./install.sh --system # System-wide installation only
./install.sh --dev # Development installation only
./install.sh --both # Both system + development (recommended)
Manual Installation
For advanced users or custom setups:
1. Clone the repository
git clone https://github.com/alexcolls/whatsapp-cli.git
cd whatsapp-cli
2. Install dependencies with Poetry
Make sure to have python 3.10+ installed. If not, install it: https://www.python.org/downloads/.
Make sure you have poetry installed. If not, install it: https://python-poetry.org/docs/#installation.
poetry install
3. (Optional) Install Playwright browsers
If previous step failed for some reason, then run:
poetry run playwright install chromium
Usually this is handled automatically, but run the above if the CLI asks you to install browsers or you encounter browser-related errors.
4. Configure environment (optional)
cp .env.sample .env
# Edit .env with your preferred settings
๐ฏ Usage
Standalone CLI
Run the interactive WhatsApp CLI:
poetry run whatsapp
You'll be greeted with an interactive shell:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ
โ WhatsApp CLI v0.1.0 โ
โ โ
โ Easy-to-use WhatsApp interface for โ
โ your terminal โ
โ Type 'help' for available commands โ
โ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
whatsapp>
Available Commands
| Command | Description | Example |
|---|
start | Connect to WhatsApp Web (scan QR if needed) | start |
list-groups | List all available groups/chats | list-groups |
listen <group> | Listen to messages from a group | listen 1 or listen "Family Group" |
send <group> <msg> | Send a message to a group | send 1 "Hello everyone!" |
help | Show help message | help |
exit | Exit the CLI | exit |
Example Session
whatsapp> start
๐ Starting WhatsApp bot...
๐ฑ Please scan the QR code with your phone to authenticate
Waiting for authentication...
โ Authentication successful!
โ Session saved
โ WhatsApp bot connected and ready!
whatsapp> list-groups
๐ Fetching groups...
WhatsApp Groups/Chats
โโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโ
โ # โ Name โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ 1 โ Family Group โ
โ 2 โ Work Team โ
โ 3 โ Friends โ
โโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโ
Total: 3 groups/chats
whatsapp> listen 2
โ Opened group: Work Team
๐ Listening to 'Work Team'... (Press Ctrl+C to stop)
[10:45] John: Hey everyone
[10:46] Sarah: Hi!
^C
Stopped listening
whatsapp> send 2 "Thanks for the update!"
โ Opened group: Work Team
โ Message sent to Work Team
whatsapp> exit
๐ Goodbye!
As a Python Module
Import and use WhatsAppBot in your Python projects:
from pathlib import Path
from whatsappcli import WhatsAppBot
# Initialize bot
bot = WhatsAppBot(
session_path=Path.home() / ".whatsapp-cli" / "session",
headless=False
)
# Start and connect
bot.start()
# List groups
groups = bot.get_groups()
for group in groups:
print(f"{group['id']}: {group['name']}")
# Send a message
bot.send_message("Family Group", "Hello from Python!")
# Listen to messages with callback
def handle_message(msg):
print(f"New message from {msg['sender']}: {msg['text']}")
bot.listen_to_group("Work Team", callback=handle_message)
# Stop bot
bot.stop()
โ๏ธ Configuration
Configuration is managed via a .env file. Copy .env.sample to .env and customize:
# Session Management
WHATSAPP_SESSION_PATH=/home/quantium/.whatsapp-cli/session
# Run browser in headless mode (true/false)
WHATSAPP_HEADLESS=false
# Logging Configuration
LOG_LEVEL=INFO
# Optional: Path to log file (leave empty for console only)
LOG_FILE=
# Optional: Comma-separated list of default groups
DEFAULT_GROUPS=
If values are missing from .env, the CLI will prompt you interactively.
๐๏ธ Project Structure
whatsapp-cli/
โโโ src/
โ โโโ whatsappcli/
โ โโโ __init__.py # Package initialization
โ โโโ __main__.py # CLI entry point
โ โโโ bot.py # WhatsAppBot class
โ โโโ commands.py # CLI command handlers
โ โโโ session.py # Session management
โ โโโ utils.py # Utility functions
โโโ pyproject.toml # Poetry configuration
โโโ .env.sample # Environment template
โโโ .gitignore
โโโ CHANGELOG.md
โโโ LICENSE
โโโ README.md
๐ง Development
Running in Development Mode
# Install with dev dependencies
poetry install
# Run CLI
poetry run whatsapp
# Run with Python directly
poetry run python -m whatsappcli
Testing the Module Import
poetry run python -c "from whatsappcli import WhatsAppBot; print('Import successful!')"
๐ Notes
- First Run: On first run, you'll need to scan a QR code with your phone to authenticate
- Session Persistence: After initial authentication, sessions are saved locally
- Browser Mode: Use
WHATSAPP_HEADLESS=false to see the browser window (useful for debugging)
- WhatsApp Web: This tool uses WhatsApp Web, so your phone needs to be online
- Rate Limits: Be mindful of WhatsApp's rate limits when sending messages
๐ค Contributing
We welcome contributions from the community! Whether it's bug reports, feature requests, documentation improvements, or code contributions, your help is appreciated.
How to Contribute
- Report Issues - Found a bug? Open an issue
- Suggest Features - Have an idea? Start a discussion
- Submit Pull Requests - Want to contribute code? See our Contributing Guide
Quick Start for Contributors
# Fork and clone the repository
git clone https://github.com/YOUR-USERNAME/whatsapp-cli.git
cd whatsapp-cli
# Install development dependencies
./install.sh --dev
# Make your changes and test
./run.sh
# Submit a pull request
For detailed guidelines, coding standards, and best practices, please read our CONTRIBUTING.md.
๐ License
See the LICENSE file for details.
๐ Integration
This module is designed to be easily imported into larger Python projects. Simply install it as a dependency and import the WhatsAppBot class:
from whatsappcli import WhatsAppBot
Perfect for social media management tools, automation scripts, or multi-platform messaging systems!
๐ Project Info
โ ๏ธ Disclaimer
This tool is for educational and personal use only. Make sure to comply with WhatsApp's Terms of Service. The authors are not responsible for any misuse of this tool.
Important Notes:
- This tool uses WhatsApp Web (not the official API)
- Your phone must be online and connected to the internet
- Automated/bulk messaging may violate WhatsApp's terms
- Use responsibly and respect privacy
๐ Acknowledgments
Made with โค๏ธ using Python, Playwright, and Rich