whatsapp-web.js 1.24.0 → 1.25.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.
@@ -1,156 +1,19 @@
1
1
  'use strict';
2
2
 
3
- // Exposes the internal Store to the WhatsApp Web client
4
- exports.ExposeStore = (moduleRaidStr) => {
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
- * Target options object description
126
- * @typedef {Object} TargetOptions
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
+ let msg = window.Store.Msg.get(msgId);
8
+ let chat = window.Store.Chat.get(chatId);
131
9
 
132
- /**
133
- * Function to modify functions
134
- * @param {TargetOptions} target Options specifying the target function to search for modifying
135
- * @param {Function} callback Modified function
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) {
@@ -332,15 +195,23 @@ exports.LoadUtils = () => {
332
195
  delete listOptions.list.footer;
333
196
  }
334
197
 
198
+ const botOptions = {};
199
+ if (options.invokedBotWid) {
200
+ botOptions.messageSecret = window.crypto.getRandomValues(new Uint8Array(32));
201
+ botOptions.botMessageSecret = await window.Store.BotSecret.genBotMsgSecretFromMsgSecret(botOptions.messageSecret);
202
+ botOptions.invokedBotWid = window.Store.WidFactory.createWid(options.invokedBotWid);
203
+ botOptions.botPersonaId = window.Store.BotProfiles.BotProfileCollection.get(options.invokedBotWid).personaId;
204
+ delete options.invokedBotWid;
205
+ }
206
+
335
207
  const meUser = window.Store.User.getMaybeMeUser();
336
- const isMD = window.Store.MDBackend;
337
208
  const newId = await window.Store.MsgKey.newId();
338
209
 
339
210
  const newMsgId = new window.Store.MsgKey({
340
211
  from: meUser,
341
212
  to: chat.id,
342
213
  id: newId,
343
- participant: isMD && chat.id.isGroup() ? meUser : undefined,
214
+ participant: chat.id.isGroup() ? meUser : undefined,
344
215
  selfDir: 'out',
345
216
  });
346
217
 
@@ -370,8 +241,14 @@ exports.LoadUtils = () => {
370
241
  ...vcardOptions,
371
242
  ...buttonOptions,
372
243
  ...listOptions,
244
+ ...botOptions,
373
245
  ...extraOptions
374
246
  };
247
+
248
+ // Bot's won't reply if canonicalUrl is set (linking)
249
+ if (botOptions) {
250
+ delete message.canonicalUrl;
251
+ }
375
252
 
376
253
  await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
377
254
  return window.Store.Msg.get(newMsgId._serialized);
@@ -666,7 +543,7 @@ exports.LoadUtils = () => {
666
543
  window.WWebJS.getContact = async contactId => {
667
544
  const wid = window.Store.WidFactory.createWid(contactId);
668
545
  const contact = await window.Store.Contact.find(wid);
669
- const bizProfile = await window.Store.BusinessProfileCollection.fetchBizProfile(wid);
546
+ const bizProfile = await window.Store.BusinessProfile.fetchBizProfile(wid);
670
547
  bizProfile.profileOptions && (contact.businessProfile = bizProfile);
671
548
  return window.WWebJS.getContactModel(contact);
672
549
  };
@@ -787,9 +664,8 @@ exports.LoadUtils = () => {
787
664
  };
788
665
 
789
666
  window.WWebJS.sendChatstate = async (state, chatId) => {
790
- if (window.Store.MDBackend) {
791
- chatId = window.Store.WidFactory.createWid(chatId);
792
- }
667
+ chatId = window.Store.WidFactory.createWid(chatId);
668
+
793
669
  switch (state) {
794
670
  case 'typing':
795
671
  await window.Store.ChatState.sendChatStateComposing(chatId);
@@ -1037,7 +913,7 @@ exports.LoadUtils = () => {
1037
913
  let response;
1038
914
  let result = [];
1039
915
 
1040
- await window.Store.GroupMetadata.queryAndUpdate(groupWid);
916
+ await window.Store.GroupQueryAndUpdate(groupWid);
1041
917
 
1042
918
  if (!requesterIds?.length) {
1043
919
  membershipRequests = group.groupMetadata.membershipApprovalRequests._models.map(({ id }) => id);
@@ -1131,4 +1007,5 @@ exports.LoadUtils = () => {
1131
1007
  if (response.messageSendResult === 'OK') return true;
1132
1008
  return false;
1133
1009
  };
1010
+
1134
1011
  };
@@ -29,15 +29,12 @@ class LocalWebCache extends WebCache {
29
29
  }
30
30
  }
31
31
 
32
- async persist(indexHtml) {
33
- // extract version from index (e.g. manifest-2.2206.9.json -> 2.2206.9)
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;