Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs: correct four claims this branch got wrong

Yudhi Armyndharis96b166b43632
diff --git a/.env.example b/.env.example
index 223ce4102..5c9ae7802 100644
--- a/.env.example
+++ b/.env.example
@@ -197,10 +197,10 @@ BAILEYS_MARK_ONLINE_ON_CONNECT=true
# brand-new WhatsApp account that immediately sends at volume is the pattern that gets numbers
# banned. Any malformed entry falls the WHOLE schedule back to the default rather than sending more
# than you asked for. Counts come from the messages table, so they survive a restart — but that also
-# means the cap only sees sends that WRITE a row there. Status posts and Baileys product sends are
-# real outbound traffic that persists none, so they pass through the check without being counted:
-# a session doing either can exceed its stated daily allowance. Chat sends, bulk included, are
-# counted exactly.
+# means the cap only sees sends that WRITE a row there. Status posts, message edits and Baileys
+# product sends are real outbound traffic that persists no new row, so they pass through the check
+# without being counted: a session doing any of them can exceed its stated daily allowance. Chat
+# sends, bulk included, are counted exactly.
# SEND_PACING_ENABLED=true
# SEND_PACING_WARMUP_SCHEDULE=20,40,80,160,320,640,1000
#
@@ -369,6 +369,8 @@ WEBHOOK_SSRF_PROTECT=true
# # (no decryption, no memory allocation, no storage).
# # NOTE: disabling also makes hasMedia report false and removes the
# # media field from webhooks and the dashboard.
+# # Accepts true/false/1/0/yes/no; anything else fails the boot,
+# # because an unrecognised value silently means ENABLED.
# EXPORT_INLINE_MEDIA_BUDGET_BYTES=8388608
# # How much inline base64 media one GET /infra/export-data may
# # carry, in encoded bytes (default 8 MiB). Past it the remaining
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9ca5dd4e..8405c896e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **A WhatsApp-initiated unlink now clears a session's stored credentials once rather than twice** — whatsapp-web.js can raise the logout event more than once for a single unlink and nothing deduplicated it, so the repeats raced each other and a still-open browser into the `ENOTEMPTY` failure the removal now carries the retry budget to survive.
- **A reaction to a message the gateway never stored no longer vanishes** — the `message.reaction` webhook and the dashboard stream were both gated on the stored row, so a reaction to an ephemeral message, or to one that arrived before the session went live, was dropped with no error and no log.
-- **`MEDIA_DOWNLOAD_ENABLED` is now validated at boot** — it is read as "anything that is not `false`/`0`/`no`", so a typo left inbound media being decrypted and base64-inlined into every message row instead of disabling it.
-- **A data export no longer carries inline media bytes** — base64 inflates a single 50 MiB attachment to 66 MiB, past the import's own 25mb request-body limit, so a backup could export cleanly and then be refused with `413` on restore.
+- **`MEDIA_DOWNLOAD_ENABLED` is now validated at boot** — it is read as "anything that is not `false`/`0`/`no`", so a typo left inbound media being decrypted and base64-inlined into every message row instead of disabling it. Only `true`/`false`/`1`/`0`/`yes`/`no` are accepted now, so a spelling like `on` that used to work will fail startup until it is changed.
+- **A data export now bounds the inline media it carries** — base64 inflates a single 50 MiB attachment to 66 MiB, past the import's own 25mb request-body limit, so a backup could export cleanly and then be refused with `413` on restore. `EXPORT_INLINE_MEDIA_BUDGET_BYTES` (8 MiB by default) caps the total across messages and bulk batches, and payloads past it export as the omitted marker; a URL-referenced payload is never dropped, and a large enough text-only history can still exceed the limit.
- **A data import now carries each session's ownership lease by its remaining time instead of its original deadline** — a restore re-applied the deadline unchanged, so one that ran longer than a claim had left committed that claim as expired, including claims held by other nodes whose engines never stopped.
- **A refused data import no longer offers a retry that stops live engines** — the one refusal whose retry is destructive now carries `IMPORT_WOULD_ORPHAN_ENGINES` and the dashboard matches it positively, so a refusal that only asks the operator to wait can no longer present a confirm whose OK re-runs the replace-all with `stopOrphans=true`.
- **A data import is refused with `409` when another transaction holds the connection** — on SQLite it would otherwise nest inside that transaction and commit into it rather than to disk, so a restore reported as successful could vanish with that transaction's rollback.
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 7092a947d..d95eab9db 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -1244,11 +1244,11 @@ extra work is done.
When enabled, two rules can refuse a send:
-| Rule | What it means |
-| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| Warm-up daily cap | The session has used its allowance for the current **UTC** day. The allowance grows with the session's age (`SEND_PACING_WARMUP_SCHEDULE`), because a brand-new WhatsApp account that immediately sends at volume is the pattern that gets numbers banned. The count comes from the messages table, so it survives restarts — and so it only sees sends that write a row there. Status posts and Baileys product sends are checked against the cap but never counted into it, so a session using either can exceed its stated allowance; chat sends, bulk included, are counted exactly. |
-| Cold-reachout cap | The session has used its allowance of **new conversations** for the UTC day (`SEND_PACING_COLD_DAILY_CAP`). A send is a cold reachout when the account has no history with that chat in **either** direction — replying to someone who wrote to you first is never counted, and never refused by this rule. Status posts address no chat and are exempt. |
-| Failure breaker | Consecutive send failures reached `SEND_PACING_BREAKER_THRESHOLD`, which usually means WhatsApp has already started refusing this account. The streak has no time decay — only a successful send resets it, so failures spread across a long quiet period still accumulate toward the threshold. Sends resume after `SEND_PACING_BREAKER_COOLDOWN_MS`, or immediately after any send succeeds. |
+| Rule | What it means |
+| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| Warm-up daily cap | The session has used its allowance for the current **UTC** day. The allowance grows with the session's age (`SEND_PACING_WARMUP_SCHEDULE`), because a brand-new WhatsApp account that immediately sends at volume is the pattern that gets numbers banned. The count comes from the messages table, so it survives restarts — and so it only sees sends that write a row there. Status posts, message edits and Baileys product sends are checked against the cap but never counted into it — none of them writes a row, and an edit only updates one — so a session using them can exceed its stated allowance; chat sends, bulk included, are counted exactly. |
+| Cold-reachout cap | The session has used its allowance of **new conversations** for the UTC day (`SEND_PACING_COLD_DAILY_CAP`). A send is a cold reachout when the account has no history with that chat in **either** direction — replying to someone who wrote to you first is never counted, and never refused by this rule. Status posts address no chat and are exempt. |
+| Failure breaker | Consecutive send failures reached `SEND_PACING_BREAKER_THRESHOLD`, which usually means WhatsApp has already started refusing this account. The streak has no time decay — only a successful send resets it, so failures spread across a long quiet period still accumulate toward the threshold. Sends resume after `SEND_PACING_BREAKER_COOLDOWN_MS`, or immediately after any send succeeds. |
A refusal is `429` with a body carrying **`code: "SEND_PACING_LIMITED"`** and `retryAfterSeconds`:
@@ -5000,7 +5000,11 @@ Export every row of the 13 migration tables from the Data DB as JSON. Read-only,
**Auth:** API key (ADMIN)
-> **Inline media bytes are not in the export.** A message row's `metadata.media` keeps its shape but arrives as the omitted marker — `{ mimetype, filename?, omitted: true, sizeBytes }`, the same one the engine emits when an inbound payload is over `MEDIA_DOWNLOAD_MAX_BYTES`. Without this, one media message could exceed the import's own request-body limit (`BODY_SIZE_LIMIT`, 25mb by default), producing a backup this gateway refuses to restore with `413`. Restored messages therefore render without their pictures. The files themselves are not part of this endpoint in either direction: back them up with the storage tree (see `scripts/backup.sh`, which copies it unconditionally), and note that the export never carried them even before the bytes were dropped.
+> **Inline media is carried up to a budget, then omitted.** `EXPORT_INLINE_MEDIA_BUDGET_BYTES` (8 MiB of encoded base64 by default) bounds how much inline media one export may hold, counted across both `messages` and `messageBatches`. Payloads past it arrive as the omitted marker — `{ mimetype, filename?, omitted: true, sizeBytes }`, the same shape the engine emits when an inbound payload exceeds `MEDIA_DOWNLOAD_MAX_BYTES` — so those messages restore without their pictures. Without the bound, one 50 MiB attachment becomes 66 MiB of base64 and exceeds the import's own request-body limit (`BODY_SIZE_LIMIT`, 25mb by default), producing a backup this gateway refuses to restore with `413`.
+>
+> A **URL-referenced** payload is never counted or dropped: `metadata.media.data` holds either base64 or the URL a send was given, and a URL is a pointer worth a few dozen bytes.
+>
+> This bounds the media, not the export — a large enough text-only history still exceeds the import limit, because every row costs a few hundred bytes of scaffolding whatever was said. For a backup that keeps everything, use `scripts/backup.sh`: it snapshots the database file itself (and `pg_dump`s Postgres), so inline media rides along regardless of this budget.
The migration set (`MigrationTables`) is, in payload-key order: `sessions`, `webhooks`, `messages`, `messageBatches`, `templates`, `baileysStoredMessages`, `lidMappings`, `pluginInstances`, `conversationMappings`, `ingressEvents`, `webhookDeliveryFailures`, `integrationDeliveryFailures`, `statusUpdates`.
diff --git a/src/modules/message/send-pacing.service.ts b/src/modules/message/send-pacing.service.ts
index 555907f98..0970ee7c7 100644
--- a/src/modules/message/send-pacing.service.ts
+++ b/src/modules/message/send-pacing.service.ts
@@ -94,10 +94,11 @@ const MAX_REFUSAL_KEYS = 1000;
* already the durable record of every chat send — bulk included, which persists through the same
* `saveOutgoingMessage` — and it already carries the `(sessionId, createdAt)` index the count needs.
* So the cap survives restarts with no table and no migration. The trade is that it counts only what
- * writes a row: a status post (status.service.ts) and a Baileys product send (catalog.service.ts)
- * are real outbound traffic that persists none, so both clear this check without ever adding to it,
- * and a session using them can exceed its stated allowance. Deliberate, and documented in
- * .env.example and docs/06 so the number an operator reads is the number they get.
+ * writes a row. Three paths clear this check without ever adding to it: a status post
+ * (status.service.ts), a Baileys product send (catalog.service.ts), and a message edit — which is
+ * gated here via applySendingGate but only UPDATEs the existing row, never inserts. A session using
+ * them can exceed its stated allowance. Deliberate, and documented in .env.example and docs/06 so
+ * the number an operator reads is the number they get.
* The breaker, by contrast, is in memory on purpose: it describes live conditions, and a restart
* clearing it is the correct behaviour.
*/