Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(pacing): say that the warm-up cap only counts sends that write a row
Yudhi Armyndharis5730168630b4
diff --git a/.env.example b/.env.exampleindex a530aa69a..17207a252 100644--- a/.env.example+++ b/.env.example@@ -196,7 +196,11 @@ BAILEYS_MARK_ONLINE_ON_CONNECT=true# session's first day, and the last entry applies to every day after that. It starts small because a# 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.+# 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.# SEND_PACING_ENABLED=true# SEND_PACING_WARMUP_SCHEDULE=20,40,80,160,320,640,1000#diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 8d0a085d9..bfb6cdbfb 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. |-| 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 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. |A refusal is `429` with a body carrying **`code: "SEND_PACING_LIMITED"`** and `retryAfterSeconds`:diff --git a/src/modules/message/send-pacing.service.ts b/src/modules/message/send-pacing.service.tsindex 361af6528..555907f98 100644--- a/src/modules/message/send-pacing.service.ts+++ b/src/modules/message/send-pacing.service.ts@@ -91,11 +91,15 @@ const MAX_REFUSAL_KEYS = 1000;* exactly the automated traffic it exists to pace.** The daily count is read from the `messages` table rather than a counter of its own. That table is- * already the durable record of every send — bulk included, which persists through the same+ * 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, no migration, and no way to drift from what was really- * sent. The breaker, by contrast, is in memory on purpose: it describes live conditions, and a- * restart clearing it is the correct behaviour.+ * 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.+ * The breaker, by contrast, is in memory on purpose: it describes live conditions, and a restart+ * clearing it is the correct behaviour.*/@Injectable()export class SendPacingService {