fix(whatsapp-bridge): implement dynamic WhatsApp version resolution - #73795
fix(whatsapp-bridge): implement dynamic WhatsApp version resolution#73795lucaslokchan wants to merge 3 commits into
Conversation
- Added a new function `resolveWaVersion` to fetch the latest WhatsApp Web version and fallback to the latest Baileys version if necessary. - Updated the `startSocket` function to utilize the new version resolution logic, ensuring compatibility with the latest WhatsApp features.
e91911d to
93d612b
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused pairing fix. Current main still obtains the socket version through fetchLatestBaileysVersion() at scripts/whatsapp-bridge/bridge.js:398, so this is not already implemented in Hermes.
Problems
- The new resolver branch at
scripts/whatsapp-bridge/bridge.js:396-402has no executable regression test; the current bridge tests do not reference either version helper, andgh pr checks 73795reports no checks. - This intentionally prefers the live WhatsApp Web revision. In the linked upstream discussion, a Baileys maintainer warns that this can diverge from the protocol revision Baileys has validated; upstream PR #2728 instead updated the revision used by the existing helper.
Suggested changes
- Extract and directly test the resolver's live-success and Baileys-fallback paths; avoid source-text tests.
- Add rationale for choosing the live-Web source over the upstream-maintained version source, or narrow the change to the upstream-approved path.
Automated hermes-sweeper review.
| if (waWeb.isLatest && !waWeb.error) { | ||
| return waWeb.version; | ||
| } | ||
| return (await fetchLatestBaileysVersion()).version; |
There was a problem hiding this comment.
Please add executable coverage for this fallback path as well as the isLatest live-version path. The bridge starts side effects at module load, so extract this resolver to a pure helper and test the helper directly rather than adding a source-text contract.
There was a problem hiding this comment.
Addressed the test feedback in commit d993dbe412841f49e36942604729cb2e6cf6e52b:
-
Moved resolveWaVersion to bridge_helpers.js (DI for the two fetch functions)
-
Added tests for live-success and both Baileys-fallback paths in bridge.native.test.mjs
-
All bridge Node tests pass locally
- Moved the `resolveWaVersion` function to `bridge_helpers.js` for better modularity. - Updated `startSocket` to utilize the new `resolveWaVersion` function, passing the appropriate fetch functions. - Added tests for `resolveWaVersion` to ensure correct behavior for live version retrieval and fallback scenarios.
What does this PR do?
Fixes WhatsApp bridge pairing failures caused by a stale WA Web protocol version.
startSocket() in scripts/whatsapp-bridge/bridge.js previously resolved the version only via fetchLatestBaileysVersion(). When WhatsApp bumps their Web client version, the Baileys-packaged version can lag. WhatsApp then rejects the WebSocket handshake with HTTP 405 (Method Not Allowed), and the bridge reconnects in a loop without completing QR pairing.
This PR adds resolveWaVersion() which prefers fetchLatestWaWebVersion() (live WhatsApp Web version) and falls back to fetchLatestBaileysVersion() if the live fetch fails. This matches the upstream Baileys workaround (#2731) and fixes #73700.
resolveWaVersionto fetch the latest WhatsApp Web version and fallback to the latest Baileys version if necessary.startSocketfunction to utilize the new version resolution logic, ensuring compatibility with the latest WhatsApp features.Related Issue
Fixes #73700
Upstream: WhiskeySockets/Baileys#2731
Type of Change
Changes Made
How to Test
rm -rf ~/.hermes/platforms/whatsapp/sessionconnectedafter scancurl http://127.0.0.1:<bridge-port>/healthreturns"status": "connected"Before:
⚠️ Connection closed (reason: 405). Reconnecting in 3s...— pairing never completes.After: bridge connects and pairing completes normally.