refactor(client): move sendReaction method to the Client (#201695)

`Message.react` moved to `Client.sendReaction`
This commit is contained in:
Maksim Koryukov 2026-04-12 08:30:32 -04:00 • committed by GitHub
commit 11594b2887
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 18 deletions

6
index.d.ts vendored
View file

@ -210,6 +210,12 @@ declare namespace WAWebJS {
options?: MessageSendOptions, options?: MessageSendOptions,
): Promise<Message>; ): Promise<Message>;
/** Send a reaction to a specific messageId */
sendReaction(
messageId: string,
reaction: string,
): Promise<void>;
/** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */ /** Sends a channel admin invitation to a user, allowing them to become an admin of the channel */
sendChannelAdminInvite( sendChannelAdminInvite(
chatId: string, chatId: string,

View file

@ -1540,6 +1540,33 @@ class Client extends EventEmitter {
return sentMsg ? new Message(this, sentMsg) : undefined; 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 * @typedef {Object} SendChannelAdminInviteOptions
* @property {?string} comment The comment to be added to an invitation * @property {?string} comment The comment to be added to an invitation

View file

@ -477,24 +477,7 @@ class Message extends Base {
* @return {Promise} * @return {Promise}
*/ */
async react(reaction) { async react(reaction) {
await this.client.pupPage.evaluate( return this.client.sendReaction(this.id._serialized, reaction);
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,
);
} }
/** /**