Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(status): leave absent status fields off the wire
Yudhi Armyndharisc42e36e5a171
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 891f448af..0a358629c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- Omit the name, push name, caption, background colour and font of a received status that has none from `GET /status` instead of returning `null`, as the schema declares.- Bound the inbound media a PostgreSQL session holds before storing it to `INBOUND_MEDIA_CONCURRENCY` payloads, keeping each chat's arrival order.- Drop a Baileys edit, revoke or reaction from another chat, or an edit or revoke from the wrong author, aimed at a message still being downloaded, on SQLite too.- Warn at storage export when a file is larger than the per-entry import cap `STORAGE_IMPORT_MAX_BYTES`.diff --git a/src/modules/status-store/status-store.service.spec.ts b/src/modules/status-store/status-store.service.spec.tsindex f6292ea66..3d1e745ba 100644--- a/src/modules/status-store/status-store.service.spec.ts+++ b/src/modules/status-store/status-store.service.spec.ts@@ -78,6 +78,25 @@ describe('StatusStoreService (ingest / list / getMedia)', () => {expect(styled.font).toBe(2);});+ it('serves a status with no name, push name, caption or styling without those keys', async () => {+ const postedAt = Date.now();+ await service.ingest('sess', { waStatusId: 'bare', contactJid: '[email protected]', type: 'text', postedAt });++ // The columns read back as null, but StatusDto and the openapi schema declare these fields optional,+ // not nullable: a client typed from the contract must see them absent.+ const listed = (await service.list('sess')).find(s => s.id === 'bare')!;+ const [byContact] = await service.listByContact('sess', '[email protected]');+ const wire = {+ id: 'bare',+ contact: { id: '[email protected]' },+ type: 'text',+ timestamp: new Date(postedAt).toISOString(),+ expiresAt: new Date(postedAt + 24 * 60 * 60 * 1000).toISOString(),+ };+ expect(JSON.parse(JSON.stringify(listed))).toEqual(wire);+ expect(JSON.parse(JSON.stringify(byContact))).toEqual(wire);+ });+it('ingest persists media to a file under the cap and records mediaPath', async () => {const { row } = await service.ingest('sess', {waStatusId: 'w2',diff --git a/src/modules/status-store/status-store.service.ts b/src/modules/status-store/status-store.service.tsindex b9fda1969..4be46847e 100644--- a/src/modules/status-store/status-store.service.ts+++ b/src/modules/status-store/status-store.service.ts@@ -290,18 +290,24 @@ export class StatusStoreService implements OnModuleInit, OnModuleDestroy {return phone ? `${phone}@c.us` : jid;}+ // The nullable columns read back as null, while Status declares these fields optional: `?? undefined`+ // keeps them off the wire, as the contract (StatusDto, openapi) says.private toStatus(row: StatusUpdate): Status {return {id: row.waStatusId,- contact: { id: this.canonicalContactJid(row.contactJid), name: row.contactName, pushName: row.contactPushName },+ contact: {+ id: this.canonicalContactJid(row.contactJid),+ name: row.contactName ?? undefined,+ pushName: row.contactPushName ?? undefined,+ },type: row.type,- caption: row.caption,+ caption: row.caption ?? undefined,mediaUrl:row.mediaPath && !row.mediaOmitted? `/api/sessions/${row.sessionId}/status/${row.waStatusId}/media`: undefined,- backgroundColor: row.backgroundColor,- font: row.font,+ backgroundColor: row.backgroundColor ?? undefined,+ font: row.font ?? undefined,timestamp: new Date(row.postedAt),expiresAt: new Date(row.expiresAt),};