Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

perf(baileys): do not download the media of the account's own status post

Yudhi Armyndharisa481bbfb7739
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.ts
index d997f787b..37b059a27 100644
--- a/src/engine/adapters/baileys-events.ts
+++ b/src/engine/adapters/baileys-events.ts
@@ -374,7 +374,14 @@ export class BaileysEvents {
});
return;
}
- const incoming = await this.mapMessage(msg, contentType, { skipMediaDownload: opts?.skipMedia });
+ // The account's own status post reaches the projector and is dropped there: a story is not a
+ // conversation, so no `message.sent` is emitted for it. Downloading its media first is work
+ // nothing consumes, and a story is a full-size photo or video. Everything else about the path
+ // is kept, so the message is still recorded and still guards against a repeat delivery.
+ const ownStatusPost = msg.key.fromMe === true && remoteJid === 'status@broadcast';
+ const incoming = await this.mapMessage(msg, contentType, {
+ skipMediaDownload: opts?.skipMedia || ownStatusPost,
+ });
if (msg.key.fromMe === true) {
this.host.getOnMessageCreate()?.(incoming);
} else {
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index 93f75d66b..ce50ccc6d 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -2419,6 +2419,39 @@ describe('BaileysAdapter inbound fan-out', () => {
expect(onMessageCreate).toHaveBeenCalledTimes(1);
});
+ // A story is not a conversation: the projector drops an own status post rather than reporting it,
+ // so downloading its media first is work nothing consumes, and a story is a full-size photo.
+ it('does not download the media of a status the account posted from its phone', async () => {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+ const baileys = jest.requireMock('@whiskeysockets/baileys') as {
+ getContentType: jest.Mock;
+ downloadMediaMessage: jest.Mock;
+ };
+ baileys.getContentType.mockReturnValue('imageMessage');
+ baileys.downloadMediaMessage.mockClear();
+
+ const onMessageCreate = jest.fn();
+ const adapter = newAdapter();
+ await adapter.initialize({ onMessageCreate });
+ fakeSock.fire('connection.update', { connection: 'open' });
+
+ fakeSock.fire('messages.upsert', {
+ type: 'append',
+ messages: [
+ {
+ key: { remoteJid: 'status@broadcast', fromMe: true, id: 'OWN_STATUS_1' },
+ message: { imageMessage: { mimetype: 'image/jpeg', caption: 'from the phone' } },
+ messageTimestamp: Math.floor(Date.now() / 1000) - 60,
+ },
+ ],
+ });
+ await new Promise(r => setImmediate(r));
+
+ expect(baileys.downloadMediaMessage).not.toHaveBeenCalled();
+ // Still reported, so nothing downstream changes: only the download is skipped.
+ expect(onMessageCreate).toHaveBeenCalledTimes(1);
+ });
+
// A store that cannot answer must not be read as "this was never sent": the only other outcome is
// the handler's catch, which drops the message, and Baileys acks the node before emitting it, so
// WhatsApp never sends it again. Fail open, and take the duplicate risk instead of the loss.