Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): keep reactions to a received broadcast-list message
Yudhi Armyndharis684d4c1ecd64
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.tsindex c0f01ed41..31feb45e4 100644--- a/src/engine/adapters/baileys-events.ts+++ b/src/engine/adapters/baileys-events.ts@@ -575,7 +575,10 @@ export class BaileysEvents {** A reaction to a message the account sent to a broadcast list is exempt: Baileys files the* own-device copy under the list jid (`<id>@broadcast`), while each recipient reacts from their 1:1- * chat, so no chat can ever match it. Edits and revokes stay strict.+ * chat, so no chat can ever match it. A list message the account received is filed under the list+ * jid too, but Baileys shows it in the 1:1 chat with its sender (getChatId in process-message.js), so+ * a reaction to it is checked against that sender, whose other-dialect id Baileys puts in+ * remoteJidAlt. Edits and revokes stay strict.*/private async targetsForeignMessage(targetId: string | null | undefined,@@ -587,10 +590,13 @@ export class BaileysEvents {? (await this.readStoredMessage(targetId, 'checking what an edit, revoke or reaction targets'))?.key: undefined;if (!original) return false;- if (kind === 'reaction' && original.fromMe === true && original.remoteJid?.endsWith('@broadcast')) return false;+ const broadcast = kind === 'reaction' && !!original.remoteJid?.endsWith('@broadcast');+ if (broadcast && original.fromMe === true) return false;+ const originalChat =+ broadcast && original.remoteJid !== 'status@broadcast' ? original.participant : original.remoteJid;const neutral = (jid: string): string => this.host.toNeutralJid(jid);const foreign =- differentWaIds([original.remoteJid, original.remoteJidAlt], [key.remoteJid, key.remoteJidAlt], neutral) ||+ differentWaIds([originalChat, original.remoteJidAlt], [key.remoteJid, key.remoteJidAlt], neutral) ||(checkAuthor &&((original.fromMe === true) !== (key.fromMe === true) ||(key.fromMe !== true &&diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 339f1030f..fdd328fe5 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -3407,7 +3407,16 @@ describe('BaileysAdapter inbound fan-out', () => {expect(await deliver(original, key, reaction)).toBe(1);expect(await deliver(original, key, edit)).toBe(0);expect(await deliver(original, key, revoke)).toBe(0);- expect(await deliver({ ...original, fromMe: false }, key, reaction)).toBe(0);+ expect(await deliver({ ...original, fromMe: false, participant: bob }, key, reaction)).toBe(0);+ });++ // A broadcast-list message the account received is filed under the list jid with its sender as+ // participant, and Baileys shows it, and files reactions to it, in the 1:1 chat with that sender.+ it('keeps a reaction to a received broadcast-list message from its sender chat, but not from another', async () => {+ const original = { remoteJid: '1700000000@broadcast', fromMe: false, participant: alice };+ expect(await deliver(original, { remoteJid: alice, fromMe: true }, reaction)).toBe(1);+ expect(await deliver(original, { remoteJid: alice, fromMe: false }, reaction)).toBe(1);+ expect(await deliver(original, { remoteJid: bob, fromMe: false }, reaction)).toBe(0);});it('keeps an edit whose chat is an unresolved lid, since it may be the stored phone-number chat', async () => {