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 +1 -1
- package/example.js +37 -4
- package/index.d.ts +24 -2
- package/index.js +0 -1
- package/package.json +1 -1
- package/src/Client.js +560 -536
- package/src/authStrategies/LocalAuth.js +4 -1
- package/src/structures/GroupChat.js +12 -4
- package/src/structures/Message.js +27 -27
- package/src/util/Constants.js +1 -1
- package/src/util/Injected/AuthStore/AuthStore.js +17 -0
- package/src/util/Injected/AuthStore/LegacyAuthStore.js +22 -0
- package/src/util/Injected/LegacyStore.js +146 -0
- package/src/util/Injected/Store.js +167 -0
- package/src/util/{Injected.js → Injected/Utils.js} +49 -166
- package/src/util/InterfaceController.js +2 -2
- package/src/webCache/LocalWebCache.js +3 -6
- package/src/authStrategies/LegacySessionAuth.js +0 -72
|
@@ -1,156 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
eval('var moduleRaid = ' + moduleRaidStr);
|
|
6
|
-
// eslint-disable-next-line no-undef
|
|
7
|
-
window.mR = moduleRaid();
|
|
8
|
-
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
|
|
9
|
-
window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
|
|
10
|
-
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
|
|
11
|
-
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
|
|
12
|
-
window.Store.Call = window.mR.findModule((module) => module.default && module.default.Call)[0].default.Call;
|
|
13
|
-
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
|
|
14
|
-
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
|
|
15
|
-
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
|
|
16
|
-
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
|
|
17
|
-
window.Store.GroupMetadata.queryAndUpdate = window.mR.findModule('queryAndUpdateGroupMetadataById')[0].queryAndUpdateGroupMetadataById;
|
|
18
|
-
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
|
|
19
|
-
window.Store.ContactCollection = window.mR.findModule('ContactCollection')[0].ContactCollection;
|
|
20
|
-
window.Store.MediaPrep = window.mR.findModule('prepRawMedia')[0];
|
|
21
|
-
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
|
22
|
-
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
|
|
23
|
-
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
|
24
|
-
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
|
|
25
|
-
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
|
|
26
|
-
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
|
|
27
|
-
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
|
|
28
|
-
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
|
|
29
|
-
window.Store.SendClear = window.mR.findModule('sendClear')[0];
|
|
30
|
-
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
|
|
31
|
-
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
|
|
32
|
-
window.Store.EditMessage = window.mR.findModule('addAndSendMessageEdit')[0];
|
|
33
|
-
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
|
|
34
|
-
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
|
|
35
|
-
window.Store.ContactMethods = window.mR.findModule('getUserid')[0];
|
|
36
|
-
window.Store.BusinessProfileCollection = window.mR.findModule('BusinessProfileCollection')[0].BusinessProfileCollection;
|
|
37
|
-
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
|
|
38
|
-
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
|
39
|
-
window.Store.Validators = window.mR.findModule('findLinks')[0];
|
|
40
|
-
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
|
|
41
|
-
window.Store.WidFactory = window.mR.findModule('createWid')[0];
|
|
42
|
-
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
|
|
43
|
-
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
|
|
44
|
-
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
|
|
45
|
-
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
|
46
|
-
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
|
47
|
-
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
|
|
48
|
-
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
|
|
49
|
-
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
|
|
50
|
-
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
|
|
51
|
-
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
|
52
|
-
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
|
53
|
-
window.Store.LinkPreview = window.mR.findModule('getLinkPreview')[0];
|
|
54
|
-
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
|
|
55
|
-
window.Store.SocketWap = window.mR.findModule('wap')[0];
|
|
56
|
-
window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
|
|
57
|
-
window.Store.DrawerManager = window.mR.findModule('DrawerManager')[0].DrawerManager;
|
|
58
|
-
window.Store.LidUtils = window.mR.findModule('getCurrentLid')[0];
|
|
59
|
-
window.Store.WidToJid = window.mR.findModule('widToUserJid')[0];
|
|
60
|
-
window.Store.JidToWid = window.mR.findModule('userJidToUserWid')[0];
|
|
61
|
-
window.Store.getMsgInfo = (window.mR.findModule('sendQueryMsgInfo')[0] || {}).sendQueryMsgInfo || window.mR.findModule('queryMsgInfo')[0].queryMsgInfo;
|
|
62
|
-
window.Store.pinUnpinMsg = window.mR.findModule('sendPinInChatMsg')[0].sendPinInChatMsg;
|
|
63
|
-
|
|
64
|
-
/* eslint-disable no-undef, no-cond-assign */
|
|
65
|
-
window.Store.QueryExist = ((m = window.mR.findModule('queryExists')[0]) ? m.queryExists : window.mR.findModule('queryExist')[0].queryWidExists);
|
|
66
|
-
window.Store.ReplyUtils = (m = window.mR.findModule('canReplyMsg')).length > 0 && m[0];
|
|
67
|
-
/* eslint-enable no-undef, no-cond-assign */
|
|
68
|
-
|
|
69
|
-
window.Store.Settings = {
|
|
70
|
-
...window.mR.findModule('ChatlistPanelState')[0],
|
|
71
|
-
setPushname: window.mR.findModule((m) => m.setPushname && !m.ChatlistPanelState)[0].setPushname
|
|
72
|
-
};
|
|
73
|
-
window.Store.StickerTools = {
|
|
74
|
-
...window.mR.findModule('toWebpSticker')[0],
|
|
75
|
-
...window.mR.findModule('addWebpMetadata')[0]
|
|
76
|
-
};
|
|
77
|
-
window.Store.GroupUtils = {
|
|
78
|
-
...window.mR.findModule('createGroup')[0],
|
|
79
|
-
...window.mR.findModule('setGroupDescription')[0],
|
|
80
|
-
...window.mR.findModule('sendExitGroup')[0],
|
|
81
|
-
...window.mR.findModule('sendSetPicture')[0]
|
|
82
|
-
};
|
|
83
|
-
window.Store.GroupParticipants = {
|
|
84
|
-
...window.mR.findModule('promoteParticipants')[0],
|
|
85
|
-
...window.mR.findModule('sendAddParticipantsRPC')[0]
|
|
86
|
-
};
|
|
87
|
-
window.Store.GroupInvite = {
|
|
88
|
-
...window.mR.findModule('resetGroupInviteCode')[0],
|
|
89
|
-
...window.mR.findModule('queryGroupInvite')[0]
|
|
90
|
-
};
|
|
91
|
-
window.Store.GroupInviteV4 = {
|
|
92
|
-
...window.mR.findModule('queryGroupInviteV4')[0],
|
|
93
|
-
...window.mR.findModule('sendGroupInviteMessage')[0]
|
|
94
|
-
};
|
|
95
|
-
window.Store.MembershipRequestUtils = {
|
|
96
|
-
...window.mR.findModule('getMembershipApprovalRequests')[0],
|
|
97
|
-
...window.mR.findModule('sendMembershipRequestsActionRPC')[0]
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
if (!window.Store.Chat._find) {
|
|
101
|
-
window.Store.Chat._find = e => {
|
|
102
|
-
const target = window.Store.Chat.get(e);
|
|
103
|
-
return target ? Promise.resolve(target) : Promise.resolve({
|
|
104
|
-
id: e
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// eslint-disable-next-line no-undef
|
|
110
|
-
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
|
|
111
|
-
|
|
112
|
-
const _isMDBackend = window.mR.findModule('isMDBackend');
|
|
113
|
-
if(_isMDBackend && _isMDBackend[0] && _isMDBackend[0].isMDBackend) {
|
|
114
|
-
window.Store.MDBackend = _isMDBackend[0].isMDBackend();
|
|
115
|
-
} else {
|
|
116
|
-
window.Store.MDBackend = true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
|
|
120
|
-
if(_features) {
|
|
121
|
-
window.Store.Features = _features.LegacyPhoneFeatures;
|
|
122
|
-
}
|
|
3
|
+
exports.LoadUtils = () => {
|
|
4
|
+
window.WWebJS = {};
|
|
123
5
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* @property {string|number} module The name or a key of the target module to search
|
|
128
|
-
* @property {number} index The index value of the target module
|
|
129
|
-
* @property {string} function The function name to get from a module
|
|
130
|
-
*/
|
|
6
|
+
window.WWebJS.forwardMessage = async (chatId, msgId) => {
|
|
7
|
+
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
8
|
+
let chat = window.Store.Chat.get(chatId);
|
|
131
9
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
window.injectToFunction = (target, callback) => {
|
|
138
|
-
const module = typeof target.module === 'string'
|
|
139
|
-
? window.mR.findModule(target.module)
|
|
140
|
-
: window.mR.modules[target.module];
|
|
141
|
-
const originalFunction = module[target.index][target.function];
|
|
142
|
-
const modifiedFunction = (...args) => callback(originalFunction, ...args);
|
|
143
|
-
module[target.index][target.function] = modifiedFunction;
|
|
10
|
+
if (window.compareWwebVersions(window.Debug.VERSION, '>', '2.3000.0')) {
|
|
11
|
+
return window.Store.ForwardUtils.forwardMessagesToChats([msg], [chat], false);
|
|
12
|
+
} else {
|
|
13
|
+
return chat.forwardMessages([msg]);
|
|
14
|
+
}
|
|
144
15
|
};
|
|
145
16
|
|
|
146
|
-
window.injectToFunction({ module: 'mediaTypeFromProtobuf', index: 0, function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
|
|
147
|
-
|
|
148
|
-
window.injectToFunction({ module: 'typeAttributeFromProtobuf', index: 0, function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
exports.LoadUtils = () => {
|
|
152
|
-
window.WWebJS = {};
|
|
153
|
-
|
|
154
17
|
window.WWebJS.sendSeen = async (chatId) => {
|
|
155
18
|
let chat = window.Store.Chat.get(chatId);
|
|
156
19
|
if (chat !== undefined) {
|
|
@@ -181,7 +44,13 @@ exports.LoadUtils = () => {
|
|
|
181
44
|
}
|
|
182
45
|
let quotedMsgOptions = {};
|
|
183
46
|
if (options.quotedMessageId) {
|
|
184
|
-
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];
|
|
185
54
|
|
|
186
55
|
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
|
|
187
56
|
const canReply = window.Store.ReplyUtils ?
|
|
@@ -332,15 +201,23 @@ exports.LoadUtils = () => {
|
|
|
332
201
|
delete listOptions.list.footer;
|
|
333
202
|
}
|
|
334
203
|
|
|
204
|
+
const botOptions = {};
|
|
205
|
+
if (options.invokedBotWid) {
|
|
206
|
+
botOptions.messageSecret = window.crypto.getRandomValues(new Uint8Array(32));
|
|
207
|
+
botOptions.botMessageSecret = await window.Store.BotSecret.genBotMsgSecretFromMsgSecret(botOptions.messageSecret);
|
|
208
|
+
botOptions.invokedBotWid = window.Store.WidFactory.createWid(options.invokedBotWid);
|
|
209
|
+
botOptions.botPersonaId = window.Store.BotProfiles.BotProfileCollection.get(options.invokedBotWid).personaId;
|
|
210
|
+
delete options.invokedBotWid;
|
|
211
|
+
}
|
|
212
|
+
|
|
335
213
|
const meUser = window.Store.User.getMaybeMeUser();
|
|
336
|
-
const isMD = window.Store.MDBackend;
|
|
337
214
|
const newId = await window.Store.MsgKey.newId();
|
|
338
215
|
|
|
339
216
|
const newMsgId = new window.Store.MsgKey({
|
|
340
217
|
from: meUser,
|
|
341
218
|
to: chat.id,
|
|
342
219
|
id: newId,
|
|
343
|
-
participant:
|
|
220
|
+
participant: chat.id.isGroup() ? meUser : undefined,
|
|
344
221
|
selfDir: 'out',
|
|
345
222
|
});
|
|
346
223
|
|
|
@@ -370,8 +247,14 @@ exports.LoadUtils = () => {
|
|
|
370
247
|
...vcardOptions,
|
|
371
248
|
...buttonOptions,
|
|
372
249
|
...listOptions,
|
|
250
|
+
...botOptions,
|
|
373
251
|
...extraOptions
|
|
374
252
|
};
|
|
253
|
+
|
|
254
|
+
// Bot's won't reply if canonicalUrl is set (linking)
|
|
255
|
+
if (botOptions) {
|
|
256
|
+
delete message.canonicalUrl;
|
|
257
|
+
}
|
|
375
258
|
|
|
376
259
|
await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
|
|
377
260
|
return window.Store.Msg.get(newMsgId._serialized);
|
|
@@ -556,14 +439,13 @@ exports.LoadUtils = () => {
|
|
|
556
439
|
return msg;
|
|
557
440
|
};
|
|
558
441
|
|
|
559
|
-
window.WWebJS.getPollVoteModel = (vote) => {
|
|
442
|
+
window.WWebJS.getPollVoteModel = async (vote) => {
|
|
560
443
|
const _vote = vote.serialize();
|
|
561
|
-
if (vote.parentMsgKey)
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
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;
|
|
567
449
|
};
|
|
568
450
|
|
|
569
451
|
window.WWebJS.getChatModel = async chat => {
|
|
@@ -581,7 +463,9 @@ exports.LoadUtils = () => {
|
|
|
581
463
|
|
|
582
464
|
res.lastMessage = null;
|
|
583
465
|
if (res.msgs && res.msgs.length) {
|
|
584
|
-
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;
|
|
585
469
|
if (lastMessage) {
|
|
586
470
|
res.lastMessage = window.WWebJS.getMessageModel(lastMessage);
|
|
587
471
|
}
|
|
@@ -666,7 +550,7 @@ exports.LoadUtils = () => {
|
|
|
666
550
|
window.WWebJS.getContact = async contactId => {
|
|
667
551
|
const wid = window.Store.WidFactory.createWid(contactId);
|
|
668
552
|
const contact = await window.Store.Contact.find(wid);
|
|
669
|
-
const bizProfile = await window.Store.
|
|
553
|
+
const bizProfile = await window.Store.BusinessProfile.fetchBizProfile(wid);
|
|
670
554
|
bizProfile.profileOptions && (contact.businessProfile = bizProfile);
|
|
671
555
|
return window.WWebJS.getContactModel(contact);
|
|
672
556
|
};
|
|
@@ -787,9 +671,8 @@ exports.LoadUtils = () => {
|
|
|
787
671
|
};
|
|
788
672
|
|
|
789
673
|
window.WWebJS.sendChatstate = async (state, chatId) => {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
674
|
+
chatId = window.Store.WidFactory.createWid(chatId);
|
|
675
|
+
|
|
793
676
|
switch (state) {
|
|
794
677
|
case 'typing':
|
|
795
678
|
await window.Store.ChatState.sendChatStateComposing(chatId);
|
|
@@ -1037,7 +920,7 @@ exports.LoadUtils = () => {
|
|
|
1037
920
|
let response;
|
|
1038
921
|
let result = [];
|
|
1039
922
|
|
|
1040
|
-
await window.Store.
|
|
923
|
+
await window.Store.GroupQueryAndUpdate(groupWid);
|
|
1041
924
|
|
|
1042
925
|
if (!requesterIds?.length) {
|
|
1043
926
|
membershipRequests = group.groupMetadata.membershipApprovalRequests._models.map(({ id }) => id);
|
|
@@ -1125,10 +1008,10 @@ exports.LoadUtils = () => {
|
|
|
1125
1008
|
};
|
|
1126
1009
|
|
|
1127
1010
|
window.WWebJS.pinUnpinMsgAction = async (msgId, action, duration) => {
|
|
1128
|
-
const message = window.Store.Msg.get(msgId);
|
|
1011
|
+
const message = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
|
1129
1012
|
if (!message) return false;
|
|
1130
1013
|
const response = await window.Store.pinUnpinMsg(message, action, duration);
|
|
1131
|
-
|
|
1132
|
-
return false;
|
|
1014
|
+
return response.messageSendResult === 'OK';
|
|
1133
1015
|
};
|
|
1016
|
+
|
|
1134
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
|
}
|
|
@@ -29,15 +29,12 @@ class LocalWebCache extends WebCache {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async persist(indexHtml) {
|
|
33
|
-
//
|
|
34
|
-
const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
|
|
35
|
-
if(!version) return;
|
|
36
|
-
|
|
32
|
+
async persist(indexHtml, version) {
|
|
33
|
+
// version = (version+'').replace(/[^0-9.]/g,'');
|
|
37
34
|
const filePath = path.join(this.path, `${version}.html`);
|
|
38
35
|
fs.mkdirSync(this.path, { recursive: true });
|
|
39
36
|
fs.writeFileSync(filePath, indexHtml);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
module.exports = LocalWebCache;
|
|
40
|
+
module.exports = LocalWebCache;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const BaseAuthStrategy = require('./BaseAuthStrategy');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Legacy session auth strategy
|
|
7
|
-
* Not compatible with multi-device accounts.
|
|
8
|
-
* @param {object} options - options
|
|
9
|
-
* @param {string} options.restartOnAuthFail - Restart client with a new session (i.e. use null 'session' var) if authentication fails
|
|
10
|
-
* @param {object} options.session - Whatsapp session to restore. If not set, will start a new session
|
|
11
|
-
* @param {string} options.session.WABrowserId
|
|
12
|
-
* @param {string} options.session.WASecretBundle
|
|
13
|
-
* @param {string} options.session.WAToken1
|
|
14
|
-
* @param {string} options.session.WAToken2
|
|
15
|
-
*/
|
|
16
|
-
class LegacySessionAuth extends BaseAuthStrategy {
|
|
17
|
-
constructor({ session, restartOnAuthFail }={}) {
|
|
18
|
-
super();
|
|
19
|
-
this.session = session;
|
|
20
|
-
this.restartOnAuthFail = restartOnAuthFail;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async afterBrowserInitialized() {
|
|
24
|
-
if(this.session) {
|
|
25
|
-
await this.client.pupPage.evaluateOnNewDocument(session => {
|
|
26
|
-
if (document.referrer === 'https://whatsapp.com/') {
|
|
27
|
-
localStorage.clear();
|
|
28
|
-
localStorage.setItem('WABrowserId', session.WABrowserId);
|
|
29
|
-
localStorage.setItem('WASecretBundle', session.WASecretBundle);
|
|
30
|
-
localStorage.setItem('WAToken1', session.WAToken1);
|
|
31
|
-
localStorage.setItem('WAToken2', session.WAToken2);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
localStorage.setItem('remember-me', 'true');
|
|
35
|
-
}, this.session);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async onAuthenticationNeeded() {
|
|
40
|
-
if(this.session) {
|
|
41
|
-
this.session = null;
|
|
42
|
-
return {
|
|
43
|
-
failed: true,
|
|
44
|
-
restart: this.restartOnAuthFail,
|
|
45
|
-
failureEventPayload: 'Unable to log in. Are the session details valid?'
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return { failed: false };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async getAuthEventPayload() {
|
|
53
|
-
const isMD = await this.client.pupPage.evaluate(() => {
|
|
54
|
-
return window.Store.MDBackend;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if(isMD) throw new Error('Authenticating via JSON session is not supported for MultiDevice-enabled WhatsApp accounts.');
|
|
58
|
-
|
|
59
|
-
const localStorage = JSON.parse(await this.client.pupPage.evaluate(() => {
|
|
60
|
-
return JSON.stringify(window.localStorage);
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
WABrowserId: localStorage.WABrowserId,
|
|
65
|
-
WASecretBundle: localStorage.WASecretBundle,
|
|
66
|
-
WAToken1: localStorage.WAToken1,
|
|
67
|
-
WAToken2: localStorage.WAToken2
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = LegacySessionAuth;
|