Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(baileys): implement postTextStatus via status@broadcast + statusJidList

yudhia55b84255c55
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index dc792775c..af7bb05b5 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -1674,3 +1674,36 @@ describe('BaileysAdapter sendSeen + markUnread + deleteChat', () => {
expect(fakeSock.chatModify).not.toHaveBeenCalled();
});
});
+
+describe('BaileysAdapter status posting', () => {
+ beforeEach(() => {
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ fakeSock.resetEmitter();
+ jest.clearAllMocks();
+ });
+
+ const ready = async (): Promise<BaileysAdapter> => {
+ const adapter = newAdapter();
+ await adapter.initialize(noopCallbacks());
+ fakeSock.fire('connection.update', { connection: 'open' });
+ return adapter;
+ };
+
+ it('postTextStatus sends to status@broadcast with denormalized statusJidList + styling, no store write', async () => {
+ fakeSock.sendMessage.mockResolvedValue({ key: { id: 'STATUS1' }, messageTimestamp: 1719600000 });
+ const adapter = await ready();
+ const result = await adapter.postTextStatus('hello', {
+ recipients: ['[email protected]', '628222@lid'],
+ backgroundColor: '#25D366',
+ font: 2,
+ });
+ expect(fakeSock.sendMessage).toHaveBeenCalledWith('status@broadcast', { text: 'hello' }, {
+ statusJidList: ['[email protected]', '628222@lid'],
+ backgroundColor: '#25D366',
+ font: 2,
+ });
+ expect(result.statusId).toBe('STATUS1');
+ expect(result.expiresAt.getTime() - result.timestamp.getTime()).toBe(24 * 3_600_000);
+ expect(fakeStore.put).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/engine/adapters/baileys.adapter.ts b/src/engine/adapters/baileys.adapter.ts
index e56a196fe..2ec8a6c6b 100644
--- a/src/engine/adapters/baileys.adapter.ts
+++ b/src/engine/adapters/baileys.adapter.ts
@@ -797,8 +797,8 @@ export class BaileysAdapter implements IWhatsAppEngine {
getContactStatus(_contactId: string): Promise<Status[]> {
return this.unsupported('getContactStatus');
}
- postTextStatus(_text: string, _options: StatusPostOptions): Promise<StatusResult> {
- return this.unsupported('postTextStatus');
+ postTextStatus(text: string, options: StatusPostOptions): Promise<StatusResult> {
+ return this.postStatus({ text }, options);
}
postImageStatus(_media: MediaInput, _options: StatusPostOptions): Promise<StatusResult> {
return this.unsupported('postImageStatus');
@@ -1312,6 +1312,35 @@ export class BaileysAdapter implements IWhatsAppEngine {
return found;
}
+ /**
+ * Post a status (story) to `status@broadcast` with a denormalized `statusJidList` (the allow-list of
+ * neutral recipients folded back to the engine dialect). Image/video variants route through here too.
+ * The outbound status echo is NOT persisted — status isn't a chat message (the inbound filter in
+ * handleMessagesUpsert already skips `type:'append'` echoes).
+ */
+ private async postStatus(content: AnyMessageContent, options: StatusPostOptions): Promise<StatusResult> {
+ this.ensureReady();
+ const statusJidList = options.recipients.map(r => this.sessionStore.toEngineJid(r));
+ const sent = await this.sock!.sendMessage('status@broadcast', content, {
+ statusJidList,
+ backgroundColor: options.backgroundColor,
+ font: options.font,
+ });
+ return this.toStatusResult(sent);
+ }
+
+ /** Shape a Baileys send result into a StatusResult; expiresAt is timestamp + 24h (WhatsApp status TTL). */
+ private toStatusResult(sent: WAMessage | undefined): StatusResult {
+ const ts = sent?.messageTimestamp
+ ? new Date(this.toUnixSeconds(sent.messageTimestamp) * 1000)
+ : new Date();
+ return {
+ statusId: sent?.key?.id ?? '',
+ timestamp: ts,
+ expiresAt: new Date(ts.getTime() + 24 * 3_600_000),
+ };
+ }
+
private unsupported(method: string): Promise<any> {
return Promise.reject(new EngineNotSupportedError(method));
}