Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(session): name the closing-socket window in the pairing 409
Yudhi Armyndharis9f7b228a8856
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex d8c9f5ffb..53c67c771 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -719,7 +719,7 @@ Request an 8-char pairing code to link via phone number (alternative to QR).`status` is the lowercase session status.-**Errors:** `400` validation, or session not started, or already authenticated · `401` · `403` · `404` not found · `409` session not waiting to be linked yet; wait for `status` to read `qr_ready` and retry (after a code was accepted, wait for `ready` instead)+**Errors:** `400` validation, or session not started, or already authenticated · `401` · `403` · `404` not found · `409` session not waiting to be linked yet; wait for `status` to read `qr_ready` and retry (after a code was accepted, wait for `ready` instead). On Baileys a session that already reads `qr_ready` can still answer `409` while its socket is closing, for up to the WebSocket close timeout (30 s); that is retryable and the status follows shortly.#### POST /api/sessions/:sessionId/presence/subscribediff --git a/docs/examples/session-phone-number-pairing.md b/docs/examples/session-phone-number-pairing.mdindex e9780f349..f3aa06c1e 100644--- a/docs/examples/session-phone-number-pairing.md+++ b/docs/examples/session-phone-number-pairing.md@@ -47,7 +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. Requesting a code before that 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. Treat `qr_ready` as the signal to try, not a guarantee: on Baileys the socket can already be closing while the status has not caught up, so a 409 is still possible for a few seconds and is worth one retry.## 3. Request a Pairing Code@@ -95,6 +95,6 @@ After the code is accepted, the OpenWA session should move to a connected/ready- If OpenWA returns `Session is not started`, call `POST /api/sessions/{sessionId}/start` first.- If OpenWA returns `Session is already authenticated`, the account is already linked and no pairing code is needed.-- If OpenWA returns 409 `Session is not waiting to be linked`, the engine is still connecting (or reconnecting after a drop). Wait for `status` to read `qr_ready` and request again. After a code was accepted the same 409 is answered until the session is `ready`; do not request another code then.+- If OpenWA returns 409 `Session is not waiting to be linked`, the engine is still connecting (or reconnecting after a drop). Wait for `status` to read `qr_ready` and request again. After a code was accepted the same 409 is answered until the session is `ready`; do not request another code then. On Baileys the same 409 can also answer while `status` already reads `qr_ready`, for as long as the WebSocket takes to finish closing (up to 30 s on a silently dropped connection); retry rather than treating it as a bad state.- If the phone number is rejected, send digits only in international format, without `+`, spaces, or punctuation.- If you want to create a brand-new WhatsApp account programmatically, that is outside OpenWA's scope. OpenWA only links an existing WhatsApp account.diff --git a/openapi.json b/openapi.jsonindex 801872601..15c905355 100644--- a/openapi.json+++ b/openapi.json@@ -818,7 +818,7 @@"description": "Session not found"},"409": {- "description": "The session is not waiting to be linked: the engine is still connecting, or reconnecting after a drop, so the request never reached WhatsApp. Wait for `status` to read `qr_ready` and retry. Once a code has been accepted the session moves through `authenticating` and `initializing` to `ready` and answers this until then; wait for `ready` in that case. A session that reads `ready` is already linked and answers `400` instead."+ "description": "The session is not waiting to be linked: the engine is still connecting, or reconnecting after a drop, so the request never reached WhatsApp. Wait for `status` to read `qr_ready` and retry. Once a code has been accepted the session moves through `authenticating` and `initializing` to `ready` and answers this until then; wait for `ready` in that case. A session that reads `ready` is already linked and answers `400` instead. One window answers this while the session still reads `qr_ready`: on the Baileys engine a socket that has begun closing stops accepting a pairing request before the status catches up, which on a silently dropped connection takes until the WebSocket's close timeout (30 s); retry, and the status follows shortly."}},"summary": "Request an 8-char pairing code to link via phone number (alternative to QR)",diff --git a/src/common/openapi/engine-status-responses.ts b/src/common/openapi/engine-status-responses.tsindex 4b40228b9..b2c48d487 100644--- a/src/common/openapi/engine-status-responses.ts+++ b/src/common/openapi/engine-status-responses.ts@@ -26,13 +26,22 @@ export const ENGINE_NOT_READY_409 =* `EngineNotReadyError` (409) on `POST /sessions/:sessionId/pairing-code`, where the generic wording* above points the caller at the wrong state: both engines accept a pairing request only while the* session is `qr_ready`, and a session that reads `ready` is already linked and answers `400`.+ *+ * `qr_ready` is necessary but not sufficient on Baileys, hence the closing-socket sentence: the guard+ * also tests `ws.isOpen`, and the status trails the transport because Baileys emits its close only+ * after `await ws.close()` resolves. Same shape as the reload window ENGINE_NOT_READY_409 names, and+ * for the same reason: a caller that treats the documented status as sufficient would otherwise read+ * a legitimate retryable 409 as a bad state.*/export const PAIRING_NOT_READY_409 ='The session is not waiting to be linked: the engine is still connecting, or reconnecting after a ' +'drop, so the request never reached WhatsApp. Wait for `status` to read `qr_ready` and retry. Once a ' +'code has been accepted the session moves through `authenticating` and `initializing` to `ready` and ' +'answers this until then; wait for `ready` in that case. A session that reads `ready` is already ' +- 'linked and answers `400` instead.';+ 'linked and answers `400` instead. One window answers this while the session still reads ' ++ '`qr_ready`: on the Baileys engine a socket that has begun closing stops accepting a pairing ' ++ 'request before the status catches up, which on a silently dropped connection takes until the ' ++ "WebSocket's close timeout (30 s); retry, and the status follows shortly.";/*** The catalog and status services pass a `NotFoundException` factory to `EngineRegistry.require()`