Skip to content

fix(whatsapp-gateway): self-chat E2EE, agent UUID resolution, auto-connect#454

Open
Shuichi-code wants to merge 1 commit intoRightNow-AI:mainfrom
Shuichi-code:fix/whatsapp-gateway-improvements
Open

fix(whatsapp-gateway): self-chat E2EE, agent UUID resolution, auto-connect#454
Shuichi-code wants to merge 1 commit intoRightNow-AI:mainfrom
Shuichi-code:fix/whatsapp-gateway-improvements

Conversation

@Shuichi-code
Copy link

@Shuichi-code Shuichi-code commented Mar 8, 2026

Summary

Fixes multiple issues preventing the WhatsApp Web gateway from properly receiving and replying to messages through OpenFang:

  • Upgrade Baileys v6 → v7.0.0-rc.9 — Fixes "Waiting for this message" E2EE decryption errors when using self-chat (Notes to Self). Baileys v6 lacks proper multi-device self-chat E2EE support.
  • Add getMessage callback with in-memory message store — Required by Baileys v7 for E2EE decryption of self-sent messages on linked devices.
  • Resolve agent name → UUID at startup — Calls GET /api/agents to map human-readable agent names (e.g. "assistant") to UUIDs, fixing "Invalid agent ID" errors from the OpenFang API.
  • Auto-connect on startup — If auth_store/creds.json exists from a previous session, automatically reconnects to WhatsApp without requiring POST /login/start. Essential since the OpenFang daemon spawns the gateway as a child process.
  • Handle WhatsApp LID JIDs — Converts privacy-preserving @lid JIDs to @s.whatsapp.net for proper message delivery.
  • Support self-chat (Notes to Self) — Accepts fromMe messages and routes replies to the account owner's JID instead of the LID.
  • Quote original message in replies — Provides E2EE context for message decryption on linked devices.
  • File-based logging — Writes to gateway.log since the OpenFang daemon captures stdout, making debugging difficult.

Test plan

  • Fresh QR code scan connects successfully with Baileys v7
  • Auto-reconnects on startup when auth_store/creds.json exists
  • Agent name resolves to UUID via /api/agents endpoint
  • Incoming messages from other users are forwarded to OpenFang and replies sent back
  • Self-chat messages (Notes to Self) are forwarded and replied to without "Waiting for this message" errors
  • Messages from LID JIDs are properly converted and delivered
  • gateway.log is written with timestamped entries

…nnect

- Upgrade Baileys from v6 to v7.0.0-rc.9 for proper multi-device
  self-chat E2EE support (fixes "Waiting for this message" errors)
- Add getMessage callback with in-memory message store for E2EE
  decryption of self-sent messages
- Resolve agent name to UUID at startup via GET /api/agents, fixing
  "Invalid agent ID" errors when forwarding messages
- Auto-connect to WhatsApp on startup if saved session (creds.json)
  exists, removing dependency on POST /login/start
- Handle WhatsApp LID JIDs (@lid) by converting to @s.whatsapp.net
  for proper message delivery
- Accept fromMe messages to support "Notes to Self" chat mode
- Route self-sent message replies to account owner's JID
- Quote original message in replies for E2EE context
- Add file-based logging (gateway.log) since daemon captures stdout

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant