From 9fa9ccb2c74c46c47439d531c0e30b110e83f832 Mon Sep 17 00:00:00 2001 From: Maksim Koryukov Date: Sat, 6 Dec 2025 08:41:24 -0400 Subject: [PATCH] feat(client): add `sendReaction` method to the Client --- index.d.ts | 3 +++ src/Client.js | 19 +++++++++++++++++++ src/structures/Message.js | 8 +------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1b6653ac26e..f35a3c9c8eb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -172,6 +172,9 @@ declare namespace WAWebJS { /** Send a message to a specific chatId */ sendMessage(chatId: string, content: MessageContent, 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, channelId: string, options?: { comment?: string }): Promise diff --git a/src/Client.js b/src/Client.js index 9cc337518ef..702303f883a 100644 --- a/src/Client.js +++ b/src/Client.js @@ -905,6 +905,25 @@ class Client extends EventEmitter { }, chatId); } + + /** + * React to a message with an emoji + * @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.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0]; + if(!msg) return null; + + await window.Store.sendReactionToMsg(msg, reaction); + }, messageId, reaction); + } + + /** * An object representing mentions of groups * @typedef {Object} GroupMention diff --git a/src/structures/Message.js b/src/structures/Message.js index bd5f8918999..4437016dc84 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -407,13 +407,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.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0]; - if(!msg) return null; - await window.Store.sendReactionToMsg(msg, reaction); - }, this.id._serialized, reaction); + return this.client.sendReaction(this.id._serialized, reaction) } /**