Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(docker): ship the Baileys app-state patcher, and derive the list that lost it
Yudhi Armyndharise09e2c19dd24
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 06aa50099..63f1c73a0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- **The published image now actually carries the app-state resync fix** — the patcher that bounds the loop was wired into the install hook but never added to the two hand-written lists in the Dockerfile, so it was absent from the production stage, the hook's existence check skipped it without a word, and every image shipped unpatched. It is copied and run fatally now, and a derived check fails the build if a patcher is ever added to one list and not the other.- **A channel refusal answers `403` again, not a bare `500`** — narrowing the refusal classifier in the same release fixed the IQ error channel and silently de-classified the other one: WhatsApp's `w:mex` surface reports a refusal as a GraphQL error inside a _successful_ IQ, so it never carries the numeric code the classifier now reads, and deleting or muting a channel the account does not own regressed from `403` to an opaque `500`. The two error channels are decoded separately now; a dead socket and an unanswered query still do not read as refusals.- **A profile picture lookup that WhatsApp never answered no longer reads as "this contact has no picture"** — the route answered `200` with `url: null` after a silent minute, which is the same answer a contact without a picture gives, so a caller had no way to tell them apart; it now answers `503`. Passing the engine's own timeout would not have been enough on its own, because the resulting error landed in the catch that produces that same `null`. The batch lookup is unchanged: a per-id failure there is documented as `null` and stays that way.- **The last fifteen writes that reported success without confirmation now report it** — the addressbook saves, block and unblock, the archive/unread/clear/delete chat actions, delete-for-me and star, the four label writes and a call rejection all go through an engine call that discards its own result, so each answered `200` whether WhatsApp applied the change or never replied; a rejected call was the sharpest case, since the gateway also published a `rejected` outcome for a rejection nothing had acknowledged. All now share the request budget and answer `503` when no confirmation arrives.diff --git a/Dockerfile b/Dockerfileindex effea591d..60657795c 100644--- a/Dockerfile+++ b/Dockerfile@@ -120,15 +120,19 @@ COPY package*.json ./# scripts/postinstall.js rides along: `npm ci` below runs the hook, which fails# when the file is missing. With the patcher present the hook applies it in# --best-effort mode; the explicit fatal run right after is the real gate.-COPY scripts/postinstall.js scripts/patch-wwebjs-201832.js scripts/wwebjs-201832.patch scripts/patch-wwebjs-newsletter-preview.js scripts/patch-wwebjs-status.js scripts/patch-wwebjs-ready-sync.js ./scripts/+COPY scripts/postinstall.js scripts/patch-wwebjs-201832.js scripts/wwebjs-201832.patch scripts/patch-wwebjs-newsletter-preview.js scripts/patch-wwebjs-status.js scripts/patch-wwebjs-ready-sync.js scripts/patch-baileys-appstate.js ./scripts/# Install production dependencies only, then apply the backports. The status patcher runs after# the two patchers it depends on: its transforms were written against the tree they leave behind.+# scripts/dockerfile-patchers.spec.js derives this list from scripts/patch-*.js and fails if a+# patcher is added without being copied AND run here — a hand-written list loses one silently, and+# the Baileys one shipped in postinstall for a whole release without ever reaching the image.RUN npm ci --omit=dev \&& node scripts/patch-wwebjs-201832.js \&& node scripts/patch-wwebjs-newsletter-preview.js \&& node scripts/patch-wwebjs-status.js \&& node scripts/patch-wwebjs-ready-sync.js \+ && node scripts/patch-baileys-appstate.js \&& npm cache clean --force# Replace the npm the base image bundles. npm is not on the request path — the entrypoint runsdiff --git a/package.json b/package.jsonindex 759c5c0e3..4e8048b0d 100644--- a/package.json+++ b/package.json@@ -35,7 +35,7 @@"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"","lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test": "jest",- "test:scripts": "node --test scripts/postinstall.spec.js scripts/patch-wwebjs-newsletter-preview.spec.js scripts/patch-wwebjs-status.spec.js scripts/patch-wwebjs-ready-sync.spec.js scripts/patch-baileys-appstate.spec.js",+ "test:scripts": "node --test scripts/postinstall.spec.js scripts/patch-wwebjs-newsletter-preview.spec.js scripts/patch-wwebjs-status.spec.js scripts/patch-wwebjs-ready-sync.spec.js scripts/patch-baileys-appstate.spec.js scripts/dockerfile-patchers.spec.js","test:watch": "jest --watch","test:cov": "jest --coverage","test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",diff --git a/scripts/dockerfile-patchers.spec.js b/scripts/dockerfile-patchers.spec.jsnew file mode 100644index 000000000..79c938c76--- /dev/null+++ b/scripts/dockerfile-patchers.spec.js@@ -0,0 +1,46 @@+'use strict';++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('fs');+const path = require('path');++/**+ * The Dockerfile hand-lists the patchers it copies into the production stage and the ones it runs+ * fatally afterwards. A hand-written list silently loses a patcher added later: the file is absent+ * from the image, postinstall's fs.existsSync guard skips it without a word, and the fix it carries+ * never reaches the published image. That is exactly what happened to the Baileys app-state+ * patcher, which shipped in postinstall and was never added here.+ *+ * Derive the set instead of restating it.+ */+const ROOT = path.join(__dirname, '..');+const dockerfile = fs.readFileSync(path.join(ROOT, 'Dockerfile'), 'utf8');++const patchers = fs+ .readdirSync(__dirname)+ .filter(f => f.startsWith('patch-') && f.endsWith('.js') && !f.endsWith('.spec.js'))+ .sort();++test('the fixture finds the patchers at all', () => {+ // Guard the guard: an empty list would make every assertion below vacuously pass.+ assert.ok(patchers.length >= 5, `expected several patchers, found ${patchers.length}`);+});++test('every patcher is COPIED into the production stage', () => {+ const missing = patchers.filter(p => !dockerfile.includes(`scripts/${p}`));+ assert.deepEqual(missing, [], `not copied into the image: ${missing.join(', ')}`);+});++test('every patcher is RUN fatally after npm ci', () => {+ // The postinstall hook runs them --best-effort; the explicit run is the real gate, so a shape+ // change fails the image build instead of shipping unpatched.+ const missing = patchers.filter(p => !dockerfile.includes(`node scripts/${p}`));+ assert.deepEqual(missing, [], `never run in the image build: ${missing.join(', ')}`);+});++test('every patcher is also wired into postinstall', () => {+ const postinstall = fs.readFileSync(path.join(__dirname, 'postinstall.js'), 'utf8');+ const missing = patchers.filter(p => !postinstall.includes(p));+ assert.deepEqual(missing, [], `not wired into postinstall: ${missing.join(', ')}`);+});