🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@standujar/plugin-whatsapp

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@standujar/plugin-whatsapp

WhatsApp plugin for elizaOS

latest
Source
npmnpm
Version
1.7.1
Version published
Maintainers
1
Created
Source

📱 WhatsApp Plugin for ElizaOS

License ElizaOS Compatible Version Dependencies

A powerful WhatsApp integration plugin for ElizaOS that enables your AI agent to communicate through WhatsApp Web using whatsapp-web.js. Features automatic session management and seamless message handling.

FeaturesInstallationConfigurationUsageAdvancedContributing

✨ 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

# Using bun (recommended)
bun add @standujar/plugin-whatsapp

# Using npm
npm install @standujar/plugin-whatsapp

# Using yarn
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

# Required: Session name for WhatsApp authentication (must match the name used in generate-auth script)
WHATSAPP_SESSION_NAME=eliza-bot

# Optional: Enable/disable automatic replies (default: true)
WHATSAPP_AUTO_REPLY=true

# Optional: Use Puppeteer for browser automation (default: true)
WHATSAPP_USE_PUPPETEER=true

# Optional: Local auth directory path (default: .wwebjs_auth)
WHATSAPP_AUTH_PATH=.wwebjs_auth

# Optional: Comma-separated list of allowed phone numbers
WHATSAPP_ALLOWED_NUMBERS=33612345678,33698765432

# Optional: AWS S3 Configuration for session backup
WHATSAPP_S3_BUCKET=your-bucket-name
WHATSAPP_S3_REGION=eu-west-3
WHATSAPP_S3_PREFIX=sessions/

# Optional: AWS Credentials (if not using IAM roles)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=eu-west-3

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.):

ParameterTypeDefaultDescription
sessionNamestring"eliza-bot"Unique identifier for the WhatsApp session (must match the name used when generating the QR code)
autoReplybooleantrueEnable automatic message responses
usePuppeteerbooleantrueUse Puppeteer for browser automation
authPathstring".wwebjs_auth"Directory path for storing authentication data
allowedNumbersstring[]undefinedList of phone numbers allowed to interact with the bot
s3Downloadobjectundefined(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",  // Required
        "region": "eu-west-3",          // Optional (default: "eu-west-3")
        "prefix": "sessions/"           // Optional (default: "whatsapp/")
      }
    }
  }
}

🚀 Usage

Basic Setup

  • Add the plugin to your character configuration:
{
  "plugins": ["@standujar/plugin-whatsapp"]
}
  • Configure the session name via environment variable OR character settings:
# Option A: In your .env file
WHATSAPP_SESSION_NAME=eliza-bot

# Option B: In your character settings
"settings": {
  "whatsapp": {
    "sessionName": "eliza-bot"
  }
}

Note: The actual session folder will be .wwebjs_auth/session-eliza-bot/ (the "session-" prefix is added automatically)

  • Generate WhatsApp session (see Session Generation section below)

  • Start your ElizaOS agent:

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

# Navigate to scripts directory
cd scripts

# Install dependencies
bun install

# Generate authentication (use the same name as in your config)
WHATSAPP_SESSION_NAME=eliza-bot bun run generate-auth

Docker provides a consistent environment with all Chrome dependencies pre-installed:

# Build the Docker image
docker build -t whatsapp-auth-generator ./scripts

# Run from your project root (where you run elizaos CLI)
# Use the same session name as in your config!
docker run -it \
  -e WHATSAPP_SESSION_NAME=eliza-bot \
  -v $(pwd)/.wwebjs_auth:/app/.wwebjs_auth \
  whatsapp-auth-generator

# Note: Run this command from your ElizaOS project root directory
# The session will be saved in .wwebjs_auth/session-eliza-bot/ at the project root

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",  // France
        "14155552671",  // US
        "447911123456"  // UK
      ]
    }
  }
}

🔧 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:

# Zip the session directory
cd .wwebjs_auth
zip -r ../session-backup.zip session-*
cd ..

# Upload to S3
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:

EventDescriptionAction
qrQR code generatedDisplay for scanning
authenticatedSuccessfully authenticatedLog success
readyClient readyStart message processing
messageMessage receivedQueue for processing
disconnectedConnection lostAttempt reconnection

Puppeteer Configuration

The plugin uses optimized Puppeteer settings:

{
  headless: true,
  args: [
    '--no-sandbox',
    '--disable-setuid-sandbox'
  ],
  executablePath: '/usr/bin/chromium-browser' // Or auto-detected
}

🔍 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

# Clone the repository
git clone https://github.com/standujar/plugin-whatsapp.git

# Install dependencies
bun install

# Run tests
bun test

# Build the plugin
bun run build

# Run in development mode
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

  • Basic WhatsApp Web integration
  • Session persistence
  • S3 session backup/restore
  • Number filtering
  • Message queuing
  • Group chat support
  • Media message handling (images, documents)
  • Voice message transcription
  • Reaction support
  • Status updates
  • Multi-session management
Made with ❤️ by Stan for the ElizaOS community

FAQs

Package last updated on 14 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts