Files
fusion/plugins/fusion-plugin-whatsapp-chat
gsxdsm c0d610d9d7 fix(whatsapp-plugin): connect with current WA Web version and load as bundled plugin
WhatsApp rejects handshakes advertising Baileys' baked-in stale protocol
version with a 405 close, so the plugin cycled starting->disconnected and
never issued a QR. connect() now fetches the current WA Web version per
socket build. /status also exposes lastError so this failure mode is
diagnosable from the documented troubleshooting surface.

The published bundled.js also failed to load entirely ("Dynamic require
of 'crypto' is not supported"): plugin bundles are ESM but Baileys is
CJS. bundlePluginEntry now injects the same createRequire banner as
dist/bin.js.

Verified end-to-end against an isolated fn serve: bundled.js loads,
status reaches awaiting-qr, /qr serves a scannable QR data URL,
/pair-code validates input, /logout clears auth state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 09:13:55 -07:00
..
2026-07-13 10:32:12 -07:00

WhatsApp Chat Plugin

WhatsApp Web (Baileys) bridge for Fusion. It pairs with your phone (QR or pairing code), keeps a background connection alive, forwards inbound direct text messages to a Fusion AI session, and sends the assistant reply back to WhatsApp.

No Meta Cloud app, webhook URL, verify token, or Graph API credentials are required.

Setup

  1. Enable/install the plugin in Plugin Manager.
  2. Configure allowedSenders (empty means nobody is allowed).
  3. Choose pairingMode:
    • qr (default): fetch QR from /api/plugins/fusion-plugin-whatsapp-chat/qr and scan in WhatsApp.
    • code: set pairingPhoneNumber (E.164 digits without +) and request code via /pair-code.
  4. Confirm /status reports connected.

Settings

  • pairingMode: qr or code.
  • pairingPhoneNumber: E.164 digits without + (used for code mode).
  • allowedSenders: allowed WhatsApp JIDs or E.164 digits.
  • agentSystemPrompt: system prompt for replies.
  • historyTurnLimit: persisted turn window (default 40).
  • dedupeRetentionDays: replay-protection retention window for inbound message IDs (default 7 days). Rows older than this are pruned lazily whenever a new inbound message is processed.

Routes

  • GET /api/plugins/fusion-plugin-whatsapp-chat/status
  • GET /api/plugins/fusion-plugin-whatsapp-chat/qr
  • POST /api/plugins/fusion-plugin-whatsapp-chat/pair-code
  • POST /api/plugins/fusion-plugin-whatsapp-chat/logout

Storage and lifecycle

  • Starts socket on onLoad, stops on onUnload.
  • Persists transcript and dedupe state in:
    • whatsapp_chat_sessions
    • whatsapp_chat_dedupe
  • Persists Baileys auth state in:
    • whatsapp_auth_creds
    • whatsapp_auth_keys
  • After restart, plugin reconnects automatically when auth is valid.

Troubleshooting

  • Stuck awaiting-qr: fetch a fresh QR and scan promptly.
  • loggedOut: call /logout (or wait for clear) and re-pair.
  • Pair code not generated: ensure pairingPhoneNumber is E.164 digits without +.
  • No replies: check allowedSenders; empty list blocks all inbound messages by design.

Compliance warning

Baileys is an unofficial WhatsApp Web protocol client. Use may violate WhatsApp Terms of Service. This plugin is intended for self-hosted, single-user use at your own risk.