whatsapp-web.js 1.18.4 → 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 +2 -2
- package/example.js +9 -0
- package/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/structures/Call.js +9 -1
- package/src/structures/Message.js +3 -1
- package/src/util/Constants.js +1 -1
- package/src/util/Injected.js +25 -1
- package/src/util/InterfaceController.js +4 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765) ](https://www.npmjs.com/package/whatsapp-web.js) [](https://depfu.com/github/pedroslopez/whatsapp-web.js?project_id=9765)  [](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 $
|
|
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
package/src/structures/Call.js
CHANGED
|
@@ -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;
|
|
@@ -386,7 +386,9 @@ class Message extends Base {
|
|
|
386
386
|
|
|
387
387
|
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
|
388
388
|
const msg = window.Store.Msg.get(msgId);
|
|
389
|
-
|
|
389
|
+
if (!msg) {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
390
392
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
|
391
393
|
// try to resolve media
|
|
392
394
|
await msg.downloadMedia({
|
package/src/util/Constants.js
CHANGED
package/src/util/Injected.js
CHANGED
|
@@ -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];
|
|
@@ -53,6 +52,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
53
52
|
window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
|
|
54
53
|
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
|
55
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];
|
|
56
57
|
window.Store.StickerTools = {
|
|
57
58
|
...window.mR.findModule('toWebpSticker')[0],
|
|
58
59
|
...window.mR.findModule('addWebpMetadata')[0]
|
|
@@ -85,6 +86,11 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|
|
85
86
|
} else {
|
|
86
87
|
window.Store.MDBackend = true;
|
|
87
88
|
}
|
|
89
|
+
|
|
90
|
+
const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
|
|
91
|
+
if(_features) {
|
|
92
|
+
window.Store.Features = _features.LegacyPhoneFeatures;
|
|
93
|
+
}
|
|
88
94
|
};
|
|
89
95
|
|
|
90
96
|
exports.LoadUtils = () => {
|
|
@@ -265,6 +271,7 @@ exports.LoadUtils = () => {
|
|
|
265
271
|
...ephemeralFields,
|
|
266
272
|
...locationOptions,
|
|
267
273
|
...attOptions,
|
|
274
|
+
...(Object.keys(attOptions).length > 0 ? attOptions.toJSON() : {}),
|
|
268
275
|
...quotedMsgOptions,
|
|
269
276
|
...vcardOptions,
|
|
270
277
|
...buttonOptions,
|
|
@@ -602,4 +609,21 @@ exports.LoadUtils = () => {
|
|
|
602
609
|
|
|
603
610
|
return undefined;
|
|
604
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
|
+
};
|
|
605
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
|
}
|