Back to Eliza

WhatsApp Plugin

packages/docs/plugin-registry/platform/whatsapp.md

2.0.15.4 KB
Original Source

The WhatsApp plugin connects Eliza agents to WhatsApp, supporting two authentication methods: Baileys (QR code scan, personal accounts) and Cloud API (WhatsApp Business API, official).

Package: @elizaos/plugin-whatsapp

Overview

Two paths are available:

  • Baileys (Personal) — Uses the WhatsApp Web multi-device protocol. No API keys or business accounts needed. Scan a QR code with your phone to authenticate. Pros: no cost, works with personal accounts. Cons: unofficial API (may violate WhatsApp ToS), session can expire if phone disconnects.
  • Cloud API (Business) — Uses Meta's official WhatsApp Business Cloud API. Requires a WhatsApp Business Account and access tokens from the Meta Developer Dashboard. Pros: official, reliable, webhook-based. Cons: requires business account, per-message costs may apply.

Installation

bash
eliza plugins install @elizaos/plugin-whatsapp

Setup

1. Configure Authentication Directory

The plugin stores WhatsApp session credentials in an authDir directory. On first run, it will display a QR code for you to scan with your phone.

json
{
  "connectors": {
    "whatsapp": {
      "authDir": "./whatsapp-auth"
    }
  }
}

2. Scan the QR Code

On first start, the plugin prints a QR code to the terminal. Scan it with WhatsApp on your phone:

  1. Open WhatsApp on your phone
  2. Go to Settings → Linked Devices → Link a Device
  3. Scan the QR code displayed in the terminal

The session is saved to authDir and persists across restarts.

Cloud API Setup

For the official WhatsApp Business API, set environment variables instead of (or in addition to) authDir:

bash
WHATSAPP_ACCESS_TOKEN=your-access-token
WHATSAPP_PHONE_NUMBER_ID=your-phone-number-id
WHATSAPP_WEBHOOK_VERIFY_TOKEN=your-webhook-verify-token
WHATSAPP_BUSINESS_ACCOUNT_ID=your-business-account-id

These can be placed in ~/.eliza/.env or the env section of your config file.

Configuration

FieldRequiredDescription
authDirBaileys onlyDirectory path for Baileys session files
enabledNoSet false to disable (default: true)
allowedJidsNoArray of WhatsApp JIDs (phone numbers) to respond to
allowedGroupsNoArray of group JIDs to participate in
ignoreOwnMessagesNoSkip messages sent by the bot itself (default: true)
dmPolicyNoDM acceptance policy: "pairing", "open", or "closed" (default: "pairing")
groupPolicyNoGroup message policy: "open", "disabled", or "allowlist" (default: "allowlist")
selfChatModeNoRespond to your own messages for testing (default: false)
json
{
  "connectors": {
    "whatsapp": {
      "authDir": "./whatsapp-auth",
      "dmPolicy": "pairing",
      "groupPolicy": "allowlist",
      "groupAllowFrom": ["[email protected]"]
    }
  }
}

Multi-Account Support

Run multiple WhatsApp accounts by configuring the accounts map:

json
{
  "connectors": {
    "whatsapp": {
      "accounts": {
        "account1": {
          "authDir": "./whatsapp-auth-1"
        },
        "account2": {
          "authDir": "./whatsapp-auth-2",
          "enabled": false
        }
      }
    }
  }
}

Features

  • Personal accounts — No Business API subscription required
  • Multi-device support — WhatsApp multi-device protocol
  • Group chats — Responds in group conversations
  • Private messages — 1:1 message handling
  • Media — Receives and sends images, documents, voice notes
  • Status updates — Can post to WhatsApp Status
  • Multi-account — Manage multiple WhatsApp numbers

Message Flow

WhatsApp WebSocket event
       ↓
Plugin filters by allowed JIDs/groups
       ↓
Media downloaded and processed if present
       ↓
AgentRuntime processes message
       ↓
Response sent via Baileys API

Environment Variables

VariableRequiredDescription
WHATSAPP_ACCESS_TOKENNoWhatsApp Cloud API access token
WHATSAPP_PHONE_NUMBER_IDNoWhatsApp Business phone number ID
WHATSAPP_AUTH_METHODNoAuthentication method: baileys or cloud-api
WHATSAPP_AUTH_DIRNoDirectory for Baileys session files
WHATSAPP_PRINT_QRNoPrint QR code in terminal for Baileys auth
WHATSAPP_WEBHOOK_VERIFY_TOKENNoWebhook verification token for Cloud API
WHATSAPP_BUSINESS_ACCOUNT_IDNoWhatsApp Business account ID
WHATSAPP_API_VERSIONNoCloud API version
WHATSAPP_DM_POLICYNoDM acceptance policy
WHATSAPP_GROUP_POLICYNoGroup message policy

Auto-Enable

The plugin auto-enables when connectors.whatsapp contains an authDir or accounts configuration with at least one account that has authDir set.

Session Persistence

Session credentials are stored in the authDir as multiple JSON files. Back up this directory to avoid needing to re-scan the QR code after a restart.