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 an own broadcast-list message
Yudhi Armyndharis4b976b4eec54
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.tsindex ebb8b7cd0..dcf815973 100644--- a/src/engine/adapters/baileys-events.ts+++ b/src/engine/adapters/baileys-events.ts@@ -352,7 +352,7 @@ export class BaileysEvents {// --- reactionMessage: don't emit onMessage ---if (contentType === 'reactionMessage') {const rm = normalizedRoot?.reactionMessage;- if (await this.targetsForeignMessage(rm?.key?.id, msg.key, false)) return;+ if (await this.targetsForeignMessage(rm?.key?.id, msg.key, false, 'reaction')) return;const event: ReactionEvent = {messageId: rm?.key?.id ?? '',chatId: this.host.toNeutralJid(remoteJid),@@ -465,16 +465,22 @@ export class BaileysEvents {* emits it as-is and the projector updates the stored row by id alone, so a contact who knows an id* could rewrite or erase that message. Fails open: with no stored original, or ids that cannot be* compared (see {@link differentWaIds}), the event goes through as it always has.+ *+ * 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.*/private async targetsForeignMessage(targetId: string | null | undefined,key: WAMessageKey,checkAuthor: boolean,+ kind?: 'reaction',): Promise<boolean> {const original = targetId? (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 neutral = (jid: string): string => this.host.toNeutralJid(jid);const foreign =differentWaIds([original.remoteJid, original.remoteJidAlt], [key.remoteJid, key.remoteJidAlt], neutral) ||diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 580a351b3..c312f79e4 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -3368,6 +3368,17 @@ describe('BaileysAdapter inbound fan-out', () => {expect(await deliver({ remoteJid: alice, fromMe: false }, { remoteJid: alice, fromMe: false }, message)).toBe(1);});+ // Baileys files the own-device copy of a broadcast-list send under the list jid, while each+ // recipient reacts from their 1:1 chat, so the chats can never match for a reaction.+ it('keeps a recipient reaction to a broadcast-list message the account sent, but not an edit or revoke', async () => {+ const original = { remoteJid: '1700000000@broadcast', fromMe: true };+ const key = { remoteJid: alice, fromMe: false };+ 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);+ });+it('keeps an edit whose chat is an unresolved lid, since it may be the stored phone-number chat', async () => {expect(await deliver({ remoteJid: alice, fromMe: false }, { remoteJid: '99887766@lid', fromMe: false }, edit),