Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(status): dispatch an opt-in status.received webhook on ingest

Yudhi Armyndharisa2bf8f96a01d
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 1f046427a..21c2d02ad 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -4905,6 +4905,9 @@ These are the events OpenWA actually emits. A webhook is registered with an `eve
| `group.leave` | Participant(s) leave or are removed from a group | `{ groupId, actorId?, participantIds, timestamp }` |
| `group.update` | Group metadata changes (subject, description, announce/locked settings) | `{ groupId, actorId?, participantIds, changes?, timestamp }` — `changes` carries only the fields that changed: `subject?`, `description?`, `announce?`, `locked?` |
| `call.received` | An incoming voice/video call starts ringing | `{ callId, from, isVideo, isGroup, timestamp }` — `callId` is the id to pass to `POST /sessions/:sessionId/calls/:callId/reject` |
+| `status.received` | A contact posts a status/story (opt-in — see below) | `{ sessionId, statusId, contact: { id, name?, pushName? }, type, caption?, hasMedia, mediaOmitted, omitReason?, postedAt, expiresAt }` — `statusId` is the store's `id` (usable with the status endpoints below); `postedAt`/`expiresAt` are epoch **milliseconds** (unlike the epoch-seconds convention for message timestamps), matching the `GET /status` store's own `Date`-backed fields |
+
+> **`status.received` is opt-in and carries no media blob.** Unlike every other event above, `status.received` is only delivered to a webhook whose `events` list explicitly includes `"status.received"` (or `"*"`) — registering for other events does not implicitly subscribe you to it. The payload never embeds media bytes: when `hasMedia` is `true`, fetch the file separately via `GET /api/sessions/:sessionId/status/:statusId/media`. Your own posted statuses never trigger this event — only inbound stories from contacts (an own-send echo is dropped before ingest).
> **`STORE_EPHEMERAL_MESSAGES=false` affects `message.received`.** When `STORE_EPHEMERAL_MESSAGES` is set to `false`, incoming disappearing messages (those with `ephemeralDuration > 0`) are **not** persisted nor dispatched — no DB insert, no webhook delivery, and no websocket event. Downstream consumers and the dashboard both stop seeing them. Default is `true` (backward compatible — store and dispatch everything).
diff --git a/src/modules/session/session.service.spec.ts b/src/modules/session/session.service.spec.ts
index 186ca76b6..941541f4f 100644
--- a/src/modules/session/session.service.spec.ts
+++ b/src/modules/session/session.service.spec.ts
@@ -2208,6 +2208,49 @@ describe('SessionService', () => {
expect(dispatchedEvents('message.received')).toHaveLength(0);
});
+ it('dispatches status.received with the ingested row once ingest resolves', async () => {
+ const callbacks = await startAndCaptureCallbacks();
+ (statusStore.ingest as jest.Mock).mockResolvedValueOnce({
+ waStatusId: 'st1',
+ contactJid: '[email protected]',
+ contactName: 'Alice',
+ type: 'text',
+ caption: 'hi',
+ mediaOmitted: false,
+ postedAt: 1000,
+ expiresAt: 1000 + 86400000,
+ });
+
+ callbacks.onMessage!(
+ makeMessage({
+ id: 'st1',
+ from: 'status@broadcast',
+ chatId: 'status@broadcast',
+ fromMe: false,
+ isStatusBroadcast: true,
+ author: '[email protected]',
+ kind: 'status',
+ }),
+ );
+ await flush();
+
+ expect(webhookService.dispatch).toHaveBeenCalledWith(
+ 'sess-uuid-1',
+ 'status.received',
+ expect.objectContaining({
+ statusId: 'st1',
+ contact: { id: '[email protected]', name: 'Alice' },
+ type: 'text',
+ caption: 'hi',
+ hasMedia: false,
+ mediaOmitted: false,
+ postedAt: 1000,
+ expiresAt: 1000 + 86400000,
+ }),
+ );
+ });
+
it('skips persist and dispatch for ephemeral messages when STORE_EPHEMERAL_MESSAGES=false', async () => {
process.env.STORE_EPHEMERAL_MESSAGES = 'false';
const callbacks = await startAndCaptureCallbacks();
diff --git a/src/modules/session/session.service.ts b/src/modules/session/session.service.ts
index 534602f40..79b633399 100644
--- a/src/modules/session/session.service.ts
+++ b/src/modules/session/session.service.ts
@@ -682,11 +682,29 @@ export class SessionService implements OnModuleDestroy, OnModuleInit, OnApplicat
}
/**
- * Hook point for the status.received dispatch (webhook/WS/hook), called once an inbound status row
- * is ingested. Intentionally a no-op for now — wired up separately so ingest itself ships first.
+ * Dispatches the opt-in `status.received` webhook once an inbound status row is ingested.
+ * `WebhookService.dispatch` already filters delivery to webhooks whose `events` array includes
+ * `status.received`, so no extra gating is needed here. No media bytes are included in the
+ * payload — consumers fetch media via the status media endpoint.
*/
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- private dispatchStatusReceived(_sessionId: string, _row: StatusUpdate): void {}
+ private dispatchStatusReceived(sessionId: string, row: StatusUpdate): void {
+ void this.webhookService.dispatch(sessionId, 'status.received', {
+ sessionId,
+ statusId: row.waStatusId,
+ contact: {
+ id: row.contactJid,
+ ...(row.contactName ? { name: row.contactName } : {}),
+ ...(row.contactPushName ? { pushName: row.contactPushName } : {}),
+ },
+ type: row.type,
+ ...(row.caption ? { caption: row.caption } : {}),
+ hasMedia: Boolean(row.mediaPath) && !row.mediaOmitted,
+ mediaOmitted: row.mediaOmitted,
+ ...(row.omitReason ? { omitReason: row.omitReason } : {}),
+ postedAt: row.postedAt,
+ expiresAt: row.expiresAt,
+ });
+ }
/**
* Persist pre-connection history into the `messages` table for the chat view, without webhook/hook/ws
@@ -881,8 +899,11 @@ export class SessionService implements OnModuleDestroy, OnModuleInit, OnApplicat
if (!this.isLiveEngine(id, engine)) return;
// Status/Story posts arrive via the inbound path for some engines; ingest them into the
// status store instead of the message pipeline. Mirrors the isStatusBroadcast guard in
- // onMessageCreate below (own-send echo — that branch stays a plain drop).
+ // onMessageCreate below: an own-send echo (fromMe) stays a plain drop — never ingested,
+ // never dispatched — so a status you posted never re-appears in your own webhooks/API as
+ // if a contact had posted it.
if (message.isStatusBroadcast) {
+ if (message.fromMe) return;
const status = buildIncomingStatus(message);
if (status) {
void this.statusStore