Reaction feature added. (#1400)

* Fix get order.

* Fix types.

* Add set picture for profile and for groups.

* Fix bug.

* Fix

* Fix types

* Fix eslint

* Add send reaction feature.

* Add send reaction feature.

* Add set picture for profile and for groups.

* Add send reaction feature.

* Add send reaction feature.

* Add send reaction feature.

* Add send reaction feature.

* Add send reaction feature.

* Add send reaction feature.

* Update src/structures/Reaction.js

Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>

* Bug fixes.

* Bug fixes.

* Bug fixes.

* Fix

* Fix

* Fix example

* Fix conflict

* Fix conflict

* Fix conflict

* Fix conflict

* Fix conflict

* Fix conflict

* move implementation to message model

Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
Co-authored-by: Pedro Lopez <pedroslopez@me.com>
This commit is contained in:
Alon Schwartzblat
2022-06-21 07:46:07 +03:00
committed by GitHub
parent a0b18fb685
commit 61c0a6be56
9 changed files with 31 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
const { Client, Location, List, Buttons, LocalAuth } = require('./index'); const { Client, Location, List, Buttons, LocalAuth} = require('./index');
const client = new Client({ const client = new Client({
authStrategy: new LocalAuth(), authStrategy: new LocalAuth(),
@@ -191,6 +191,8 @@ client.on('message', async msg => {
let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}]; let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
let list = new List('List body','btnText',sections,'Title','footer'); let list = new List('List body','btnText',sections,'Title','footer');
client.sendMessage(msg.from, list); client.sendMessage(msg.from, list);
} else if (msg.body === '!reaction') {
msg.react('👍');
} }
}); });

14
index.d.ts vendored
View File

@@ -114,7 +114,7 @@ declare namespace WAWebJS {
/** Send a message to a specific chatId */ /** Send a message to a specific chatId */
sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message> sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
/** Searches for messages */ /** Searches for messages */
searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]> searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
@@ -141,7 +141,7 @@ declare namespace WAWebJS {
* @param displayName New display name * @param displayName New display name
*/ */
setDisplayName(displayName: string): Promise<boolean> setDisplayName(displayName: string): Promise<boolean>
/** Changes and returns the archive state of the Chat */ /** Changes and returns the archive state of the Chat */
unarchiveChat(chatId: string): Promise<boolean> unarchiveChat(chatId: string): Promise<boolean>
@@ -687,7 +687,7 @@ declare namespace WAWebJS {
acceptGroupV4Invite: () => Promise<{status: number}>, acceptGroupV4Invite: () => Promise<{status: number}>,
/** Deletes the message from the chat */ /** Deletes the message from the chat */
delete: (everyone?: boolean) => Promise<void>, delete: (everyone?: boolean) => Promise<void>,
/** Downloads and returns the attatched message media */ /** Downloads and returns the attached message media */
downloadMedia: () => Promise<MessageMedia>, downloadMedia: () => Promise<MessageMedia>,
/** Returns the Chat this message was sent in */ /** Returns the Chat this message was sent in */
getChat: () => Promise<Chat>, getChat: () => Promise<Chat>,
@@ -703,6 +703,8 @@ declare namespace WAWebJS {
* If not, it will send the message in the same Chat as the original message was sent. * If not, it will send the message in the same Chat as the original message was sent.
*/ */
reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>, reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>,
/** React to this message with an emoji*/
react: (reaction: string) => Promise,
/** /**
* Forwards this message to another chat * Forwards this message to another chat
*/ */
@@ -711,7 +713,7 @@ declare namespace WAWebJS {
star: () => Promise<void>, star: () => Promise<void>,
/** Unstar this message */ /** Unstar this message */
unstar: () => Promise<void>, unstar: () => Promise<void>,
/** Get information about message delivery statuso */ /** Get information about message delivery status */
getInfo: () => Promise<MessageInfo | null>, getInfo: () => Promise<MessageInfo | null>,
/** /**
* Gets the order associated with a given message * Gets the order associated with a given message
@@ -816,7 +818,7 @@ declare namespace WAWebJS {
static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia> static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
} }
export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
/** /**
* Represents a Contact on WhatsApp * Represents a Contact on WhatsApp
@@ -1287,7 +1289,7 @@ declare namespace WAWebJS {
constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null) constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null)
} }
/** Message type buttons */ /** Message type Buttons */
export class Buttons { export class Buttons {
body: string | MessageMedia body: string | MessageMedia
buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }> buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>

View File

@@ -10,7 +10,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constan
const { ExposeStore, LoadUtils } = require('./util/Injected'); const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory'); const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory'); const ContactFactory = require('./factories/ContactFactory');
const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List } = require('./structures'); const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List} = require('./structures');
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth'); const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
const NoAuth = require('./authStrategies/NoAuth'); const NoAuth = require('./authStrategies/NoAuth');
@@ -585,7 +585,7 @@ class Client extends EventEmitter {
internalOptions.list = content; internalOptions.list = content;
content = ''; content = '';
} }
if (internalOptions.sendMediaAsSticker && internalOptions.attachment) { if (internalOptions.sendMediaAsSticker && internalOptions.attachment) {
internalOptions.attachment = await Util.formatToWebpSticker( internalOptions.attachment = await Util.formatToWebpSticker(
internalOptions.attachment, { internalOptions.attachment, {
@@ -749,7 +749,7 @@ class Client extends EventEmitter {
return couldSet; return couldSet;
} }
/** /**
* Gets the current connection state for the client * Gets the current connection state for the client
* @returns {WAState} * @returns {WAState}

View File

@@ -147,7 +147,7 @@ class GroupChat extends Chat {
this.groupMetadata.desc = description; this.groupMetadata.desc = description;
return true; return true;
} }
/** /**
* Updates the group settings to only allow admins to send messages. * Updates the group settings to only allow admins to send messages.
* @param {boolean} [adminsOnly=true] Enable or disable this option * @param {boolean} [adminsOnly=true] Enable or disable this option

View File

@@ -335,6 +335,18 @@ class Message extends Base {
return this.client.sendMessage(chatId, content, options); return this.client.sendMessage(chatId, content, options);
} }
/**
* React to this message with an emoji
* @param {string} reaction - Emoji to react with. Send an empty string to remove the reaction.
* @return {Promise}
*/
async react(reaction){
await this.client.pupPage.evaluate(async (messageId, reaction) => {
const msg = await window.Store.Msg.get(messageId);
await window.Store.sendReactionToMsg(msg, reaction);
}, this.id._serialized, reaction);
}
/** /**
* Accept Group V4 Invite * Accept Group V4 Invite
* @returns {Promise<Object>} * @returns {Promise<Object>}

View File

@@ -17,5 +17,5 @@ module.exports = {
Call: require('./Call'), Call: require('./Call'),
Buttons: require('./Buttons'), Buttons: require('./Buttons'),
List: require('./List'), List: require('./List'),
Payment: require('./Payment') Payment: require('./Payment'),
}; };

View File

@@ -49,6 +49,7 @@ exports.ExposeStore = (moduleRaidStr) => {
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups; window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0]; window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0]; window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
window.Store.StickerTools = { window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0] ...window.mR.findModule('addWebpMetadata')[0]
@@ -99,7 +100,6 @@ exports.LoadUtils = () => {
delete options.attachment; delete options.attachment;
delete options.sendMediaAsSticker; delete options.sendMediaAsSticker;
} }
let quotedMsgOptions = {}; let quotedMsgOptions = {};
if (options.quotedMessageId) { if (options.quotedMessageId) {
let quotedMessage = window.Store.Msg.get(options.quotedMessageId); let quotedMessage = window.Store.Msg.get(options.quotedMessageId);

View File

@@ -6,7 +6,6 @@ const { tmpdir } = require('os');
const ffmpeg = require('fluent-ffmpeg'); const ffmpeg = require('fluent-ffmpeg');
const webp = require('node-webpmux'); const webp = require('node-webpmux');
const fs = require('fs').promises; const fs = require('fs').promises;
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k); const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
/** /**

View File

@@ -332,6 +332,7 @@ describe('Client', function() {
'QueryOrder', 'QueryOrder',
'QueryProduct', 'QueryProduct',
'PresenceUtils', 'PresenceUtils',
'ProfilePic',
'QueryExist', 'QueryExist',
'QueryProduct', 'QueryProduct',
'QueryOrder', 'QueryOrder',
@@ -347,7 +348,7 @@ describe('Client', function() {
'Wap', 'Wap',
'WidFactory', 'WidFactory',
'findCommonGroups', 'findCommonGroups',
'ProfilePic', 'sendReactionToMsg',
]; ];
const loadedModules = await client.pupPage.evaluate((expectedModules) => { const loadedModules = await client.pupPage.evaluate((expectedModules) => {