Skip to content

fix(whatsapp): honor proxy env vars during pairing - #43659

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/whatsapp-proxy-pairing
Closed

fix(whatsapp): honor proxy env vars during pairing#43659
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/whatsapp-proxy-pairing

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

What does this PR do?

Teach the WhatsApp bridge to honor standard HTTPS_PROXY / HTTP_PROXY environment variables when Baileys opens its WebSocket connection. In proxied environments this lets pairing reach the QR-code step instead of looping on disconnect reason 408 before the bridge is usable.

Related Issue

Fixes #43603

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • scripts/whatsapp-bridge/bridge.js: pass proxy-derived socket options into makeWASocket() so Baileys uses proxy env vars during pairing and reconnect.
  • scripts/whatsapp-bridge/proxy.js: add a narrow helper that resolves HTTPS_PROXY / https_proxy before HTTP_PROXY / http_proxy and lazily constructs the proxy agent.
  • scripts/whatsapp-bridge/proxy.test.mjs: cover proxy env precedence and agent wiring without needing a live WhatsApp session.
  • scripts/whatsapp-bridge/package.json: add the direct https-proxy-agent dependency the bridge now uses at runtime.
  • scripts/whatsapp-bridge/package-lock.json: lock the new bridge dependency and its transitive packages for repo-local installs.

How to Test

  1. Run npm install --prefix scripts/whatsapp-bridge.
  2. Run node --test scripts/whatsapp-bridge/allowlist.test.mjs scripts/whatsapp-bridge/proxy.test.mjs.
  3. In a proxied environment, export HTTPS_PROXY=http://proxy.example:3128 (or one of the lowercase / HTTP variants) and start the WhatsApp pairing flow; verify it reaches the QR-code step instead of repeating Connection closed (reason: 408). Reconnecting in 3s....
  4. Run /opt/homebrew/bin/timeout -k 30 480 sh -c 'pytest tests/ -q -x --timeout=60 "$@"' sh to exercise the repo test suite. In my local shared environment this aborted during collection because fastapi is missing (tests/hermes_cli/test_dashboard_auth_401_reauth.py), so CI or a fully provisioned local env should cover the Python suite.

What platforms tested on

  • macOS darwin-arm64
  • Node.js v26.0.0 for the bridge regression tests

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS darwin-arm64, Node.js v26.0.0

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

  • node --test scripts/whatsapp-bridge/allowlist.test.mjs scripts/whatsapp-bridge/proxy.test.mjs passed locally.
  • The required broad pytest command aborted during collection with ModuleNotFoundError: No module named 'fastapi' in tests/hermes_cli/test_dashboard_auth_401_reauth.py before it reached any WhatsApp bridge code.

@konsisumer
konsisumer requested a review from a team June 10, 2026 17:01
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels Jun 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #43607 — same fix for #43603 (pass HTTPS_PROXY/HTTP_PROXY-derived agent into Baileys makeWASocket via https-proxy-agent), touching the same bridge files. #43607 was filed earlier the same day. Related: older proxy-support PR #12787.

@konsisumer

Copy link
Copy Markdown
Contributor Author

Closing — this PR was labeled duplicate, taking that as a maintainer signal to stop. If that's incorrect, feel free to reopen and remove the label.

@austinpickett

Copy link
Copy Markdown
Collaborator

Closing in favour of #43822 (kyssta-exe), which the team is using as the canonical proxy implementation for this feature cluster.

Why #43822 was preferred over this PR:

  • This PR extracts proxy logic into a separate proxy.js module (5 files, 130+ additions) — that's over-engineered for what is essentially a ~10-line env-var read + agent construction
  • The inline approach in fix(whatsapp): add HTTPS proxy support for Baileys WebSocket (#43603) #43822 keeps the change reviewable in a single diff hunk and is easier for contributors to understand
  • proxy.js adds an abstraction boundary that doesn't buy meaningful testability here since the env-var read is trivial

The package-lock.json update is good, but will be regenerated after the canonical PR merges.

Thank you for the thorough implementation — the modular approach would make more sense if proxy config gained more complexity down the road! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WhatsApp pairing fails behind HTTP(S) proxy with repeated 408 disconnects

3 participants