📱 WhatsApp Plugin for ElizaOS
✨ Features
- 🤖 WhatsApp Web Integration: Connect your ElizaOS agent to WhatsApp using QR code authentication
- 💬 Bidirectional Messaging: Send and receive messages seamlessly
- 📱 Multi-Device Support: Works with WhatsApp multi-device beta
- 🔐 Session Persistence: Automatic session management with local storage
- 🎯 Number Filtering: Restrict bot to specific phone numbers (allowlist)
- ⚡ Auto-Reply: Configurable automatic response system
- 🎭 Puppeteer Integration: Built-in browser automation with stealth mode
- 📊 Message Management: Intelligent message queuing and processing
- 🔄 Reconnection Handling: Automatic reconnection on disconnection
- ☁️ Optional S3 Backup: AWS S3 integration for session backup (production deployments)
Note: This plugin uses whatsapp-web.js which automates WhatsApp Web. It does not use the official WhatsApp Business API. For business-critical applications, consider using official WhatsApp Business API solutions.
📦 Installation
bun add @standujar/plugin-whatsapp
npm install @standujar/plugin-whatsapp
yarn add @standujar/plugin-whatsapp
Dependencies
The plugin requires the following dependencies (automatically installed):
@elizaos/core - ElizaOS core framework
whatsapp-web.js - WhatsApp Web client library
puppeteer-extra - Enhanced Puppeteer for browser automation
puppeteer-extra-plugin-stealth - Stealth plugin to avoid detection
@aws-sdk/client-s3 - AWS S3 client (for optional session backup)
@aws-sdk/credential-providers - AWS credential management
⚙️ Configuration
The plugin can be configured using either environment variables OR character settings. Character settings take priority over environment variables.
Option 1: Environment Variables
WHATSAPP_SESSION_NAME=eliza-bot
WHATSAPP_AUTO_REPLY=true
WHATSAPP_USE_PUPPETEER=true
WHATSAPP_AUTH_PATH=.wwebjs_auth
WHATSAPP_ALLOWED_NUMBERS=33612345678,33698765432
WHATSAPP_S3_BUCKET=your-bucket-name
WHATSAPP_S3_REGION=eu-west-3
WHATSAPP_S3_PREFIX=sessions/
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=eu-west-3
Option 2: Character Configuration (Recommended)
Add the plugin and settings to your ElizaOS character file:
{
"name": "MyAssistant",
"plugins": ["@standujar/plugin-whatsapp"],
"settings": {
"whatsapp": {
"sessionName": "eliza-bot",
"authPath": ".wwebjs_auth",
"autoReply": true,
"usePuppeteer": true,
"allowedNumbers": [
"33612345678",
"33698765432"
]
}
}
}
Configuration Parameters
All parameters can be set via environment variables (WHATSAPP_) or character settings (settings.whatsapp.):
sessionName | string | "eliza-bot" | Unique identifier for the WhatsApp session (must match the name used when generating the QR code) |
autoReply | boolean | true | Enable automatic message responses |
usePuppeteer | boolean | true | Use Puppeteer for browser automation |
authPath | string | ".wwebjs_auth" | Directory path for storing authentication data |
allowedNumbers | string[] | undefined | List of phone numbers allowed to interact with the bot |
s3Download | object | undefined | (Optional) S3 configuration for session backup/restore |
S3 Configuration (Optional - Production Only)
If you need S3 backup for production deployments, add the s3Download object:
{
"settings": {
"whatsapp": {
"s3Download": {
"bucket": "whatsapp-sessions",
"region": "eu-west-3",
"prefix": "sessions/"
}
}
}
}
🚀 Usage
Basic Setup
- Add the plugin to your character configuration:
{
"plugins": ["@standujar/plugin-whatsapp"]
}
- Configure the session name via environment variable OR character settings:
WHATSAPP_SESSION_NAME=eliza-bot
"settings": {
"whatsapp": {
"sessionName": "eliza-bot"
}
}
Note: The actual session folder will be .wwebjs_auth/session-eliza-bot/ (the "session-" prefix is added automatically)
bun start
Session Generation
The plugin includes helper scripts to generate WhatsApp authentication sessions. You can use either Node.js directly or Docker:
Option 1: Using Node.js
cd scripts
bun install
WHATSAPP_SESSION_NAME=eliza-bot bun run generate-auth
Option 2: Using Docker (Recommended)
Docker provides a consistent environment with all Chrome dependencies pre-installed:
docker build -t whatsapp-auth-generator ./scripts
docker run -it \
-e WHATSAPP_SESSION_NAME=eliza-bot \
-v $(pwd)/.wwebjs_auth:/app/.wwebjs_auth \
whatsapp-auth-generator
After scanning the QR code with your WhatsApp mobile app:
- Session files will be saved in
.wwebjs_auth directory
- A session info file will be created with account details
- The session can be used immediately with your ElizaOS agent
Session Script Available
The scripts/ directory contains a utility to generate WhatsApp authentication:
generate-whatsapp-auth.js - Generates a new WhatsApp session with QR code authentication
- Creates session files in
.wwebjs_auth directory
- Saves account information for reference
Advanced Configuration
With S3 Backup (Optional)
For production deployments, you can enable S3 session backup:
{
"settings": {
"whatsapp": {
"sessionName": "production-bot",
"s3Download": {
"bucket": "my-whatsapp-sessions",
"region": "us-east-1",
"prefix": "prod/sessions/"
}
}
}
}
Number Filtering
Restrict the bot to specific phone numbers:
{
"settings": {
"whatsapp": {
"allowedNumbers": [
"33612345678",
"14155552671",
"447911123456"
]
}
}
}
🔧 Advanced
S3 Session Backup (Optional)
For production environments, the plugin supports automatic session backup and restoration using AWS S3:
How It Works
- Session Download: On startup, the plugin checks S3 for an existing session backup
- Automatic Restoration: If found, the session is downloaded and extracted locally
- Skip QR Code: With a valid session backup, no QR code scanning is needed
- Session Persistence: Sessions are stored as ZIP files in S3
AWS Configuration
The plugin automatically detects the AWS environment:
- ECS/Production: Uses task role credentials automatically
- Local Development: Uses AWS SSO profile or credential chain
- AWS Profile Support: Respects
AWS_PROFILE and AWS_DEFAULT_PROFILE environment variables
S3 File Structure
Sessions are stored in S3 with the following structure:
s3://your-bucket/
└── sessions/
└── your-session-name.zip
Manual Session Backup
To manually backup your session to S3:
cd .wwebjs_auth
zip -r ../session-backup.zip session-*
cd ..
aws s3 cp session-backup.zip s3://your-bucket/sessions/your-session-name.zip
📊 Message Flow
sequenceDiagram
participant U as User
participant W as WhatsApp
participant P as Plugin
participant E as ElizaOS
participant S3 as S3 (Optional)
Note over P,S3: Startup Phase
P->>S3: Check for session backup
S3-->>P: Download session (if exists)
P->>W: Initialize client
W-->>P: QR Code (if no session)
Note over U,E: Message Processing
U->>W: Send message
W->>P: Message received event
P->>P: Check allowed numbers
P->>E: Process with AI
E-->>P: Generate response
P->>W: Send response
W->>U: Deliver message
🛠️ Technical Details
Architecture
The plugin consists of several key components:
- WhatsAppService: Main service class that manages the WhatsApp client lifecycle
- MessageManager: Handles message queuing, processing, and response generation
- SessionDownloader: Manages S3 session backup and restoration
- Config Loader: Handles configuration from environment variables and character settings
Event Handling
The plugin listens to the following WhatsApp events:
qr | QR code generated | Display for scanning |
authenticated | Successfully authenticated | Log success |
ready | Client ready | Start message processing |
message | Message received | Queue for processing |
disconnected | Connection lost | Attempt reconnection |
Puppeteer Configuration
The plugin uses optimized Puppeteer settings:
{
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
],
executablePath: '/usr/bin/chromium-browser'
}
🔍 Debugging
Enable debug logging to troubleshoot issues:
LOG_LEVEL=debug bun start
Common debug points:
- QR code generation and display
- Session authentication status
- Message reception and processing
- S3 session download attempts
- Number filtering decisions
Development Setup
git clone https://github.com/standujar/plugin-whatsapp.git
bun install
bun test
bun run build
bun run dev
Scripts
bun start - Start the ElizaOS agent with the plugin
bun run build - Build the TypeScript source
bun run dev - Run in development mode
bun run lint - Run linting with Biome
bun run format - Format code with Biome
bun run clean - Clean build artifacts
bun run test - Run tests
📄 License
This plugin is licensed under the MIT License. See LICENSE file for details.
🆘 Support
📈 Roadmap
Made with ❤️ by Stan for the ElizaOS community