Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(baileys): trim the pairing-code guard notes
Yudhi Armyndharise3c45bbc0a2e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex af95f642b..5f8f08cb6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,11 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed-- Baileys: requesting a pairing code in the first second or two after `POST /sessions/{id}/start` returns the- documented 409 instead of a 500 with a `Connection Closed` stack trace. The socket object exists before its- WebSocket has finished connecting, so the send threw a raw Boom 428; the request is now gated on the session- reaching `qr_ready`, the same guard the whatsapp-web.js engine already carried. Clients that retry on 409 ride- through the window instead of surfacing an error.+- Baileys: requesting a pairing code before the session reaches `qr_ready` answers the documented 409 instead+ of a 500 with a `Connection Closed` stack trace, the same guard the whatsapp-web.js engine already carried.+ Thanks @m7fz7.## [0.23.2] - 2026-08-23diff --git a/docs/examples/session-phone-number-pairing.md b/docs/examples/session-phone-number-pairing.mdindex d47061b90..5a50a8106 100644--- a/docs/examples/session-phone-number-pairing.md+++ b/docs/examples/session-phone-number-pairing.md@@ -15,6 +15,9 @@ This flow returns an 8-character pairing code that the user enters in WhatsApp o[Start Session]│▼+[Wait for status qr_ready]+ │+ ▼[Request Pairing Code]│▼@@ -44,9 +47,7 @@ curl -X POST http://localhost:2785/api/sessions/{sessionId}/start \-H "X-API-Key: $API_KEY"```-The session must be started before requesting a pairing code, and the engine needs a moment to-connect after `start` returns. Poll `GET /api/sessions/{sessionId}` until `status` is `qr_ready` —-that is the point the engine can accept a pairing request. Asking earlier returns 409.+The session must be started before requesting a pairing code, and the engine needs a moment to connect after `start` returns. Poll `GET /api/sessions/{sessionId}` until `status` is `qr_ready`: that is the point the engine can accept a pairing request. Requesting a code before that returns 409.## 3. Request a Pairing Codediff --git a/src/engine/adapters/baileys-lifecycle.ts b/src/engine/adapters/baileys-lifecycle.tsindex 49f384611..1754c9357 100644--- a/src/engine/adapters/baileys-lifecycle.ts+++ b/src/engine/adapters/baileys-lifecycle.ts@@ -763,14 +763,11 @@ export class BaileysLifecycle {}/**- * Gated on QR_READY, not on the socket merely existing — the same guard, for the same reason, as- * the whatsapp-web.js engine's requestPairingCode. `this.sock` is assigned the moment- * makeWASocket returns, seconds before the WebSocket finishes connecting, and Baileys' sendNode- * throws a raw Boom 428 ('Connection Closed') whenever `ws.isOpen` is false — which surfaced as a- * 500 with a stack trace on every cold-start pairing request. QR_READY is exactly the window this- * can work in: it is set from the `connection.update { qr }` event, which WhatsApp only sends- * once the noise handshake is done, and every transient close drops the status back to- * INITIALIZING for the reconnect, so it also covers a socket that died after a QR was published.+ * Gated on QR_READY, not on the socket merely existing: `this.sock` is assigned the moment makeWASocket+ * returns, before the WebSocket is open, and Baileys' sendNode throws a raw Boom 428 until it is. QR_READY+ * is set from the post-handshake `connection.update { qr }` event and every close drops it, so it is the+ * exact window a pairing request can succeed in. Same guard, for the same reason, as the whatsapp-web.js+ * engine's requestPairingCode.*/async requestPairingCode(phoneNumber: string): Promise<string> {if (!this.sock || this.status !== EngineStatus.QR_READY) {