Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(docs): make the contract and the ops chapter match what this branch changed
Yudhi Armyndharis927ef67a7763
diff --git a/docs/10-devops-infrastructure.md b/docs/10-devops-infrastructure.mdindex 4df668b03..a654b475f 100644--- a/docs/10-devops-infrastructure.md+++ b/docs/10-devops-infrastructure.md@@ -892,11 +892,14 @@ export class MetricsService {gauge('openwa_process_uptime_seconds', '...', Math.round(process.uptime()));gauge('openwa_process_resident_memory_bytes', '...', mem.rss);gauge('openwa_process_heap_used_bytes', '...', mem.heapUsed);- gauge('openwa_sessions_total', '...', overview.sessions.total);- gauge('openwa_sessions_active', '...', overview.sessions.active);- // openwa_sessions{status="..."} — one line per status- // openwa_messages_total{direction="outgoing"|"incoming"}- // openwa_messages_failed_total+ gauge('openwa_stats_available', '...', overview ? 1 : 0);+ if (overview) {+ gauge('openwa_sessions_total', '...', overview.sessions.total);+ gauge('openwa_sessions_active', '...', overview.sessions.active);+ // openwa_sessions{status="..."} — one line per status+ // openwa_messages_total{direction="outgoing"|"incoming"}+ // openwa_messages_failed_total+ }return lines.join('\n') + '\n';}}@@ -904,17 +907,26 @@ export class MetricsService {**Exported metric names** (the complete set — nothing else is emitted):-| Metric | Type | Labels | Meaning |-| -------------------------------------- | ----- | ----------------------------------- | ------------------------------------ |-| `openwa_up` | gauge | — | Always `1` when scraped |-| `openwa_process_uptime_seconds` | gauge | — | Process uptime |-| `openwa_process_resident_memory_bytes` | gauge | — | RSS |-| `openwa_process_heap_used_bytes` | gauge | — | V8 heap used |-| `openwa_sessions_total` | gauge | — | Configured sessions |-| `openwa_sessions_active` | gauge | — | READY (active) sessions |-| `openwa_sessions` | gauge | `status` | Session count per status |-| `openwa_messages_total` | gauge | `direction` (`incoming`/`outgoing`) | Current stored messages by direction |-| `openwa_messages_failed_total` | gauge | — | Current messages in FAILED state |+| Metric | Type | Labels | Meaning |+| -------------------------------------- | ----- | ----------------------------------- | -------------------------------------------------------------------------------------------- |+| `openwa_up` | gauge | — | Always `1` when scraped |+| `openwa_process_uptime_seconds` | gauge | — | Process uptime |+| `openwa_process_resident_memory_bytes` | gauge | — | RSS |+| `openwa_process_heap_used_bytes` | gauge | — | V8 heap used |+| `openwa_stats_available` | gauge | — | 1 when the database-derived series below could be read on this scrape, 0 when they could not |+| `openwa_sessions_total` | gauge | — | Configured sessions |+| `openwa_sessions_active` | gauge | — | READY (active) sessions |+| `openwa_sessions` | gauge | `status` | Session count per status |+| `openwa_messages_total` | gauge | `direction` (`incoming`/`outgoing`) | Current stored messages by direction |+| `openwa_messages_failed_total` | gauge | — | Current messages in FAILED state |++> **The database-derived series can be absent.** `openwa_sessions_*`, `openwa_messages_*` and the per-status+> breakdown are read from the data database on each scrape. If that read fails — an outage, a statement+> timeout, pool exhaustion, a `SQLITE_BUSY` under load — they are OMITTED rather than reported as zero, and+> `openwa_stats_available` goes to 0. The process, HTTP and webhook series keep being served, so `up` stays 1+> and still means "the process is alive". Alert on `openwa_stats_available == 0` for the degradation itself;+> an alert written as `openwa_sessions_active == 0` would never fire for it, and one written with `absent()`+> would.### Grafana Dashboard Definitiondiff --git a/openapi.json b/openapi.jsonindex 97cbadc3d..1a756ed65 100644--- a/openapi.json+++ b/openapi.json@@ -5510,6 +5510,9 @@}}},+ "400": {+ "description": "The id does not name a group"+ },"409": {"description": "The session is not connected — an engine exists for it but is not `ready`: disconnected, reconnecting, or still initializing, so the request never reached WhatsApp. Wait for `ready` and retry. A session that was never started answers `400` instead, and the session lifecycle routes answer `409` for a conflicting state rather than this. One window answers this while the session still reads `ready`: WhatsApp Web periodically reloads its own page and the engine re-injects into it — for those few seconds the answer is a `409` naming the reload; retry shortly."},@@ -5619,6 +5622,9 @@}}},+ "400": {+ "description": "The id does not name a group"+ },"403": {"description": "The engine refused the change — admin rights required"},diff --git a/src/modules/group/group.controller.ts b/src/modules/group/group.controller.tsindex 71385e295..f02873509 100644--- a/src/modules/group/group.controller.ts+++ b/src/modules/group/group.controller.ts@@ -447,6 +447,7 @@ export class GroupController {description: 'Picture URL, or null when the group has none',type: GroupPictureResponseDto,})+ @ApiResponse({ status: 400, description: 'The id does not name a group' })@ApiResponse({status: 503,description: 'WhatsApp did not answer within the request budget — nothing could be read.',@@ -489,6 +490,7 @@ export class GroupController {@ApiParam({ name: 'sessionId', description: 'Session ID' })@ApiParam({ name: 'groupId', description: 'Group ID' })@ApiResponse({ status: 200, description: 'Group picture removed', type: GroupAckResponseDto })+ @ApiResponse({ status: 400, description: 'The id does not name a group' })@ApiResponse({ status: 403, description: 'The engine refused the change — admin rights required' })@ApiResponse({status: 503,diff --git a/src/modules/infra/infra-data.controller.spec.ts b/src/modules/infra/infra-data.controller.spec.tsindex 70501be90..400d2ca61 100644--- a/src/modules/infra/infra-data.controller.spec.ts+++ b/src/modules/infra/infra-data.controller.spec.ts@@ -2023,8 +2023,14 @@ describe('InfraDataController.importData rejects a malformed table value', () =>await expect(controller().importData({ tables: { messages: 'nope' } } as never)).rejects.toThrow(/messages/);});- // Negative twin: an absent table is legal (a partial archive), and must not be rejected.- it('accepts an archive that simply omits a table', async () => {- await expect(controller().importData({ tables: {} })).rejects.not.toThrow(/must be an array/);+ // Negative twin. It guards OVER-rejection, not deletion: a "must not reject" assertion can never+ // fail when the guard is removed — that is what the four cases above are for. What it does catch is+ // the guard hardening into refusing shapes the endpoint supports: an absent table (a partial+ // archive) and an empty one (a table that legitimately has no rows).+ it.each([+ ['omits a table', { sessions: [{ id: 's1' }] }],+ ['carries an empty table', { sessions: [], messages: [] }],+ ])('does not reject an archive that %s', async (_label, tables) => {+ await expect(controller().importData({ tables } as never)).rejects.not.toThrow(/must be an array/);});});