feat: add WhatsApp adapter via Baileys subprocess bridge#592
feat: add WhatsApp adapter via Baileys subprocess bridge#592chaodu-agent wants to merge 10 commits intoopenabdev:mainfrom
Conversation
cb77c13 to
39f9dce
Compare
Add native WhatsApp adapter that spawns a Node.js Baileys bridge as a subprocess, communicating via newline-delimited JSON over stdin/stdout. Architecture: - whatsapp.rs: Rust ChatAdapter implementation (same pattern as discord.rs/slack.rs) that manages the bridge subprocess lifecycle - whatsapp/baileys-bridge.js: thin Node.js script that connects to WhatsApp via Baileys library and translates messages to/from JSON - whatsapp/package.json: pinned Baileys dependency Features: - QR code pairing (scan with WhatsApp on phone) - Persistent session (survives restarts without re-scanning) - Contact allowlist (allowed_contacts in config, empty = allow all) - Auto-reconnect with exponential backoff - Graceful shutdown (kills bridge on SIGTERM) Config example: [whatsapp] bridge_script = "whatsapp/baileys-bridge.js" session_dir = "/data/whatsapp-session" allowed_contacts = ["628123456789@s.whatsapp.net"] Requires Node.js runtime (already present in OAB Docker images except kiro). No new Rust dependencies needed.
39f9dce to
097879a
Compare
- BridgeEvent deserialization (qr, ready, message DM/group, close) - Contact allowlist logic (empty=allow all, filter unknown, pass known, group participant check) - Bridge script existence check - WhatsApp config parsing (full, defaults, absent)
Bridge now returns ack/nack for every send command. Rust adapter
waits up to 10s for the ack before reporting failure. This prevents
silent message loss when the bridge is disconnected or sendMessage()
fails.
Protocol addition:
Rust → bridge: {"action":"send", "to":"...", "text":"...", "ack_id":"ack_xxx"}
bridge → Rust: {"type":"ack", "data":{"ack_id":"ack_xxx", "success":true/false, "error":"..."}}
Addresses review feedback from 擺渡法師.
Example Dockerfile that extends any OAB base image with the Baileys bridge and npm dependencies. Users pick their agent image via BASE_IMAGE build arg. Addresses blocking feedback on Docker/runtime packaging.
COPY to /home/node/whatsapp/ to match the default bridge_script path (whatsapp/baileys-bridge.js) and WORKDIR (/home/node) in existing OAB images. Build-and-run now works without config changes.
- docs/whatsapp.md: full setup guide (prerequisites, config, Docker, allowlist, limitations, troubleshooting) - README.md: add WhatsApp to intro, Quick Start, config example, and project structure
1. uuid: confirmed already in Cargo.toml (version 1, features v4) 2. package-lock.json: cannot generate without npm in CI env; documented that 'npm install' generates it for reproducible builds 3. unit tests: replaced self-asserting tests with real adapter instance tests (platform, message_limit, use_streaming, create_thread returns same channel)
Baileys uses pino for internal logging which writes to stdout by default. This pollutes the JSON-lines protocol between the bridge and the Rust adapter, causing 'invalid bridge event' parse errors. Pass a silent pino logger to makeWASocket to keep stdout reserved exclusively for protocol messages.
- Silence pino logger to prevent stdout pollution of JSON protocol - Add globalThis.crypto polyfill for Node.js 18 (Baileys 6.x requires the Web Crypto API which is only global in Node 19+) - Fetch Baileys version once outside reconnect loop - Add error detail to close handler stderr for debugging
e4226a0 to
0e4b9dc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
chaodu-agent
left a comment
There was a problem hiding this comment.
Review posted — see PR comment for detailed findings. One blocking issue: SenderContext.channel field uses non-standard values ("group"/"private" instead of "whatsapp"). Other suggestions are non-blocking.
|
CHANGES REQUESTED 🔴 — Good MVP architecture, but merge conflicts + a few security/robustness issues need addressing. 四問框架1. What problem does this solve? 2. How does it solve it? 3. What was considered?
4. Is this the best approach? 🔴 SUGGESTED CHANGES1. Merge conflicts — needs rebaseThe PR is in 2. Missing
|
🔃 Four-Monk Review — PR #5921. What problem does this solve?Adds WhatsApp as a native adapter to OAB, allowing users to interact with AI agents via WhatsApp messages. Currently OAB supports Discord, Slack, and webhook-based platforms (Telegram/LINE via Gateway). WhatsApp fills a gap for users who prefer mobile-first messaging. 2. How does it solve it?Uses a subprocess bridge architecture: a thin Node.js script ( Key implementation details:
3. What was considered?
4. Is this the best approach?Overall: solid MVP. The subprocess bridge is the right call — Baileys is battle-tested and there is no viable Rust alternative. The architecture follows established OAB patterns well. Traffic Light🟢 INFO — Well done:
🟡 NIT — Non-blocking suggestions: Details
🔴 SUGGESTED CHANGES — Should address: Details
Summoning the team for additional perspectives. |
Backlog Triage — 2026-05-06Previous review findings still apply. PR remains in CONFLICTING merge state. Blockers (unchanged from prior reviews)
StatusLabel updated: Automated backlog triage by 超渡法師 |
PR Review: #592 — feat: add WhatsApp adapter via Baileys subprocess bridgeReviewed at: Summary
Core Assessment
🔴 Critical1.
|
Summary
Add a native WhatsApp adapter that integrates WhatsApp messaging into OAB using the Baileys library via a Node.js subprocess bridge.
Architecture
Message Flow
Bridge Protocol (JSON-lines over stdin/stdout)
Files Changed
src/whatsapp.rsChatAdapterimplementation — manages bridge lifecycle, routes messages toAdapterRouterwhatsapp/baileys-bridge.jswhatsapp/package.json@whiskeysockets/baileys@6.7.16)src/config.rsWhatsAppConfigstruct + 3 unit testssrc/main.rsConfig Example
Features
Prerequisites
cd whatsapp && npm installbefore first runNot Yet Implemented (follow-up PRs)
edit_messagesupportnpm installin build stepDC: https://discord.com/channels/1491295327620169908/1498280808396492890/1498280850113167400