whatsapp-web.js 1.24.0 → 1.26.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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <p>
8
8
  <a href="https://www.npmjs.com/package/whatsapp-web.js"><img src="https://img.shields.io/npm/v/whatsapp-web.js.svg" alt="npm" /></a>
9
9
  <a href="https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765"><img src="https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg" alt="Depfu" /></a>
10
- <img src="https://img.shields.io/badge/WhatsApp_Web-2.2346.52-brightgreen.svg" alt="WhatsApp_Web 2.2346.52" />
10
+ <img src="https://img.shields.io/badge/WhatsApp_Web-2.3000.1016590837-brightgreen.svg" alt="WhatsApp_Web 2.2346.52" />
11
11
  <a href="https://discord.gg/H7DqQs4"><img src="https://img.shields.io/discord/698610475432411196.svg?logo=discord" alt="Discord server" /></a>
12
12
  </p>
13
13
  <br />
package/example.js CHANGED
@@ -5,19 +5,30 @@ const client = new Client({
5
5
  // proxyAuthentication: { username: 'username', password: 'password' },
6
6
  puppeteer: {
7
7
  // args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
8
- headless: false
8
+ headless: false,
9
9
  }
10
10
  });
11
11
 
12
+ // client initialize does not finish at ready now.
12
13
  client.initialize();
13
14
 
14
15
  client.on('loading_screen', (percent, message) => {
15
16
  console.log('LOADING SCREEN', percent, message);
16
17
  });
17
18
 
18
- client.on('qr', (qr) => {
19
+ // Pairing code only needs to be requested once
20
+ let pairingCodeRequested = false;
21
+ client.on('qr', async (qr) => {
19
22
  // NOTE: This event will not be fired if a session is specified.
20
23
  console.log('QR RECEIVED', qr);
24
+
25
+ // paiuting code example
26
+ const pairingCodeEnabled = false;
27
+ if (pairingCodeEnabled && !pairingCodeRequested) {
28
+ const pairingCode = await client.requestPairingCode('96170100100'); // enter the target phone number
29
+ console.log('Pairing code enabled, code: '+ pairingCode);
30
+ pairingCodeRequested = true;
31
+ }
21
32
  });
22
33
 
23
34
  client.on('authenticated', () => {
@@ -29,8 +40,18 @@ client.on('auth_failure', msg => {
29
40
  console.error('AUTHENTICATION FAILURE', msg);
30
41
  });
31
42
 
32
- client.on('ready', () => {
43
+ client.on('ready', async () => {
33
44
  console.log('READY');
45
+ const debugWWebVersion = await client.getWWebVersion();
46
+ console.log(`WWebVersion = ${debugWWebVersion}`);
47
+
48
+ client.pupPage.on('pageerror', function(err) {
49
+ console.log('Page error: ' + err.toString());
50
+ });
51
+ client.pupPage.on('error', function(err) {
52
+ console.log('Page error: ' + err.toString());
53
+ });
54
+
34
55
  });
35
56
 
36
57
  client.on('message', async msg => {
@@ -418,7 +439,7 @@ client.on('message', async msg => {
418
439
  requesterIds: ['number1@c.us', 'number2@c.us'],
419
440
  sleep: null
420
441
  });
421
- } else {
442
+ } else if (msg.body === '!pinmsg') {
422
443
  /**
423
444
  * Pins a message in a chat, a method takes a number in seconds for the message to be pinned.
424
445
  * WhatsApp default values for duration to pass to the method are:
@@ -429,6 +450,14 @@ client.on('message', async msg => {
429
450
  */
430
451
  const result = await msg.pin(60); // Will pin a message for 1 minute
431
452
  console.log(result); // True if the operation completed successfully, false otherwise
453
+ }else if (msg.body === '!howManyConnections'){
454
+ /**
455
+ * Get user device count by ID
456
+ * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
457
+ * So for a non-enterprise user with one WaWeb connection it should return "2"
458
+ */
459
+ let deviceCount = await client.getContactDeviceCount(msg.from);
460
+ await msg.reply(`You have *${deviceCount}* devices connected`);
432
461
  }
433
462
  });
434
463
 
@@ -595,6 +624,10 @@ client.on('group_membership_request', async (notification) => {
595
624
  await client.rejectGroupMembershipRequests(notification.chatId, notification.author);
596
625
  });
597
626
 
627
+ client.on('message_reaction', async (reaction) => {
628
+ console.log('REACTION RECEIVED', reaction);
629
+ });
630
+
598
631
  client.on('vote_update', (vote) => {
599
632
  /** The vote that was affected: */
600
633
  console.log(vote);
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { EventEmitter } from 'events'
3
3
  import { RequestInit } from 'node-fetch'
4
4
  import * as puppeteer from 'puppeteer'
5
+ import InterfaceController from './src/util/InterfaceController'
5
6
 
6
7
  declare namespace WAWebJS {
7
8
 
@@ -17,6 +18,9 @@ declare namespace WAWebJS {
17
18
  /** Puppeteer browser running WhatsApp Web */
18
19
  pupBrowser?: puppeteer.Browser
19
20
 
21
+ /** Client interactivity interface */
22
+ interface?: InterfaceController
23
+
20
24
  /**Accepts an invitation to join a group */
21
25
  acceptInvite(inviteCode: string): Promise<string>
22
26
 
@@ -111,6 +115,14 @@ declare namespace WAWebJS {
111
115
  */
112
116
  muteChat(chatId: string, unmuteDate?: Date): Promise<void>
113
117
 
118
+ /**
119
+ * Request authentication via pairing code instead of QR code
120
+ * @param phoneNumber - Phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil)
121
+ * @param showNotification - Show notification to pair on phone number
122
+ * @returns {Promise<string>} - Returns a pairing code in format "ABCDEFGH"
123
+ */
124
+ requestPairingCode(phoneNumber: string, showNotification = true): Promise<string>
125
+
114
126
  /** Force reset of connection state for the client */
115
127
  resetState(): Promise<void>
116
128
 
@@ -164,7 +176,15 @@ declare namespace WAWebJS {
164
176
  * @param flag true/false on or off
165
177
  */
166
178
  setAutoDownloadVideos(flag: boolean): Promise<void>
167
-
179
+
180
+ /**
181
+ * Get user device count by ID
182
+ * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
183
+ * So for a non-enterprise user with one WaWeb connection it should return "2"
184
+ * @param {string} contactId
185
+ */
186
+ getContactDeviceCount(contactId: string): Promise<Number>
187
+
168
188
  /** Changes and returns the archive state of the Chat */
169
189
  unarchiveChat(chatId: string): Promise<boolean>
170
190
 
@@ -215,7 +235,7 @@ declare namespace WAWebJS {
215
235
  /** Emitted when the client has been disconnected */
216
236
  on(event: 'disconnected', listener: (
217
237
  /** reason that caused the disconnect */
218
- reason: WAState | "NAVIGATION"
238
+ reason: WAState | "LOGOUT"
219
239
  ) => void): this
220
240
 
221
241
  /** Emitted when a user joins the chat via invite link or is added by an admin */
@@ -1097,6 +1117,8 @@ declare namespace WAWebJS {
1097
1117
  }[]
1098
1118
  /** Send 'seen' status */
1099
1119
  sendSeen?: boolean
1120
+ /** Bot Wid when doing a bot mention like @Meta AI */
1121
+ invokedBotWid?: string
1100
1122
  /** Media to be sent */
1101
1123
  media?: MessageMedia
1102
1124
  /** Extra options */
package/index.js CHANGED
@@ -27,7 +27,6 @@ module.exports = {
27
27
  NoAuth: require('./src/authStrategies/NoAuth'),
28
28
  LocalAuth: require('./src/authStrategies/LocalAuth'),
29
29
  RemoteAuth: require('./src/authStrategies/RemoteAuth'),
30
- LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),
31
30
 
32
31
  ...Constants
33
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.24.0",
3
+ "version": "1.26.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",