Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(status): read statuses from the store on both engines and stream stored media

Yudhi Armyndharis925a709fbed7
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 9811de754..1f046427a 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -2690,6 +2690,8 @@ Note: this is the one route in the module that returns a literal `{ success: tru
Labels are a WhatsApp Business feature: every label route lives under a session and reads/writes the chat-label assignments exposed by the engine. Status routes manage the session's status feed (stories) — reading visible statuses and posting/deleting your own. Read routes require a base API key; all writes require `OPERATOR`.
+**Reads are store-backed, not engine-direct.** `GET /status` and `GET /status/:contactId` no longer call the engine — they read from an OpenWA-side store that ingests inbound status/story broadcasts as they arrive (plus a best-effort backfill of currently-active stories on session connect), with a 24h TTL matching WhatsApp's own story expiry. This makes reads **identical on both engines**: `whatsapp-web.js` (which had a native `getBroadcasts()`/`getBroadcastById()` path) and Baileys (which never had one — `fetchStatus` only returns the *about* text, not stories, so the raw engine methods still throw `501` if called directly, they're just no longer on the read path) now return the same shape from the same source. A status older than 24h, or received before the store existed, will not appear.
+
#### GET /api/sessions/:sessionId/labels
List all labels defined for the session (WhatsApp Business accounts only).
@@ -2822,7 +2824,7 @@ The handler always returns `{ "success": true }`. DELETE default status is `200`
#### GET /api/sessions/:sessionId/status
-Get all contact status updates (stories) visible to the session.
+Get all contact status updates (stories) visible to the session, read from the store (24h TTL, both engines — see the note above).
**Auth:** API key
@@ -2842,7 +2844,7 @@ Get all contact status updates (stories) visible to the session.
"contact": { "id": "[email protected]", "name": "Alice", "pushName": "Alice" },
"type": "image",
"caption": "On the road",
- "mediaUrl": "https://…",
+ "mediaUrl": "/api/sessions/my-session/status/[email protected]_3A1F.../media",
"backgroundColor": "#25D366",
"font": 2,
"timestamp": "2026-06-25T08:30:00.000Z",
@@ -2852,13 +2854,13 @@ Get all contact status updates (stories) visible to the session.
}
```
-The controller wraps the engine array in `{ statuses }`. `type` is one of `text | image | video`; `caption`, `mediaUrl`, `backgroundColor`, `font` are optional. `timestamp` and `expiresAt` serialize to ISO strings (these are `Date` values, not the epoch-number convention used by message timestamps).
+The controller wraps the store array in `{ statuses }`, ordered newest-first. `type` is one of `text | image | video`; `caption`, `backgroundColor`, `font` are optional. `mediaUrl` is present only when the status carried media that the store kept (see the media endpoint below) — it is a same-origin path into this API, not an external WhatsApp CDN link. `timestamp` and `expiresAt` serialize to ISO strings (these are `Date` values, not the epoch-number convention used by message timestamps).
-**Errors:** `401` missing/invalid API key, or key not scoped to this session · `404` `Session {id} not found or not connected`
+**Errors:** `401` missing/invalid API key, or key not scoped to this session
#### GET /api/sessions/:sessionId/status/:contactId
-Get status updates posted by a specific contact.
+Get status updates posted by a specific contact, read from the store (24h TTL, both engines).
**Auth:** API key
@@ -2888,9 +2890,28 @@ Get status updates posted by a specific contact.
}
```
-Same `{ statuses }` wrapper and `Status` shape as the list-all route.
+Same `{ statuses }` wrapper and `Status` shape as the list-all route. An unknown `contactId` returns `{ "statuses": [] }`, not a `404`.
+
+**Errors:** `401` missing/invalid API key, or key not scoped to this session
+
+#### GET /api/sessions/:sessionId/status/:statusId/media
+
+Stream a stored status's media bytes (the file behind a `mediaUrl` returned above).
+
+**Auth:** API key
+
+**Path parameters**
+
+| Name | Type | Description |
+| --- | --- | --- |
+| sessionId | string | WhatsApp session identifier |
+| statusId | string | The status `id` (e.g. from a `GET /status` response) |
+
+**Response** `200` — the raw media bytes as the response body, with `Content-Type` set to the stored mimetype (e.g. `image/jpeg`, `video/mp4`). Streamed via `StreamableFile` from whatever backs `StorageService` (local disk or S3 — the route does not care which).
+
+**Errors:** `401` missing/invalid API key, or key not scoped to this session · `404` `Status media not found or expired` — the status is text-only, its media was omitted (e.g. over the configured size cap), or the 24h TTL has since purged the row
-**Errors:** `401` missing/invalid API key, or key not scoped to this session · `404` session not found / not connected
+Note: `:statusId/media` is a two-path-segment route, so it never collides with the single-segment `GET /status/:contactId` above regardless of declaration order.
#### POST /api/sessions/:sessionId/status/send-text
diff --git a/docs/engine-capability-matrix.md b/docs/engine-capability-matrix.md
index ca67b31bb..3274ff0ef 100644
--- a/docs/engine-capability-matrix.md
+++ b/docs/engine-capability-matrix.md
@@ -76,7 +76,8 @@ The `rootCause`/`evidence` fields are hand-curated from source traces of the ins
| `getContactStatuses` | not-available — **library-limitation** | supported |
> **Wired.** ✅ `getContactStatus` / `getContactStatuses` on whatsapp-web.js — `getBroadcastById(id)` / `getBroadcasts()` flattened to `Status[]` (contact via `broadcast.getContact()`; type from `MessageTypes`; 24h TTL). **Caveat:** `Status.type` is the `text|image|video` union — audio/other story types collapse to `text`.
-- **`getContactStatus` / `getContactStatuses` (baileys, library-limitation).** `fetchStatus` (`Socket/chats.d.ts:42` via `USyncStatusProtocol`) returns the *about/profile text* line (`{status, setAt}`), **not** 24h stories. No story-read getter exists; story broadcasts surface only as `status@broadcast` messages via `messages.upsert` / `messaging-history.set` events. Would require OpenWA to accumulate `status@broadcast` messages itself and project them into `Status[]`.
+- **`getContactStatus` / `getContactStatuses` (baileys, library-limitation).** `fetchStatus` (`Socket/chats.d.ts:42` via `USyncStatusProtocol`) returns the *about/profile text* line (`{status, setAt}`), **not** 24h stories. No story-read getter exists; story broadcasts surface only as `status@broadcast` messages via `messages.upsert` / `messaging-history.set` events. These raw engine methods are still unimplemented on Baileys and still throw `EngineNotSupportedError` (`501`) if called directly.
+- **API-level parity shipped without adapter wiring.** The `status@broadcast` accumulator this row calls for exists now — as an OpenWA-side store (`StatusStoreService`, `src/modules/status-store/`) fed by inbound status ingestion on both engines, not inside the Baileys adapter. `GET /sessions/:id/status` and `GET /sessions/:id/status/:contactId` read from that store instead of calling `getContactStatus`/`getContactStatuses`, so the REST API is at parity across engines even though these two adapter cells remain, correctly, `not-available`.
### Messaging misc — delete / history / reactions
diff --git a/openapi.json b/openapi.json
index 902965733..1ffbac5db 100644
--- a/openapi.json
+++ b/openapi.json
@@ -4246,6 +4246,41 @@
]
}
},
+ "/api/sessions/{sessionId}/status/{statusId}/media": {
+ "get": {
+ "operationId": "StatusController_getStatusMedia",
+ "parameters": [
+ {
+ "name": "sessionId",
+ "required": true,
+ "in": "path",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "statusId",
+ "required": true,
+ "in": "path",
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "The status image/video bytes."
+ },
+ "404": {
+ "description": "No stored media (text status, omitted, or expired)."
+ }
+ },
+ "summary": "Stream a stored status media file",
+ "tags": [
+ "status"
+ ]
+ }
+ },
"/api/sessions/{sessionId}/status/send-text": {
"post": {
"operationId": "StatusController_sendTextStatus",
diff --git a/src/modules/status/status.controller.ts b/src/modules/status/status.controller.ts
index 9ad088158..5ca61abfe 100644
--- a/src/modules/status/status.controller.ts
+++ b/src/modules/status/status.controller.ts
@@ -1,6 +1,8 @@
-import { Controller, Get, Post, Delete, Param, Body } from '@nestjs/common';
+import { Controller, Get, Post, Delete, Param, Body, Res, StreamableFile } from '@nestjs/common';
+import type { Response } from 'express';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { StatusService } from './status.service';
+import { StorageService } from '../../common/storage/storage.service';
import { SendTextStatusDto } from './dto/send-text-status.dto';
import { SendImageStatusDto, SendVideoStatusDto } from './dto/send-media-status.dto';
import { RequireRole } from '../auth/decorators/auth.decorators';
@@ -9,7 +11,10 @@ import { ApiKeyRole } from '../auth/entities/api-key.entity';
@ApiTags('status')
@Controller('sessions/:sessionId/status')
export class StatusController {
- constructor(private readonly statusService: StatusService) {}
+ constructor(
+ private readonly statusService: StatusService,
+ private readonly storageService: StorageService,
+ ) {}
@Get()
@ApiOperation({ summary: 'Get all contact status updates' })
@@ -25,6 +30,23 @@ export class StatusController {
return { statuses: await this.statusService.getContactStatus(sessionId, contactId) };
}
+ // Two path segments (`:statusId/media`) never collides with the single-segment `:contactId`
+ // route above regardless of declaration order — Nest/Express match on segment count.
+ @Get(':statusId/media')
+ @ApiOperation({ summary: 'Stream a stored status media file' })
+ @ApiResponse({ status: 200, description: 'The status image/video bytes.' })
+ @ApiResponse({ status: 404, description: 'No stored media (text status, omitted, or expired).' })
+ async getStatusMedia(
+ @Param('sessionId') sessionId: string,
+ @Param('statusId') statusId: string,
+ @Res({ passthrough: true }) res: Response,
+ ): Promise<StreamableFile> {
+ const { path, mimetype } = await this.statusService.getStatusMedia(sessionId, statusId);
+ const buffer = await this.storageService.getFile(path);
+ res.set({ 'Content-Type': mimetype });
+ return new StreamableFile(buffer);
+ }
+
@Post('send-text')
@RequireRole(ApiKeyRole.OPERATOR)
@ApiOperation({ summary: 'Post a text status' })
diff --git a/src/modules/status/status.module.ts b/src/modules/status/status.module.ts
index ecbc80f56..cfb2e5767 100644
--- a/src/modules/status/status.module.ts
+++ b/src/modules/status/status.module.ts
@@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
import { StatusController } from './status.controller';
import { StatusService } from './status.service';
import { SessionModule } from '../session/session.module';
+import { StatusStoreModule } from '../status-store/status-store.module';
@Module({
- imports: [SessionModule],
+ imports: [SessionModule, StatusStoreModule],
controllers: [StatusController],
providers: [StatusService],
exports: [StatusService],
diff --git a/src/modules/status/status.service.spec.ts b/src/modules/status/status.service.spec.ts
index 8a1753c66..69d229c4e 100644
--- a/src/modules/status/status.service.spec.ts
+++ b/src/modules/status/status.service.spec.ts
@@ -1,6 +1,7 @@
-import { BadRequestException, PayloadTooLargeException } from '@nestjs/common';
+import { BadRequestException, NotFoundException, PayloadTooLargeException } from '@nestjs/common';
import { StatusService } from './status.service';
import { SessionService } from '../session/session.service';
+import { StatusStoreService } from '../status-store/status-store.service';
import { HookManager } from '../../core/hooks';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
@@ -17,13 +18,57 @@ describe('StatusService media validation and selection', () => {
// tests below.
const passThrough = (_event: string, data: unknown) => Promise.resolve({ continue: true, data });
const hookManager = { execute: jest.fn(passThrough) };
- const service = new StatusService(sessionService as unknown as SessionService, hookManager as unknown as HookManager);
+ const store = { list: jest.fn(), listByContact: jest.fn(), getMedia: jest.fn() };
+ const service = new StatusService(
+ sessionService as unknown as SessionService,
+ hookManager as unknown as HookManager,
+ store as unknown as StatusStoreService,
+ );
beforeEach(() => {
jest.clearAllMocks();
hookManager.execute.mockImplementation(passThrough);
});
+ describe('reading statuses', () => {
+ it('reads statuses from the store, not the engine', async () => {
+ store.list.mockResolvedValue([{ id: 'w1' } as any]);
+
+ const out = await service.getStatuses('sess');
+
+ expect(out).toEqual([{ id: 'w1' }]);
+ expect(store.list).toHaveBeenCalledWith('sess');
+ expect(sessionService.getEngine).not.toHaveBeenCalled();
+ });
+
+ it('reads a contact statuses from the store, not the engine', async () => {
+ store.listByContact.mockResolvedValue([{ id: 'w2' } as any]);
+
+ const out = await service.getContactStatus('sess', '[email protected]');
+
+ expect(out).toEqual([{ id: 'w2' }]);
+ expect(store.listByContact).toHaveBeenCalledWith('sess', '[email protected]');
+ expect(sessionService.getEngine).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('getStatusMedia', () => {
+ it('throws NotFoundException when the store has no media for the status', async () => {
+ store.getMedia.mockResolvedValue(null);
+
+ await expect(service.getStatusMedia('sess', 'w1')).rejects.toBeInstanceOf(NotFoundException);
+ });
+
+ it('returns the stored path and mimetype', async () => {
+ store.getMedia.mockResolvedValue({ path: 'statuses/sess/x.jpg', mimetype: 'image/jpeg' });
+
+ const media = await service.getStatusMedia('sess', 'w1');
+
+ expect(media).toEqual({ path: 'statuses/sess/x.jpg', mimetype: 'image/jpeg' });
+ expect(store.getMedia).toHaveBeenCalledWith('sess', 'w1');
+ });
+ });
+
it('prefers explicit base64 over url for image and video status media', async () => {
const media = { url: 'https://example.com/stale', base64: 'QUJD', mimetype: 'image/png' };
await service.postImageStatus('s1', media, { recipients: ['[email protected]'] });
diff --git a/src/modules/status/status.service.ts b/src/modules/status/status.service.ts
index 8432a556b..bddd24cba 100644
--- a/src/modules/status/status.service.ts
+++ b/src/modules/status/status.service.ts
@@ -1,5 +1,6 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { SessionService } from '../session/session.service';
+import { StatusStoreService } from '../status-store/status-store.service';
import type { Status, StatusResult, StatusPostOptions } from '../../engine/interfaces/whatsapp-engine.interface';
import { assertBase64WithinMediaCap, stripBase64DataUri } from '../message/media-cap.util';
import { HookManager, applySendingGate } from '../../core/hooks';
@@ -10,6 +11,7 @@ export class StatusService {
constructor(
private readonly sessionService: SessionService,
private readonly hookManager: HookManager,
+ private readonly store: StatusStoreService,
) {}
/**
@@ -40,20 +42,24 @@ export class StatusService {
return { mimetype: media.mimetype, data };
}
+ // Reads come from the store (StatusStoreService ingests status broadcasts as they arrive, plus a
+ // best-effort seed on connect), not the engine — Baileys never implemented
+ // `getContactStatuses`/`getContactStatus`, so both engines now answer reads identically from the
+ // same 24h-TTL store.
async getStatuses(sessionId: string): Promise<Status[]> {
- const engine = this.sessionService.getEngine(sessionId);
- if (!engine) {
- throw new NotFoundException(`Session ${sessionId} not found or not connected`);
- }
- return engine.getContactStatuses();
+ return this.store.list(sessionId);
}
async getContactStatus(sessionId: string, contactId: string): Promise<Status[]> {
- const engine = this.sessionService.getEngine(sessionId);
- if (!engine) {
- throw new NotFoundException(`Session ${sessionId} not found or not connected`);
+ return this.store.listByContact(sessionId, contactId);
+ }
+
+ async getStatusMedia(sessionId: string, statusId: string): Promise<{ path: string; mimetype: string }> {
+ const media = await this.store.getMedia(sessionId, statusId);
+ if (!media) {
+ throw new NotFoundException('Status media not found or expired');
}
- return engine.getContactStatus(contactId);
+ return media;
}
async postTextStatus(sessionId: string, text: string, options: StatusPostOptions): Promise<StatusResult> {