Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(baileys): read the disappearing timer off every message type

Yudhi Armyndharisde2bd6ba5982
diff --git a/src/engine/adapters/baileys-message-mapper.spec.ts b/src/engine/adapters/baileys-message-mapper.spec.ts
index 55f0a360e..d632a42ae 100644
--- a/src/engine/adapters/baileys-message-mapper.spec.ts
+++ b/src/engine/adapters/baileys-message-mapper.spec.ts
@@ -1,4 +1,5 @@
import {
+ BaileysContextContent,
BaileysIncomingFields,
baileysChatJid,
buildIncomingMessageFromBaileys,
@@ -255,6 +256,23 @@ describe('extractBaileysContext (quoted body shares the live body extractor)', (
});
});
+ it.each([
+ 'productMessage',
+ 'contactMessage',
+ 'contactsArrayMessage',
+ 'pollCreationMessageV3',
+ 'liveLocationMessage',
+ 'orderMessage',
+ 'eventMessage',
+ ])('reads the disappearing-messages timer off a %s', type => {
+ const content = { [type]: { contextInfo: { expiration: 86400 } } } as BaileysContextContent;
+ expect(extractBaileysContext(content).ephemeralDuration).toBe(86400);
+ });
+
+ it('reads no timer when no content node carries one', () => {
+ expect(extractBaileysContext({ conversation: 'hi' } as BaileysContextContent).ephemeralDuration).toBeUndefined();
+ });
+
it('carries a quote from a button-reply contextInfo', () => {
expect(
extractBaileysContext({
diff --git a/src/engine/adapters/baileys-message-mapper.ts b/src/engine/adapters/baileys-message-mapper.ts
index f4e4add92..e41677055 100644
--- a/src/engine/adapters/baileys-message-mapper.ts
+++ b/src/engine/adapters/baileys-message-mapper.ts
@@ -862,9 +862,16 @@ export function extractBaileysContext(content: BaileysContextContent): BaileysMe
// surface it so the store/viewer can render the story the way it was posted.
const extText = content.extendedTextMessage;
const contextInfo = subForContext?.contextInfo;
+ // WhatsApp stamps the timer on every message in a disappearing chat, a product, poll, contact card, live
+ // location, order or event included, so any content node answers when the carriers above have none.
+ const expiration =
+ contextInfo?.expiration ??
+ Object.values(content)
+ .map(node => (node as BaileysContextCarrier | null | undefined)?.contextInfo?.expiration)
+ .find((e): e is number => typeof e === 'number' && e > 0);
const context: BaileysMessageContext = {
- ephemeralDuration: contextInfo?.expiration ?? undefined,
+ ephemeralDuration: expiration ?? undefined,
mentionedJids: contextInfo?.mentionedJid ?? undefined,
backgroundArgb: typeof extText?.backgroundArgb === 'number' ? extText.backgroundArgb : undefined,
font: typeof extText?.font === 'number' ? extText.font : undefined,