Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(baileys): attribute a phone-made 1:1 reaction to the account

Yudhi Armyndharis594d230e3a75
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.ts
index cd2299091..817f541a8 100644
--- a/src/engine/adapters/baileys-events.ts
+++ b/src/engine/adapters/baileys-events.ts
@@ -333,7 +333,12 @@ export class BaileysEvents {
messageId: rm?.key?.id ?? '',
chatId: this.host.toNeutralJid(remoteJid),
reaction: rm?.text ?? '',
- senderId: this.host.toNeutralJid(msg.key.participant ?? remoteJid),
+ // A 1:1 key names the chat partner, not the author: for a reaction the account made from
+ // its phone (fromMe) the reactor is the account itself. Group and status keys carry the
+ // author as `participant`, own reactions included, which the edit branch reads the same way.
+ senderId: this.host.toNeutralJid(
+ msg.key.participant ?? (msg.key.fromMe === true ? this.host.normalizedSelfJid() : remoteJid),
+ ),
};
this.host.getOnMessageReaction()?.(event);
return;
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index 1f06325d9..914032f5a 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -3128,6 +3128,56 @@ describe('BaileysAdapter inbound fan-out', () => {
expect(event.senderId).toBe('[email protected]'); // canonicalized to the neutral dialect
});
+ it.each(['notify', 'append'])(
+ 'reactionMessage: attributes a 1:1 reaction made from the phone to the account (%s)',
+ async type => {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+ const baileys = jest.requireMock('@whiskeysockets/baileys') as { getContentType: jest.Mock };
+ baileys.getContentType.mockReturnValue('reactionMessage');
+ const onMessageReaction = jest.fn();
+ const adapter = newAdapter();
+ await adapter.initialize({ onMessageReaction });
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ // A 1:1 key from another device of the account names the partner and carries no participant.
+ fakeSock.fire('messages.upsert', {
+ type,
+ messages: [
+ {
+ key: { remoteJid: '[email protected]', fromMe: true, id: 'REACT_SELF' },
+ message: { reactionMessage: { key: { id: 'TARGET_MSG_ID' }, text: 'πŸ‘' } },
+ messageTimestamp: 1700000024,
+ },
+ ],
+ });
+ await new Promise(r => setImmediate(r));
+ expect(onMessageReaction).toHaveBeenCalledWith(
+ expect.objectContaining({ chatId: '[email protected]', senderId: '[email protected]', reaction: 'πŸ‘' }),
+ );
+ },
+ );
+
+ it('reactionMessage: keeps the participant as the reactor of an own group reaction', async () => {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+ const baileys = jest.requireMock('@whiskeysockets/baileys') as { getContentType: jest.Mock };
+ baileys.getContentType.mockReturnValue('reactionMessage');
+ const onMessageReaction = jest.fn();
+ const adapter = newAdapter();
+ await adapter.initialize({ onMessageReaction });
+ fakeSock.user = { id: '628999:[email protected]', name: 'Me' };
+ fakeSock.fire('messages.upsert', {
+ type: 'notify',
+ messages: [
+ {
+ key: { remoteJid: '[email protected]', fromMe: true, id: 'REACT_GRP', participant: '[email protected]' },
+ message: { reactionMessage: { key: { id: 'TARGET_MSG_ID' }, text: 'πŸ‘' } },
+ messageTimestamp: 1700000024,
+ },
+ ],
+ });
+ await new Promise(r => setImmediate(r));
+ expect(onMessageReaction).toHaveBeenCalledWith(expect.objectContaining({ senderId: '[email protected]' }));
+ });
+
describe('contentless protocol traffic on the live path (#1568)', () => {
/** Push one group message through the live upsert handler with Baileys' real content-type resolution. */
const fireLive = async (