stage-13: WhatsApp bridge with Baileys + Python adapter

Node.js bridge (bridge/whatsapp/): Baileys client with Express HTTP API
on localhost:8098 — QR code linking, message queue, reconnection logic.

Python adapter (src/adapters/whatsapp.py): polls bridge every 2s, routes
through router.py, separate whatsapp.owner/admins auth, security logging.

Integrated in main.py alongside Discord + Telegram via asyncio.gather.
CLI: echo whatsapp status/qr. 442 tests pass (32 new, zero failures).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MoltBot Service
2026-02-13 21:41:16 +00:00
parent 2d8e56d44c
commit 80502b7931
12 changed files with 3636 additions and 2 deletions

View File

@@ -118,6 +118,14 @@ def main():
else:
logger.info("No telegram_token — Telegram bot disabled")
# WhatsApp adapter (optional — only if whatsapp is enabled in config)
whatsapp_enabled = config.get("whatsapp", {}).get("enabled", False)
whatsapp_bridge_url = config.get("whatsapp", {}).get("bridge_url", "http://127.0.0.1:8098")
if whatsapp_enabled:
logger.info("WhatsApp adapter configured (bridge: %s)", whatsapp_bridge_url)
else:
logger.info("WhatsApp adapter disabled")
# PID file
PID_FILE.write_text(str(os.getpid()))
@@ -133,7 +141,7 @@ def main():
signal.signal(signal.SIGINT, handle_signal)
async def _run_all():
"""Run Discord + Telegram bots concurrently."""
"""Run Discord + Telegram + WhatsApp bots concurrently."""
tasks = [asyncio.create_task(client.start(token))]
if telegram_app:
async def _run_telegram():
@@ -149,6 +157,14 @@ def main():
await telegram_app.stop()
await telegram_app.shutdown()
tasks.append(asyncio.create_task(_run_telegram()))
if whatsapp_enabled:
from src.adapters.whatsapp import run_whatsapp, stop_whatsapp
async def _run_whatsapp():
try:
await run_whatsapp(config, whatsapp_bridge_url)
except asyncio.CancelledError:
stop_whatsapp()
tasks.append(asyncio.create_task(_run_whatsapp()))
await asyncio.gather(*tasks)
try: