From 11594b28878276c433af3f046ed169f03d9a7a93 Mon Sep 17 00:00:00 2001 From: Maksim Koryukov Date: Sun, 12 Apr 2026 08:30:32 -0400 Subject: [PATCH] refactor(client): move `sendReaction` method to the Client (#201695) `Message.react` moved to `Client.sendReaction` --- index.d.ts | 6 ++++++ src/Client.js | 27 +++++++++++++++++++++++++++ src/structures/Message.js | 19 +------------------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9fc11bb..13051ee 100644 --- a/index.d.ts +++ b/index.d.ts @@ -210,6 +210,12 @@ declare namespace WAWebJS { options?: MessageSendOptions, ): Promise; + /** Send a reaction to a specific messageId */ + sendReaction( + messageId: string, + reaction: string, + ): Promise; + /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */ sendChannelAdminInvite( chatId: string, diff --git a/src/Client.js b/src/Client.js index 145e110..15727c8 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1540,6 +1540,33 @@ class Client extends EventEmitter { return sentMsg ? new Message(this, sentMsg) : undefined; } + /** + * Send an emoji reaction to a specific message + * @param {string} messageId - Id of the message to add the reaction. + * @param {string} reaction - Emoji to react with. Send an empty string to remove the reaction. + * @return {Promise} + */ + async sendReaction(messageId, reaction) { + await this.pupPage.evaluate( + async (messageId, reaction) => { + if (!messageId) return null; + const msg = + window.require('WAWebCollections').Msg.get(messageId) || + ( + await window + .require('WAWebCollections') + .Msg.getMessagesById([messageId]) + )?.messages?.[0]; + if (!msg) return null; + await window + .require('WAWebSendReactionMsgAction') + .sendReactionToMsg(msg, reaction); + }, + messageId, + reaction, + ); + } + /** * @typedef {Object} SendChannelAdminInviteOptions * @property {?string} comment The comment to be added to an invitation diff --git a/src/structures/Message.js b/src/structures/Message.js index 8ac970e..b3323bf 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -477,24 +477,7 @@ class Message extends Base { * @return {Promise} */ async react(reaction) { - await this.client.pupPage.evaluate( - async (messageId, reaction) => { - if (!messageId) return null; - const msg = - window.require('WAWebCollections').Msg.get(messageId) || - ( - await window - .require('WAWebCollections') - .Msg.getMessagesById([messageId]) - )?.messages?.[0]; - if (!msg) return null; - await window - .require('WAWebSendReactionMsgAction') - .sendReactionToMsg(msg, reaction); - }, - this.id._serialized, - reaction, - ); + return this.client.sendReaction(this.id._serialized, reaction); } /**