whatsapp-web.js 1.25.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 +1 -1
- package/example.js +8 -0
- package/index.d.ts +9 -1
- package/package.json +1 -1
- package/src/Client.js +25 -7
- package/src/structures/Message.js +21 -22
- package/src/util/Constants.js +1 -1
- package/src/util/Injected/Store.js +1 -0
- package/src/util/Injected/Utils.js +19 -13
- package/src/util/InterfaceController.js +2 -2
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.
|
|
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
|
@@ -450,6 +450,14 @@ client.on('message', async msg => {
|
|
|
450
450
|
*/
|
|
451
451
|
const result = await msg.pin(60); // Will pin a message for 1 minute
|
|
452
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`);
|
|
453
461
|
}
|
|
454
462
|
});
|
|
455
463
|
|
package/index.d.ts
CHANGED
|
@@ -176,7 +176,15 @@ declare namespace WAWebJS {
|
|
|
176
176
|
* @param flag true/false on or off
|
|
177
177
|
*/
|
|
178
178
|
setAutoDownloadVideos(flag: boolean): Promise<void>
|
|
179
|
-
|
|
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
|
+
|
|
180
188
|
/** Changes and returns the archive state of the Chat */
|
|
181
189
|
unarchiveChat(chatId: string): Promise<boolean>
|
|
182
190
|
|
package/package.json
CHANGED
package/src/Client.js
CHANGED
|
@@ -323,6 +323,7 @@ class Client extends EventEmitter {
|
|
|
323
323
|
// remove after 2.3000.x hard release
|
|
324
324
|
await page.evaluateOnNewDocument(() => {
|
|
325
325
|
const originalError = Error;
|
|
326
|
+
window.originalError = originalError;
|
|
326
327
|
//eslint-disable-next-line no-global-assign
|
|
327
328
|
Error = function (message) {
|
|
328
329
|
const error = new originalError(message);
|
|
@@ -720,8 +721,8 @@ class Client extends EventEmitter {
|
|
|
720
721
|
}
|
|
721
722
|
});
|
|
722
723
|
window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);});
|
|
723
|
-
window.Store.PollVote.on('add', (vote) => {
|
|
724
|
-
const pollVoteModel = window.WWebJS.getPollVoteModel(vote);
|
|
724
|
+
window.Store.PollVote.on('add', async (vote) => {
|
|
725
|
+
const pollVoteModel = await window.WWebJS.getPollVoteModel(vote);
|
|
725
726
|
pollVoteModel && window.onPollVoteEvent(pollVoteModel);
|
|
726
727
|
});
|
|
727
728
|
|
|
@@ -802,7 +803,9 @@ class Client extends EventEmitter {
|
|
|
802
803
|
*/
|
|
803
804
|
async logout() {
|
|
804
805
|
await this.pupPage.evaluate(() => {
|
|
805
|
-
|
|
806
|
+
if (window.Store && window.Store.AppState && typeof window.Store.AppState.logout === 'function') {
|
|
807
|
+
return window.Store.AppState.logout();
|
|
808
|
+
}
|
|
806
809
|
});
|
|
807
810
|
await this.pupBrowser.close();
|
|
808
811
|
|
|
@@ -1034,7 +1037,7 @@ class Client extends EventEmitter {
|
|
|
1034
1037
|
if(msg) return window.WWebJS.getMessageModel(msg);
|
|
1035
1038
|
|
|
1036
1039
|
const params = messageId.split('_');
|
|
1037
|
-
if(params.length !== 3) throw new Error('Invalid serialized message id specified');
|
|
1040
|
+
if (params.length !== 3 && params.length !== 4) throw new Error('Invalid serialized message id specified');
|
|
1038
1041
|
|
|
1039
1042
|
let messagesObject = await window.Store.Msg.getMessagesById([messageId]);
|
|
1040
1043
|
if (messagesObject && messagesObject.messages.length) msg = messagesObject.messages[0];
|
|
@@ -1614,8 +1617,8 @@ class Client extends EventEmitter {
|
|
|
1614
1617
|
* @returns {Promise<Array<GroupMembershipRequest>>} An array of membership requests
|
|
1615
1618
|
*/
|
|
1616
1619
|
async getGroupMembershipRequests(groupId) {
|
|
1617
|
-
return await this.pupPage.evaluate(async (
|
|
1618
|
-
const groupWid = window.Store.WidFactory.createWid(
|
|
1620
|
+
return await this.pupPage.evaluate(async (groupId) => {
|
|
1621
|
+
const groupWid = window.Store.WidFactory.createWid(groupId);
|
|
1619
1622
|
return await window.Store.MembershipRequestUtils.getMembershipApprovalRequests(groupWid);
|
|
1620
1623
|
}, groupId);
|
|
1621
1624
|
}
|
|
@@ -1721,6 +1724,21 @@ class Client extends EventEmitter {
|
|
|
1721
1724
|
return flag;
|
|
1722
1725
|
}, flag);
|
|
1723
1726
|
}
|
|
1727
|
+
|
|
1728
|
+
/**
|
|
1729
|
+
* Get user device count by ID
|
|
1730
|
+
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
|
|
1731
|
+
* So for a non-enterprise user with one WaWeb connection it should return "2"
|
|
1732
|
+
* @param {string} contactId
|
|
1733
|
+
* @returns {number}
|
|
1734
|
+
*/
|
|
1735
|
+
async getContactDeviceCount(contactId) {
|
|
1736
|
+
let devices = await window.Store.DeviceList.getDeviceIds([window.Store.WidFactory.createWid(contactId)]);
|
|
1737
|
+
if(devices && devices.length && devices[0] != null && typeof devices[0].devices == 'object'){
|
|
1738
|
+
return devices[0].devices.length;
|
|
1739
|
+
}
|
|
1740
|
+
return 0;
|
|
1741
|
+
}
|
|
1724
1742
|
}
|
|
1725
1743
|
|
|
1726
|
-
module.exports = Client;
|
|
1744
|
+
module.exports = Client;
|
|
@@ -182,8 +182,8 @@ class Message extends Base {
|
|
|
182
182
|
inviteCodeExp: data.inviteCodeExp,
|
|
183
183
|
groupId: data.inviteGrp,
|
|
184
184
|
groupName: data.inviteGrpName,
|
|
185
|
-
fromId: '_serialized' in data.from ? data.from._serialized : data.from,
|
|
186
|
-
toId: '_serialized' in data.to ? data.to._serialized : data.to
|
|
185
|
+
fromId: typeof data.from === 'object' && '_serialized' in data.from ? data.from._serialized : data.from,
|
|
186
|
+
toId: typeof data.to === 'object' && '_serialized' in data.to ? data.to._serialized : data.to
|
|
187
187
|
} : undefined;
|
|
188
188
|
|
|
189
189
|
/**
|
|
@@ -311,9 +311,9 @@ class Message extends Base {
|
|
|
311
311
|
* @returns {Promise<Message>}
|
|
312
312
|
*/
|
|
313
313
|
async reload() {
|
|
314
|
-
const newData = await this.client.pupPage.evaluate((msgId) => {
|
|
315
|
-
const msg = window.Store.Msg.get(msgId);
|
|
316
|
-
if(!msg) return null;
|
|
314
|
+
const newData = await this.client.pupPage.evaluate(async (msgId) => {
|
|
315
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
316
|
+
if (!msg) return null;
|
|
317
317
|
return window.WWebJS.getMessageModel(msg);
|
|
318
318
|
}, this.id._serialized);
|
|
319
319
|
|
|
@@ -370,8 +370,8 @@ class Message extends Base {
|
|
|
370
370
|
async getQuotedMessage() {
|
|
371
371
|
if (!this.hasQuotedMsg) return undefined;
|
|
372
372
|
|
|
373
|
-
const quotedMsg = await this.client.pupPage.evaluate((msgId) => {
|
|
374
|
-
const msg = window.Store.Msg.get(msgId);
|
|
373
|
+
const quotedMsg = await this.client.pupPage.evaluate(async (msgId) => {
|
|
374
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
375
375
|
const quotedMsg = window.Store.QuotedMsg.getQuotedMsgObj(msg);
|
|
376
376
|
return window.WWebJS.getMessageModel(quotedMsg);
|
|
377
377
|
}, this.id._serialized);
|
|
@@ -409,9 +409,10 @@ class Message extends Base {
|
|
|
409
409
|
*/
|
|
410
410
|
async react(reaction){
|
|
411
411
|
await this.client.pupPage.evaluate(async (messageId, reaction) => {
|
|
412
|
-
if (!messageId)
|
|
413
|
-
|
|
414
|
-
|
|
412
|
+
if (!messageId) return null;
|
|
413
|
+
const msg =
|
|
414
|
+
window.Store.Msg.get(messageId) || (await window.Store.Msg.getMessagesById([messageId]))?.messages?.[0];
|
|
415
|
+
if(!msg) return null;
|
|
415
416
|
await window.Store.sendReactionToMsg(msg, reaction);
|
|
416
417
|
}, this.id._serialized, reaction);
|
|
417
418
|
}
|
|
@@ -448,9 +449,9 @@ class Message extends Base {
|
|
|
448
449
|
}
|
|
449
450
|
|
|
450
451
|
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
|
451
|
-
const msg = window.Store.Msg.get(msgId);
|
|
452
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
452
453
|
if (!msg || !msg.mediaData) {
|
|
453
|
-
return
|
|
454
|
+
return null;
|
|
454
455
|
}
|
|
455
456
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
|
456
457
|
// try to resolve media
|
|
@@ -500,7 +501,7 @@ class Message extends Base {
|
|
|
500
501
|
*/
|
|
501
502
|
async delete(everyone) {
|
|
502
503
|
await this.client.pupPage.evaluate(async (msgId, everyone) => {
|
|
503
|
-
|
|
504
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
504
505
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
|
505
506
|
|
|
506
507
|
const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
|
@@ -521,8 +522,7 @@ class Message extends Base {
|
|
|
521
522
|
*/
|
|
522
523
|
async star() {
|
|
523
524
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
526
526
|
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
|
527
527
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
|
528
528
|
return window.Store.Cmd.sendStarMsgs(chat, [msg], false);
|
|
@@ -535,8 +535,7 @@ class Message extends Base {
|
|
|
535
535
|
*/
|
|
536
536
|
async unstar() {
|
|
537
537
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
538
|
-
|
|
539
|
-
|
|
538
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
540
539
|
if (window.Store.MsgActionChecks.canStarMsg(msg)) {
|
|
541
540
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
|
542
541
|
return window.Store.Cmd.sendUnstarMsgs(chat, [msg], false);
|
|
@@ -583,7 +582,7 @@ class Message extends Base {
|
|
|
583
582
|
*/
|
|
584
583
|
async getInfo() {
|
|
585
584
|
const info = await this.client.pupPage.evaluate(async (msgId) => {
|
|
586
|
-
const msg = window.Store.Msg.get(msgId);
|
|
585
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
587
586
|
if (!msg || !msg.id.fromMe) return null;
|
|
588
587
|
|
|
589
588
|
return new Promise((resolve) => {
|
|
@@ -617,7 +616,7 @@ class Message extends Base {
|
|
|
617
616
|
async getPayment() {
|
|
618
617
|
if (this.type === MessageTypes.PAYMENT) {
|
|
619
618
|
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
|
620
|
-
const msg = window.Store.Msg.get(msgId);
|
|
619
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
621
620
|
if(!msg) return null;
|
|
622
621
|
return msg.serialize();
|
|
623
622
|
}, this.id._serialized);
|
|
@@ -692,11 +691,11 @@ class Message extends Base {
|
|
|
692
691
|
return null;
|
|
693
692
|
}
|
|
694
693
|
const messageEdit = await this.client.pupPage.evaluate(async (msgId, message, options) => {
|
|
695
|
-
|
|
694
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
696
695
|
if (!msg) return null;
|
|
697
696
|
|
|
698
|
-
let
|
|
699
|
-
if (
|
|
697
|
+
let canEdit = window.Store.MsgActionChecks.canEditText(msg) || window.Store.MsgActionChecks.canEditCaption(msg);
|
|
698
|
+
if (canEdit) {
|
|
700
699
|
const msgEdit = await window.WWebJS.editMessage(msg, message, options);
|
|
701
700
|
return msgEdit.serialize();
|
|
702
701
|
}
|
package/src/util/Constants.js
CHANGED
|
@@ -97,6 +97,7 @@ exports.ExposeStore = () => {
|
|
|
97
97
|
window.Store.Settings = window.require('WAWebUserPrefsGeneral');
|
|
98
98
|
window.Store.BotSecret = window.require('WAWebBotMessageSecret');
|
|
99
99
|
window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
|
|
100
|
+
window.Store.DeviceList = window.require('WAWebApiDeviceList');
|
|
100
101
|
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620'))
|
|
101
102
|
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
|
|
102
103
|
|
|
@@ -4,7 +4,7 @@ exports.LoadUtils = () => {
|
|
|
4
4
|
window.WWebJS = {};
|
|
5
5
|
|
|
6
6
|
window.WWebJS.forwardMessage = async (chatId, msgId) => {
|
|
7
|
-
|
|
7
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
8
8
|
let chat = window.Store.Chat.get(chatId);
|
|
9
9
|
|
|
10
10
|
if (window.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')) {
|
|
@@ -44,7 +44,13 @@ exports.LoadUtils = () => {
|
|
|
44
44
|
}
|
|
45
45
|
let quotedMsgOptions = {};
|
|
46
46
|
if (options.quotedMessageId) {
|
|
47
|
-
let quotedMessage = window.Store.Msg.
|
|
47
|
+
let quotedMessage = await window.Store.Msg.getMessagesById([options.quotedMessageId]);
|
|
48
|
+
|
|
49
|
+
if (quotedMessage['messages'].length != 1) {
|
|
50
|
+
throw new Error('Could not get the quoted message.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
quotedMessage = quotedMessage['messages'][0];
|
|
48
54
|
|
|
49
55
|
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
|
|
50
56
|
const canReply = window.Store.ReplyUtils ?
|
|
@@ -433,14 +439,13 @@ exports.LoadUtils = () => {
|
|
|
433
439
|
return msg;
|
|
434
440
|
};
|
|
435
441
|
|
|
436
|
-
window.WWebJS.getPollVoteModel = (vote) => {
|
|
442
|
+
window.WWebJS.getPollVoteModel = async (vote) => {
|
|
437
443
|
const _vote = vote.serialize();
|
|
438
|
-
if (vote.parentMsgKey)
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return null;
|
|
444
|
+
if (!vote.parentMsgKey) return null;
|
|
445
|
+
const msg =
|
|
446
|
+
window.Store.Msg.get(vote.parentMsgKey) || (await window.Store.Msg.getMessagesById([vote.parentMsgKey]))?.messages?.[0];
|
|
447
|
+
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
|
|
448
|
+
return _vote;
|
|
444
449
|
};
|
|
445
450
|
|
|
446
451
|
window.WWebJS.getChatModel = async chat => {
|
|
@@ -458,7 +463,9 @@ exports.LoadUtils = () => {
|
|
|
458
463
|
|
|
459
464
|
res.lastMessage = null;
|
|
460
465
|
if (res.msgs && res.msgs.length) {
|
|
461
|
-
const lastMessage = chat.lastReceivedKey
|
|
466
|
+
const lastMessage = chat.lastReceivedKey
|
|
467
|
+
? window.Store.Msg.get(chat.lastReceivedKey._serialized) || (await window.Store.Msg.getMessagesById([chat.lastReceivedKey._serialized]))?.messages?.[0]
|
|
468
|
+
: null;
|
|
462
469
|
if (lastMessage) {
|
|
463
470
|
res.lastMessage = window.WWebJS.getMessageModel(lastMessage);
|
|
464
471
|
}
|
|
@@ -1001,11 +1008,10 @@ exports.LoadUtils = () => {
|
|
|
1001
1008
|
};
|
|
1002
1009
|
|
|
1003
1010
|
window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
|
|
1004
|
-
const message = window.Store.Msg.get(msgId);
|
|
1011
|
+
const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
1005
1012
|
if (!message) return false;
|
|
1006
1013
|
const response = await window.Store.pinUnpinMsg(message, action, duration);
|
|
1007
|
-
|
|
1008
|
-
return false;
|
|
1014
|
+
return response.messageSendResult === 'OK';
|
|
1009
1015
|
};
|
|
1010
1016
|
|
|
1011
1017
|
};
|
|
@@ -49,7 +49,7 @@ class InterfaceController {
|
|
|
49
49
|
*/
|
|
50
50
|
async openChatWindowAt(msgId) {
|
|
51
51
|
await this.pupPage.evaluate(async msgId => {
|
|
52
|
-
|
|
52
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
53
53
|
let chat = await window.Store.Chat.find(msg.id.remote);
|
|
54
54
|
let searchContext = await window.Store.SearchContext(chat,msg);
|
|
55
55
|
await window.Store.Cmd.openChatAt(chat, searchContext);
|
|
@@ -62,7 +62,7 @@ class InterfaceController {
|
|
|
62
62
|
*/
|
|
63
63
|
async openMessageDrawer(msgId) {
|
|
64
64
|
await this.pupPage.evaluate(async msgId => {
|
|
65
|
-
|
|
65
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
66
66
|
await window.Store.Cmd.msgInfoDrawer(msg);
|
|
67
67
|
}, msgId);
|
|
68
68
|
}
|