whatsapp-web.js 1.18.3 → 1.19.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
@@ -1,4 +1,4 @@
1
- [![npm](https://img.shields.io/npm/v/whatsapp-web.js.svg)](https://www.npmjs.com/package/whatsapp-web.js) [![Depfu](https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg)](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ![WhatsApp_Web 2.2241.6](https://img.shields.io/badge/WhatsApp_Web-2.2241.6-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4)
1
+ [![npm](https://img.shields.io/npm/v/whatsapp-web.js.svg)](https://www.npmjs.com/package/whatsapp-web.js) [![Depfu](https://badges.depfu.com/badges/4a65a0de96ece65fdf39e294e0c8dcba/overview.svg)](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ![WhatsApp_Web 2.2301.6](https://img.shields.io/badge/WhatsApp_Web-2.2301.6-brightgreen.svg) [![Discord Chat](https://img.shields.io/discord/698610475432411196.svg?logo=discord)](https://discord.gg/H7DqQs4)
2
2
 
3
3
  # whatsapp-web.js
4
4
  A WhatsApp API client that connects through the WhatsApp Web browser app
@@ -94,7 +94,7 @@ You can support the maintainer of this project through the links below
94
94
 
95
95
  - [Support via GitHub Sponsors](https://github.com/sponsors/pedroslopez)
96
96
  - [Support via PayPal](https://www.paypal.me/psla/)
97
- - [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $100 in credit when you sign up (Referral)
97
+ - [Sign up for DigitalOcean](https://m.do.co/c/73f906a36ed4) and get $200 in credit when you sign up (Referral)
98
98
 
99
99
  ## Disclaimer
100
100
 
package/example.js CHANGED
@@ -257,6 +257,15 @@ client.on('change_state', state => {
257
257
  console.log('CHANGE STATE', state );
258
258
  });
259
259
 
260
+ // Change to false if you don't want to reject incoming calls
261
+ let rejectCalls = true;
262
+
263
+ client.on('call', async (call) => {
264
+ console.log('Call received, rejecting. GOTO Line 261 to disable', call);
265
+ if (rejectCalls) await call.reject();
266
+ await client.sendMessage(call.from, `[${call.fromMe ? 'Outgoing' : 'Incoming'}] Phone call from ${call.from}, type ${call.isGroup ? 'group' : ''} ${call.isVideo ? 'video' : 'audio'} call. ${rejectCalls ? 'This call was automatically rejected by the script.' : ''}`);
267
+ });
268
+
260
269
  client.on('disconnected', (reason) => {
261
270
  console.log('Client was logged out', reason);
262
271
  });
package/index.d.ts CHANGED
@@ -506,7 +506,8 @@ declare namespace WAWebJS {
506
506
  DISCONNECTED = 'disconnected',
507
507
  STATE_CHANGED = 'change_state',
508
508
  BATTERY_CHANGED = 'change_battery',
509
- REMOTE_SESSION_SAVED = 'remote_session_saved'
509
+ REMOTE_SESSION_SAVED = 'remote_session_saved',
510
+ CALL = 'call'
510
511
  }
511
512
 
512
513
  /** Group notification types */
@@ -1326,6 +1327,9 @@ declare namespace WAWebJS {
1326
1327
  webClientShouldHandle: boolean,
1327
1328
  /** Object with participants */
1328
1329
  participants: object
1330
+
1331
+ /** Reject the call */
1332
+ reject: () => Promise<void>
1329
1333
  }
1330
1334
 
1331
1335
  /** Message type List */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.18.3",
3
+ "version": "1.19.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
@@ -62,7 +62,15 @@ class Call extends Base {
62
62
 
63
63
  return super._patch(data);
64
64
  }
65
-
65
+
66
+ /**
67
+ * Reject the call
68
+ */
69
+ async reject() {
70
+ return this.client.pupPage.evaluate((peerJid, id) => {
71
+ return window.WWebJS.rejectCall(peerJid, id);
72
+ }, this.from, this.id);
73
+ }
66
74
  }
67
75
 
68
76
  module.exports = Call;
@@ -305,8 +305,9 @@ class Message extends Base {
305
305
  if (!this.hasQuotedMsg) return undefined;
306
306
 
307
307
  const quotedMsg = await this.client.pupPage.evaluate((msgId) => {
308
- let msg = window.Store.Msg.get(msgId);
309
- return msg.quotedMsgObj().serialize();
308
+ const msg = window.Store.Msg.get(msgId);
309
+ const quotedMsg = window.Store.QuotedMsg.getQuotedMsgObj(msg);
310
+ return window.WWebJS.getMessageModel(quotedMsg);
310
311
  }, this.id._serialized);
311
312
 
312
313
  return new Message(this.client, quotedMsg);
@@ -385,7 +386,9 @@ class Message extends Base {
385
386
 
386
387
  const result = await this.client.pupPage.evaluate(async (msgId) => {
387
388
  const msg = window.Store.Msg.get(msgId);
388
-
389
+ if (!msg) {
390
+ return undefined;
391
+ }
389
392
  if (msg.mediaData.mediaStage != 'RESOLVED') {
390
393
  // try to resolve media
391
394
  await msg.downloadMedia({
@@ -436,7 +439,8 @@ class Message extends Base {
436
439
  await this.client.pupPage.evaluate((msgId, everyone) => {
437
440
  let msg = window.Store.Msg.get(msgId);
438
441
 
439
- if (everyone && msg._canRevoke()) {
442
+ const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
443
+ if (everyone && canRevoke) {
440
444
  return window.Store.Cmd.sendRevokeMsgs(msg.chat, [msg], { type: msg.id.fromMe ? 'Sender' : 'Admin' });
441
445
  }
442
446
 
@@ -451,7 +455,7 @@ class Message extends Base {
451
455
  await this.client.pupPage.evaluate((msgId) => {
452
456
  let msg = window.Store.Msg.get(msgId);
453
457
 
454
- if (msg.canStar()) {
458
+ if (window.Store.MsgActionChecks.canStarMsg(msg)) {
455
459
  return window.Store.Cmd.sendStarMsgs(msg.chat, [msg], false);
456
460
  }
457
461
  }, this.id._serialized);
@@ -464,7 +468,7 @@ class Message extends Base {
464
468
  await this.client.pupPage.evaluate((msgId) => {
465
469
  let msg = window.Store.Msg.get(msgId);
466
470
 
467
- if (msg.canStar()) {
471
+ if (window.Store.MsgActionChecks.canStarMsg(msg)) {
468
472
  return window.Store.Cmd.sendUnstarMsgs(msg.chat, [msg], false);
469
473
  }
470
474
  }, this.id._serialized);
@@ -51,7 +51,7 @@ exports.Events = {
51
51
  DISCONNECTED: 'disconnected',
52
52
  STATE_CHANGED: 'change_state',
53
53
  BATTERY_CHANGED: 'change_battery',
54
- INCOMING_CALL: 'incoming_call',
54
+ INCOMING_CALL: 'call',
55
55
  REMOTE_SESSION_SAVED: 'remote_session_saved'
56
56
  };
57
57
 
@@ -13,7 +13,6 @@ exports.ExposeStore = (moduleRaidStr) => {
13
13
  window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
14
14
  window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
15
15
  window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
16
- window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].LegacyPhoneFeatures;
17
16
  window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
18
17
  window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
19
18
  window.Store.InviteInfo = window.mR.findModule('sendQueryGroupInvite')[0];
@@ -51,6 +50,10 @@ exports.ExposeStore = (moduleRaidStr) => {
51
50
  window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
52
51
  window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
53
52
  window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
53
+ window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
54
+ window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
55
+ window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
56
+ window.Store.SocketWap = window.mR.findModule('wap')[0];
54
57
  window.Store.StickerTools = {
55
58
  ...window.mR.findModule('toWebpSticker')[0],
56
59
  ...window.mR.findModule('addWebpMetadata')[0]
@@ -83,6 +86,11 @@ exports.ExposeStore = (moduleRaidStr) => {
83
86
  } else {
84
87
  window.Store.MDBackend = true;
85
88
  }
89
+
90
+ const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
91
+ if(_features) {
92
+ window.Store.Features = _features.LegacyPhoneFeatures;
93
+ }
86
94
  };
87
95
 
88
96
  exports.LoadUtils = () => {
@@ -263,6 +271,7 @@ exports.LoadUtils = () => {
263
271
  ...ephemeralFields,
264
272
  ...locationOptions,
265
273
  ...attOptions,
274
+ ...(Object.keys(attOptions).length > 0 ? attOptions.toJSON() : {}),
266
275
  ...quotedMsgOptions,
267
276
  ...vcardOptions,
268
277
  ...buttonOptions,
@@ -600,4 +609,21 @@ exports.LoadUtils = () => {
600
609
 
601
610
  return undefined;
602
611
  };
612
+
613
+ window.WWebJS.rejectCall = async (peerJid, id) => {
614
+ peerJid = peerJid.split('@')[0] + '@s.whatsapp.net';
615
+ let userId = window.Store.User.getMaybeMeUser().user + '@s.whatsapp.net';
616
+ const stanza = window.Store.SocketWap.wap('call', {
617
+ id: window.Store.SocketWap.generateId(),
618
+ from: window.Store.SocketWap.USER_JID(userId),
619
+ to: window.Store.SocketWap.USER_JID(peerJid),
620
+ }, [
621
+ window.Store.SocketWap.wap('reject', {
622
+ 'call-id': id,
623
+ 'call-creator': window.Store.SocketWap.USER_JID(peerJid),
624
+ count: '0',
625
+ })
626
+ ]);
627
+ await window.Store.Socket.deprecatedCastStanza(stanza);
628
+ };
603
629
  };
@@ -79,6 +79,7 @@ class InterfaceController {
79
79
  */
80
80
  async getFeatures() {
81
81
  return await this.pupPage.evaluate(() => {
82
+ if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
82
83
  return window.Store.Features.F;
83
84
  });
84
85
  }
@@ -89,6 +90,7 @@ class InterfaceController {
89
90
  */
90
91
  async checkFeatureStatus(feature) {
91
92
  return await this.pupPage.evaluate((feature) => {
93
+ if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
92
94
  return window.Store.Features.supportsFeature(feature);
93
95
  }, feature);
94
96
  }
@@ -99,6 +101,7 @@ class InterfaceController {
99
101
  */
100
102
  async enableFeatures(features) {
101
103
  await this.pupPage.evaluate((features) => {
104
+ if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
102
105
  for (const feature in features) {
103
106
  window.Store.Features.setFeature(features[feature], true);
104
107
  }
@@ -111,6 +114,7 @@ class InterfaceController {
111
114
  */
112
115
  async disableFeatures(features) {
113
116
  await this.pupPage.evaluate((features) => {
117
+ if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
114
118
  for (const feature in features) {
115
119
  window.Store.Features.setFeature(features[feature], false);
116
120
  }