scripts/whatsapp-bridge: support phone-number pairing via Baileys requestPairingCode - #45585
scripts/whatsapp-bridge: support phone-number pairing via Baileys requestPairingCode#45585thamam wants to merge 1 commit into
Conversation
…uestPairingCode Adds an opt-in --pair-phone=<E.164> flag to scripts/whatsapp-bridge/bridge.js that switches first-time pairing from QR scan to WhatsApp phone-number pairing code (8 chars). QR mode remains the default — no behaviour change for existing installs. Motivation: pairing a remote EC2-hosted Hermes agent via QR over SSH/journal is awkward; Baileys exposes the native alternative via sock.requestPairingCode(). See PR body for full details.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
WhatsApp bridge now supports phone-number pairing via Baileys requestPairingCode as an alternative to QR scanning. When --pair-phone is supplied and the session is not yet registered, an 8-char code is requested and displayed in the terminal for entry on the phone. QR display is suppressed when phone pairing is used. Clean opt-in feature addition.
Reviewed by Hermes Agent
…uestPairingCode Adds an opt-in --pair-phone=<E.164> flag to scripts/whatsapp-bridge/bridge.js that switches first-time pairing from QR scan to WhatsApp phone-number pairing code (8 chars). QR mode remains the default — no behaviour change for existing installs. Motivation: pairing a remote EC2-hosted Hermes agent via QR over SSH/journal is awkward; Baileys exposes the native alternative via sock.requestPairingCode(). See PR body for full details. # Status: requires-upstream-merge # Tracks: NousResearch#45585 # Note: collaborator called PR NousResearch#45585 a duplicate of upstream PR NousResearch#17907; # either landing on upstream main causes the auto-drop probe to succeed # and this patch is removed from the series next cycle. # Tests-that-must-pass-without-patch: # tests/scripts/whatsapp-bridge/test_pair_phone.py
…uestPairingCode Adds an opt-in --pair-phone=<E.164> flag to scripts/whatsapp-bridge/bridge.js that switches first-time pairing from QR scan to WhatsApp phone-number pairing code (8 chars). QR mode remains the default — no behaviour change for existing installs. Motivation: pairing a remote EC2-hosted Hermes agent via QR over SSH/journal is awkward; Baileys exposes the native alternative via sock.requestPairingCode(). See PR body for full details. # Status: requires-upstream-merge # Tracks: NousResearch#45585 # Note: collaborator called PR NousResearch#45585 a duplicate of upstream PR NousResearch#17907; # either landing on upstream main causes the auto-drop probe to succeed # and this patch is removed from the series next cycle. # Tests-that-must-pass-without-patch: # tests/scripts/whatsapp-bridge/test_pair_phone.py
teknium1
left a comment
There was a problem hiding this comment.
Thanks for adding an opt-in alternative to QR pairing. The underlying capability remains absent from current main, but this version needs updates for the current bridge and onboarding contracts.
Problems
--pair-phone=<E.164>cannot activate this implementation:getArg()only accepts separate--name valuetokens atscripts/whatsapp-bridge/bridge.js:50-52, while the PR's newPAIR_PHONEdeclaration uses it for the documented equals form.- Current dashboard onboarding launches
--pair-jsonathermes_cli/web_server.py:7151-7159and discards non-JSON output athermes_cli/web_server.py:7195-7198. The added pairing code is plain console output, and the watcher has no code-event branch (hermes_cli/web_server.py:7204-7224). - The PR changes only
bridge.js; no regression coverage is included for argument parsing, request timing, or the JSON onboarding protocol.
Suggested changes
- Accept and validate the documented flag syntax, with a test proving the normalized number reaches
requestPairingCode(). - Salvage onto the current onboarding flow: retain QR by default, add an explicit phone-pairing input path, and emit/consume a structured pairing-code event.
Automated hermes-sweeper review.
| const PAIR_ONLY = args.includes('--pair-only'); | ||
| // Opt-in: when --pair-phone=<E.164> is supplied AND the session is not yet | ||
| // registered, request an 8-char pairing code from Baileys instead of | ||
| // displaying a QR. Phone is sanitised to digits-only so "+972 55 921 1263", |
There was a problem hiding this comment.
getArg() only finds a separate --pair-phone token followed by its value (scripts/whatsapp-bridge/bridge.js:50-52). The documented --pair-phone=<E.164> form is one token, so this evaluates to an empty string and the phone-pairing branch never runs. Please parse the equals form or document/test the supported syntax consistently.
What
Adds an opt-in
--pair-phone=<E.164>flag toscripts/whatsapp-bridge/bridge.jsthat switches first-time pairing from QR scan to WhatsApp's phone-number pairing code (8 chars, entered on the phone in WhatsApp → Settings → Linked Devices → "Link with phone number"). QR mode remains the default — no behaviour change for existing installs.Why
QR scanning requires the operator to physically scan a code from the new device's WhatsApp. For headless server installs (e.g. EC2-hosted agents) this is awkward — the operator has to copy the QR image off the journal, render it large enough to scan, etc. Phone-pairing code is the documented native alternative in WhatsApp Web (and supported by Baileys via
sock.requestPairingCode()); it's just a string emitted to stdout that the operator types into the phone.This came up while wiring a second Hermes agent ("Sentinel") with a dedicated WhatsApp number on a remote EC2 box. Pasting a QR through three layers of SSH/journal was clearly the wrong shape; the bridge already uses Baileys, which exposes the API directly.
How
--pair-phone=<E.164>(digits-and-+ tolerated; sanitised to digits-only before passing to Baileys).makeWASocketreturns and creds aren't yet registered, request a pairing code viasock.requestPairingCode(phoneNumber)on next tick (~3s — empirically the smallest delay that's race-free across Node event-loop versions on first-boot Ubuntu 24.04 with fresh Baileys).XXXX-XXXXplus a short "enter on phone" instruction.connection.updatehandler when--pair-phoneis set (Baileys emits both paths until creds save; QR is noise here).Backward compatibility
--pair-phoneis opt-in. Existing scripts that don't pass it get the unchanged QR flow.--pair-onlystill works the same; it just exits cleanly after pairing in either mode.requestPairingCodeis already in Baileys (the version pinned inpackage.jsonsupports it).Testing
Verified on Ubuntu 24.04 / Node 20, Baileys at
WhiskeySockets/Baileys#01047debd81beb20da7b7779b08edcb06aa03770(the pinned commit):Code prints; entering it on a phone with no existing WhatsApp Web sessions pairs the bridge cleanly;
--pair-onlycauses a clean exit aftercreds.updateflush. Subsequent run without--pair-phone(in normal serve mode) reuses the same session and connects without re-pairing.QR path retested by running without the flag against a fresh session — identical to current behaviour, no regression.
Out of scope
Maintainer notes for this PR (delete before opening)
whatsapp-bridge-pair-phonemainofNousResearch/hermes-agentdanaharari@gmail.com/ "Doc"hermes update; then we install nodejs/npm + npm install in the bridge dir + runnode bridge.js --pair-only --pair-phone=972559211263 --mode=botand proceed with the rest of ADR-0005How Doc opens the PR (no gh CLI on Mac)
NousResearch/hermes-agentvia the GitHub web UI (top-right Fork button)git@github.com:danaharari/hermes-agent.git)whatsapp-bridge-pair-phone, apply this diff, commit as Doc, push to the forkOr — quicker — Doc can
brew install gh, dogh auth login, then I do all of steps 2-5 with one command (gh repo fork ... --clone && cd hermes-agent && git checkout -b whatsapp-bridge-pair-phone && git apply ../whatsapp-bridge-pair-phone.diff && git commit -am '...' && git push -u origin HEAD && gh pr create -f).