Skip to main content

AlphaAvatar WhatsApp Channel

Status Driver Architecture

A pluggable WhatsApp channel for AlphaAvatar, built with a driver abstraction architecture to support multiple backend APIs (Baileys / Meta / Twilio).

Built with a Driver Abstraction Architecture for future API replacement.


🏗 Architecture

This module is divided into two independent layers:

WhatsApp Backend API
        │
        ▼
Driver Layer (replaceable)
        │  WebSocket
        ▼
Bridge Core (Python)
        │  LiveKit DataChannel
        ▼
AlphaAvatar Agent

Layer Responsibilities

🔌 Driver Layer (Replaceable)

Located at:

drivers/
  baileys/

Responsible for:

  • Connecting to WhatsApp backend
  • Receiving inbound messages
  • Sending outbound messages
  • Converting raw events → unified schema
  • Communicating with Bridge Core via WebSocket

This layer can be replaced without modifying the Agent or Bridge Core.


🧠 Bridge Core (Stable API Layer)

Located at:

src/alphaavatar/channels/whatsapp/

Responsible for:

  • WebSocket hub
  • Message deduplication
  • Session mapping
  • LiveKit publish/subscribe
  • Routing whatsapp.in / whatsapp.out

This layer does not depend on a specific WhatsApp API provider.


📦 Current Driver: Baileys (WhatsApp Web)

Development & local testing only.

When to Use

  • Development
  • Internal testing
  • Personal bot

Not Recommended For

  • Production
  • Public bots
  • High-volume systems

🚀 Quick Start

1️⃣ Start Python Bridge Core

From repo root:

uv run alphaavatar-whatsapp-core

Expected output:

WhatsApp Core WS listening on ws://127.0.0.1:18789

Verify port:

ss -lntp | grep 18789

2️⃣ Start Baileys Driver

cd drivers/baileys
pnpm install
pnpm dev

Expected logs:

Connected to Core WS

Then a QR code will appear.


3️⃣ Link WhatsApp

On your phone:

  1. WhatsApp → Settings
  2. Linked Devices
  3. Link a device
  4. Scan terminal QR

Successful login:

WhatsApp connection opened

4️⃣ Test Message

Send a message to the linked account.

You should receive:

[echo] your message

If echo works, the channel pipeline is healthy.


🔄 Unified Event Schema

All drivers must emit events in the following format.

Inbound Event

{
  "v": 1,
  "channel": "whatsapp",
  "direction": "in",
  "from": "+9715xxxxxxx",
  "chat_id": "wa:xxx",
  "message_id": "xxx",
  "ts": 1700000000,
  "type": "text",
  "text": "hello",
  "meta": { "driver": "baileys" }
}

Outbound Event

{
  "v": 1,
  "channel": "whatsapp",
  "direction": "out",
  "to": "+9715xxxxxxx",
  "chat_id": "wa:xxx",
  "text": "hi!"
}

🔌 Driver Abstraction Model

Future drivers should implement:

  • Inbound handler → send to Bridge Core
  • Outbound handler → send via API
  • Reconnect logic
  • Auth lifecycle

Recommended structure:

drivers/
  baileys/
  meta/
  twilio/

Only the driver directory changes when switching backend API.


🔁 Switching to Official APIs

For production usage, replace Baileys with:

Meta Cloud API

  • Webhook-based inbound
  • HTTPS outbound
  • Business account required

Twilio WhatsApp API

  • Twilio webhook
  • Twilio REST outbound

What Does NOT Change

  • Python Bridge Core
  • LiveKit topics
  • Agent routing logic
  • Memory / RAG / MCP plugins

Only driver implementation changes.


🧠 LiveKit Integration

Bridge Core publishes:

  • whatsapp.in
  • whatsapp.out

Agent subscribes to whatsapp.in Agent replies to whatsapp.out

This decouples channel transport from AI logic.


🛠 Production Hardening Checklist

When moving beyond development:

  • Persistent deduplication (Redis / DB)
  • Per-user message queue
  • Rate limiting
  • Allowlist / pairing
  • Monitoring & health checks
  • Containerization
  • Replace Baileys with official API

📁 Project Structure

avatar-channels/
  avatar-channels-whatsapp/
    drivers/
      baileys/
        src/
    src/
      alphaavatar/channels/whatsapp/
    pyproject.toml
    README.md

📌 Design Philosophy

This module is designed with:

  • Clean separation of concerns
  • Replaceable transport layer
  • Stable AI core
  • Production upgrade path

It ensures that WhatsApp API provider changes do not cascade into AlphaAvatar core logic.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alpha_avatar_channels_whatsapp-0.6.5.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alpha_avatar_channels_whatsapp-0.6.5-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file alpha_avatar_channels_whatsapp-0.6.5.tar.gz.

File metadata

File hashes

Hashes for alpha_avatar_channels_whatsapp-0.6.5.tar.gz
Algorithm Hash digest
SHA256 5a7a2abf6704084ca162f5736c1163eb494470e0261601afb065ea6e9d22ceda
MD5 45b1ce826554f1fec71ecf3d403de24f
BLAKE2b-256 27a0cfe1b036e15ae69231c7eab03c5c8a006f7231a35e57b4ed759cb38ee262

See more details on using hashes here.

File details

Details for the file alpha_avatar_channels_whatsapp-0.6.5-py3-none-any.whl.

File metadata

File hashes

Hashes for alpha_avatar_channels_whatsapp-0.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dbddbbf3260ece3392323b3832cf719fa448cf61fe35a1ad62b2611c15ad07db
MD5 ddbe8fef7f9fd50c057f9c2784188ff5
BLAKE2b-256 b1d6d57a5294181720a93c4b7dc55f03cda0b838f3a8078d67067530f1bc241f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.7

2 files

0.6.6

2 files

This release

0.6.5 This release

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page