whatsapp-web.js 1.16.7 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/example.js CHANGED
@@ -1,4 +1,4 @@
1
- const { Client, Location, List, Buttons, LocalAuth } = require('./index');
1
+ const { Client, Location, List, Buttons, LocalAuth} = require('./index');
2
2
 
3
3
  const client = new Client({
4
4
  authStrategy: new LocalAuth(),
@@ -191,6 +191,8 @@ client.on('message', async msg => {
191
191
  let sections = [{title:'sectionTitle',rows:[{title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
192
192
  let list = new List('List body','btnText',sections,'Title','footer');
193
193
  client.sendMessage(msg.from, list);
194
+ } else if (msg.body === '!reaction') {
195
+ msg.react('👍');
194
196
  }
195
197
  });
196
198
 
package/index.d.ts CHANGED
@@ -114,7 +114,7 @@ declare namespace WAWebJS {
114
114
 
115
115
  /** Send a message to a specific chatId */
116
116
  sendMessage(chatId: string, content: MessageContent, options?: MessageSendOptions): Promise<Message>
117
-
117
+
118
118
  /** Searches for messages */
119
119
  searchMessages(query: string, options?: { chatId?: string, page?: number, limit?: number }): Promise<Message[]>
120
120
 
@@ -141,7 +141,7 @@ declare namespace WAWebJS {
141
141
  * @param displayName New display name
142
142
  */
143
143
  setDisplayName(displayName: string): Promise<boolean>
144
-
144
+
145
145
  /** Changes and returns the archive state of the Chat */
146
146
  unarchiveChat(chatId: string): Promise<boolean>
147
147
 
@@ -687,7 +687,7 @@ declare namespace WAWebJS {
687
687
  acceptGroupV4Invite: () => Promise<{status: number}>,
688
688
  /** Deletes the message from the chat */
689
689
  delete: (everyone?: boolean) => Promise<void>,
690
- /** Downloads and returns the attatched message media */
690
+ /** Downloads and returns the attached message media */
691
691
  downloadMedia: () => Promise<MessageMedia>,
692
692
  /** Returns the Chat this message was sent in */
693
693
  getChat: () => Promise<Chat>,
@@ -703,6 +703,8 @@ declare namespace WAWebJS {
703
703
  * If not, it will send the message in the same Chat as the original message was sent.
704
704
  */
705
705
  reply: (content: MessageContent, chatId?: string, options?: MessageSendOptions) => Promise<Message>,
706
+ /** React to this message with an emoji*/
707
+ react: (reaction: string) => Promise,
706
708
  /**
707
709
  * Forwards this message to another chat
708
710
  */
@@ -711,7 +713,7 @@ declare namespace WAWebJS {
711
713
  star: () => Promise<void>,
712
714
  /** Unstar this message */
713
715
  unstar: () => Promise<void>,
714
- /** Get information about message delivery statuso */
716
+ /** Get information about message delivery status */
715
717
  getInfo: () => Promise<MessageInfo | null>,
716
718
  /**
717
719
  * Gets the order associated with a given message
@@ -816,7 +818,7 @@ declare namespace WAWebJS {
816
818
  static fromUrl: (url: string, options?: MediaFromURLOptions) => Promise<MessageMedia>
817
819
  }
818
820
 
819
- export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
821
+ export type MessageContent = string | MessageMedia | Location | Contact | Contact[] | List | Buttons
820
822
 
821
823
  /**
822
824
  * Represents a Contact on WhatsApp
@@ -1287,7 +1289,7 @@ declare namespace WAWebJS {
1287
1289
  constructor(body: string, buttonText: string, sections: Array<any>, title?: string | null, footer?: string | null)
1288
1290
  }
1289
1291
 
1290
- /** Message type buttons */
1292
+ /** Message type Buttons */
1291
1293
  export class Buttons {
1292
1294
  body: string | MessageMedia
1293
1295
  buttons: Array<{ buttonId: string; buttonText: {displayText: string}; type: number }>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.16.7",
3
+ "version": "1.17.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
package/src/Client.js CHANGED
@@ -10,7 +10,7 @@ const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constan
10
10
  const { ExposeStore, LoadUtils } = require('./util/Injected');
11
11
  const ChatFactory = require('./factories/ChatFactory');
12
12
  const ContactFactory = require('./factories/ContactFactory');
13
- const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List } = require('./structures');
13
+ const { ClientInfo, Message, MessageMedia, Contact, Location, GroupNotification, Label, Call, Buttons, List} = require('./structures');
14
14
  const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
15
15
  const NoAuth = require('./authStrategies/NoAuth');
16
16
 
@@ -92,7 +92,12 @@ class Client extends EventEmitter {
92
92
  browser = await puppeteer.connect(puppeteerOpts);
93
93
  page = await browser.newPage();
94
94
  } else {
95
- browser = await puppeteer.launch(puppeteerOpts);
95
+ const browserArgs = [...(puppeteerOpts.args || [])];
96
+ if(!browserArgs.find(arg => arg.includes('--user-agent'))) {
97
+ browserArgs.push(`--user-agent=${this.options.userAgent}`);
98
+ }
99
+
100
+ browser = await puppeteer.launch({...puppeteerOpts, args: browserArgs});
96
101
  page = (await browser.pages())[0];
97
102
  }
98
103
 
@@ -580,7 +585,7 @@ class Client extends EventEmitter {
580
585
  internalOptions.list = content;
581
586
  content = '';
582
587
  }
583
-
588
+
584
589
  if (internalOptions.sendMediaAsSticker && internalOptions.attachment) {
585
590
  internalOptions.attachment = await Util.formatToWebpSticker(
586
591
  internalOptions.attachment, {
@@ -744,7 +749,7 @@ class Client extends EventEmitter {
744
749
 
745
750
  return couldSet;
746
751
  }
747
-
752
+
748
753
  /**
749
754
  * Gets the current connection state for the client
750
755
  * @returns {WAState}
@@ -184,7 +184,7 @@ class Chat extends Base {
184
184
  if (searchOptions && searchOptions.limit > 0) {
185
185
  while (msgs.length < searchOptions.limit) {
186
186
  const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat);
187
- if (!loadedMessages) break;
187
+ if (!loadedMessages || !loadedMessages.length) break;
188
188
  msgs = [...loadedMessages.filter(msgFilter), ...msgs];
189
189
  }
190
190
 
@@ -147,7 +147,7 @@ class GroupChat extends Chat {
147
147
  this.groupMetadata.desc = description;
148
148
  return true;
149
149
  }
150
-
150
+
151
151
  /**
152
152
  * Updates the group settings to only allow admins to send messages.
153
153
  * @param {boolean} [adminsOnly=true] Enable or disable this option
@@ -335,6 +335,18 @@ class Message extends Base {
335
335
  return this.client.sendMessage(chatId, content, options);
336
336
  }
337
337
 
338
+ /**
339
+ * React to this message with an emoji
340
+ * @param {string} reaction - Emoji to react with. Send an empty string to remove the reaction.
341
+ * @return {Promise}
342
+ */
343
+ async react(reaction){
344
+ await this.client.pupPage.evaluate(async (messageId, reaction) => {
345
+ const msg = await window.Store.Msg.get(messageId);
346
+ await window.Store.sendReactionToMsg(msg, reaction);
347
+ }, this.id._serialized, reaction);
348
+ }
349
+
338
350
  /**
339
351
  * Accept Group V4 Invite
340
352
  * @returns {Promise<Object>}
@@ -17,5 +17,5 @@ module.exports = {
17
17
  Call: require('./Call'),
18
18
  Buttons: require('./Buttons'),
19
19
  List: require('./List'),
20
- Payment: require('./Payment')
20
+ Payment: require('./Payment'),
21
21
  };
@@ -49,6 +49,7 @@ exports.ExposeStore = (moduleRaidStr) => {
49
49
  window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
50
50
  window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
51
51
  window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
52
+ window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
52
53
  window.Store.StickerTools = {
53
54
  ...window.mR.findModule('toWebpSticker')[0],
54
55
  ...window.mR.findModule('addWebpMetadata')[0]
@@ -99,7 +100,6 @@ exports.LoadUtils = () => {
99
100
  delete options.attachment;
100
101
  delete options.sendMediaAsSticker;
101
102
  }
102
-
103
103
  let quotedMsgOptions = {};
104
104
  if (options.quotedMessageId) {
105
105
  let quotedMessage = window.Store.Msg.get(options.quotedMessageId);
package/src/util/Util.js CHANGED
@@ -6,7 +6,6 @@ const { tmpdir } = require('os');
6
6
  const ffmpeg = require('fluent-ffmpeg');
7
7
  const webp = require('node-webpmux');
8
8
  const fs = require('fs').promises;
9
-
10
9
  const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
11
10
 
12
11
  /**