← Back to PRs

#21837: feat(whatsapp): add HTTP_PROXY/HTTPS_PROXY support for Baileys WebSocket

by jasonchen-lab open 2026-02-20 12:46 View on GitHub →
channel: whatsapp-web size: XS
## Summary Baileys WebSocketClient does not automatically use `HTTP_PROXY`/`HTTPS_PROXY`. When running in restricted regions (e.g. behind firewall) where Meta endpoints are unreachable, the connection fails with ETIMEDOUT/408. ## Changes - Pass `HttpsProxyAgent` to `makeWASocket` when `HTTP_PROXY` or `HTTPS_PROXY` is set - Set `connectTimeoutMs` to 60s to accommodate slower proxy connections ## Usage Set `HTTP_PROXY` or `HTTPS_PROXY` (e.g. `http://127.0.0.1:8080`) before starting the gateway. The WhatsApp Baileys connection will route through the proxy. ## Testing Verified on a server in a restricted region: WhatsApp WebSocket successfully connects via local HTTP proxy (sing-box) to Meta endpoints. Made with [Cursor](https://cursor.com) <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds HTTP/HTTPS proxy support for WhatsApp WebSocket connections via Baileys by passing `HttpsProxyAgent` when `HTTP_PROXY` or `HTTPS_PROXY` environment variables are set. - Imports `HttpsProxyAgent` from `https-proxy-agent` package (already present in dependencies) - Reads proxy URL from `HTTPS_PROXY` or `HTTP_PROXY` environment variables - Conditionally passes agent to `makeWASocket` when proxy is configured - Sets `connectTimeoutMs` to 60 seconds for proxy connections <h3>Confidence Score: 3/5</h3> - This PR is safe to merge with one logic fix needed - The implementation correctly adds proxy support, but unintentionally changes the connection timeout for all users (not just those using proxies), which could affect existing behavior - Pay close attention to `src/web/session.ts` line 121-126 - the timeout change affects all users <sub>Last reviewed commit: 4cb65bb</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs