@pney/whatsapp-web 1.34.6 → 1.34.7-1
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/.env.example +0 -1
- package/.gitattributes +4 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.lintstagedrc.json +6 -0
- package/.prettierignore +8 -0
- package/.prettierrc.json +10 -0
- package/README.md +83 -80
- package/commitlint.config.js +29 -0
- package/eslint.config.mjs +67 -0
- package/example.js +151 -71
- package/index.d.ts +982 -734
- package/index.js +4 -4
- package/package.json +3 -3
- package/shell.js +4 -4
- package/src/Client.js +1860 -920
- package/src/authStrategies/BaseAuthStrategy.js +4 -2
- package/src/authStrategies/LocalAuth.js +25 -12
- package/src/authStrategies/NoAuth.js +3 -4
- package/src/authStrategies/RemoteAuth.js +92 -43
- package/src/factories/ChatFactory.js +1 -1
- package/src/factories/ContactFactory.js +2 -2
- package/src/structures/Base.js +5 -3
- package/src/structures/Broadcast.js +1 -2
- package/src/structures/BusinessContact.js +1 -2
- package/src/structures/Buttons.js +14 -10
- package/src/structures/Call.js +10 -6
- package/src/structures/Channel.js +171 -91
- package/src/structures/Chat.js +57 -41
- package/src/structures/ClientInfo.js +1 -1
- package/src/structures/Contact.js +37 -16
- package/src/structures/GroupChat.js +425 -228
- package/src/structures/GroupNotification.js +21 -12
- package/src/structures/Label.js +6 -6
- package/src/structures/List.js +22 -14
- package/src/structures/Location.js +5 -4
- package/src/structures/Message.js +412 -168
- package/src/structures/MessageMedia.js +31 -18
- package/src/structures/Order.js +4 -4
- package/src/structures/Payment.js +6 -3
- package/src/structures/Poll.js +2 -2
- package/src/structures/PollVote.js +9 -6
- package/src/structures/PrivateChat.js +2 -4
- package/src/structures/PrivateContact.js +2 -4
- package/src/structures/Product.js +1 -1
- package/src/structures/ProductMetadata.js +1 -2
- package/src/structures/Reaction.js +2 -4
- package/src/structures/ScheduledEvent.js +22 -10
- package/src/util/Constants.js +8 -6
- package/src/util/Injected/AuthStore/AuthStore.js +7 -3
- package/src/util/Injected/Utils.js +753 -345
- package/src/util/InterfaceController.js +72 -25
- package/src/util/Puppeteer.js +1 -1
- package/src/util/Util.js +28 -15
- package/src/webCache/LocalWebCache.js +7 -5
- package/src/webCache/RemoteWebCache.js +10 -4
- package/src/webCache/WebCache.js +8 -5
- package/src/webCache/WebCacheFactory.js +9 -9
- package/CODE_OF_CONDUCT.md +0 -133
|
@@ -23,13 +23,13 @@ class Message extends Base {
|
|
|
23
23
|
|
|
24
24
|
_patch(data) {
|
|
25
25
|
this._data = data;
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
/**
|
|
28
28
|
* MediaKey that represents the sticker 'ID'
|
|
29
29
|
* @type {string}
|
|
30
30
|
*/
|
|
31
31
|
this.mediaKey = data.mediaKey;
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
/**
|
|
34
34
|
* ID that represents the message
|
|
35
35
|
* @type {object}
|
|
@@ -52,7 +52,9 @@ class Message extends Base {
|
|
|
52
52
|
* Message content
|
|
53
53
|
* @type {string}
|
|
54
54
|
*/
|
|
55
|
-
this.body = this.hasMedia
|
|
55
|
+
this.body = this.hasMedia
|
|
56
|
+
? data.caption || ''
|
|
57
|
+
: data.body || data.pollName || data.eventName || '';
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* Message type
|
|
@@ -70,7 +72,10 @@ class Message extends Base {
|
|
|
70
72
|
* ID for the Chat that this message was sent to, except if the message was sent by the current user.
|
|
71
73
|
* @type {string}
|
|
72
74
|
*/
|
|
73
|
-
this.from =
|
|
75
|
+
this.from =
|
|
76
|
+
typeof data.from === 'object' && data.from !== null
|
|
77
|
+
? data.from._serialized
|
|
78
|
+
: data.from;
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* ID for who this message is for.
|
|
@@ -79,19 +84,31 @@ class Message extends Base {
|
|
|
79
84
|
* If the message is sent by another user, it will be the ID for the current user.
|
|
80
85
|
* @type {string}
|
|
81
86
|
*/
|
|
82
|
-
this.to =
|
|
87
|
+
this.to =
|
|
88
|
+
typeof data.to === 'object' && data.to !== null
|
|
89
|
+
? data.to._serialized
|
|
90
|
+
: data.to;
|
|
83
91
|
|
|
84
92
|
/**
|
|
85
93
|
* If the message was sent to a group, this field will contain the user that sent the message.
|
|
86
94
|
* @type {string}
|
|
87
95
|
*/
|
|
88
|
-
this.author =
|
|
96
|
+
this.author =
|
|
97
|
+
typeof data.author === 'object' && data.author !== null
|
|
98
|
+
? data.author._serialized
|
|
99
|
+
: data.author;
|
|
89
100
|
|
|
90
101
|
/**
|
|
91
102
|
* String that represents from which device type the message was sent
|
|
92
103
|
* @type {string}
|
|
93
104
|
*/
|
|
94
|
-
this.deviceType =
|
|
105
|
+
this.deviceType =
|
|
106
|
+
typeof data.id.id === 'string' && data.id.id.length > 25
|
|
107
|
+
? 'android'
|
|
108
|
+
: typeof data.id.id === 'string' &&
|
|
109
|
+
data.id.id.substring(0, 2) === '3A'
|
|
110
|
+
? 'ios'
|
|
111
|
+
: 'web';
|
|
95
112
|
/**
|
|
96
113
|
* Indicates if the message was forwarded
|
|
97
114
|
* @type {boolean}
|
|
@@ -110,7 +127,8 @@ class Message extends Base {
|
|
|
110
127
|
* Indicates if the message is a status update
|
|
111
128
|
* @type {boolean}
|
|
112
129
|
*/
|
|
113
|
-
this.isStatus =
|
|
130
|
+
this.isStatus =
|
|
131
|
+
data.isStatusV3 || data.id.remote === 'status@broadcast';
|
|
114
132
|
|
|
115
133
|
/**
|
|
116
134
|
* Indicates if the message was starred
|
|
@@ -162,7 +180,7 @@ class Message extends Base {
|
|
|
162
180
|
description = {
|
|
163
181
|
name: splitted[0],
|
|
164
182
|
address: splitted[1],
|
|
165
|
-
url: data.clientUrl
|
|
183
|
+
url: data.clientUrl,
|
|
166
184
|
};
|
|
167
185
|
}
|
|
168
186
|
return new Location(data.lat, data.lng, description);
|
|
@@ -172,20 +190,36 @@ class Message extends Base {
|
|
|
172
190
|
* List of vCards contained in the message.
|
|
173
191
|
* @type {Array<string>}
|
|
174
192
|
*/
|
|
175
|
-
this.vCards =
|
|
193
|
+
this.vCards =
|
|
194
|
+
data.type === MessageTypes.CONTACT_CARD_MULTI
|
|
195
|
+
? data.vcardList.map((c) => c.vcard)
|
|
196
|
+
: data.type === MessageTypes.CONTACT_CARD
|
|
197
|
+
? [data.body]
|
|
198
|
+
: [];
|
|
176
199
|
|
|
177
200
|
/**
|
|
178
201
|
* Group Invite Data
|
|
179
202
|
* @type {object}
|
|
180
203
|
*/
|
|
181
|
-
this.inviteV4 =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
204
|
+
this.inviteV4 =
|
|
205
|
+
data.type === MessageTypes.GROUP_INVITE
|
|
206
|
+
? {
|
|
207
|
+
inviteCode: data.inviteCode,
|
|
208
|
+
inviteCodeExp: data.inviteCodeExp,
|
|
209
|
+
groupId: data.inviteGrp,
|
|
210
|
+
groupName: data.inviteGrpName,
|
|
211
|
+
fromId:
|
|
212
|
+
typeof data.from === 'object' &&
|
|
213
|
+
'_serialized' in data.from
|
|
214
|
+
? data.from._serialized
|
|
215
|
+
: data.from,
|
|
216
|
+
toId:
|
|
217
|
+
typeof data.to === 'object' &&
|
|
218
|
+
'_serialized' in data.to
|
|
219
|
+
? data.to._serialized
|
|
220
|
+
: data.to,
|
|
221
|
+
}
|
|
222
|
+
: undefined;
|
|
189
223
|
|
|
190
224
|
/**
|
|
191
225
|
* Indicates the mentions in the message body.
|
|
@@ -216,7 +250,7 @@ class Message extends Base {
|
|
|
216
250
|
*/
|
|
217
251
|
this.token = data.token ? data.token : undefined;
|
|
218
252
|
|
|
219
|
-
/**
|
|
253
|
+
/**
|
|
220
254
|
* Indicates whether the message is a Gif
|
|
221
255
|
* @type {boolean}
|
|
222
256
|
*/
|
|
@@ -257,7 +291,7 @@ class Message extends Base {
|
|
|
257
291
|
if (data.latestEditMsgKey) {
|
|
258
292
|
this.latestEditMsgKey = data.latestEditMsgKey;
|
|
259
293
|
}
|
|
260
|
-
|
|
294
|
+
|
|
261
295
|
/**
|
|
262
296
|
* Protocol message key.
|
|
263
297
|
* Can be used to retrieve the ID of an original message that was revoked.
|
|
@@ -284,17 +318,27 @@ class Message extends Base {
|
|
|
284
318
|
}
|
|
285
319
|
|
|
286
320
|
/** Selected List row Id **/
|
|
287
|
-
if (
|
|
288
|
-
|
|
321
|
+
if (
|
|
322
|
+
data.listResponse &&
|
|
323
|
+
data.listResponse.singleSelectReply.selectedRowId
|
|
324
|
+
) {
|
|
325
|
+
this.selectedRowId =
|
|
326
|
+
data.listResponse.singleSelectReply.selectedRowId;
|
|
289
327
|
}
|
|
290
328
|
|
|
291
329
|
if (this.type === MessageTypes.POLL_CREATION) {
|
|
292
330
|
this.pollName = data.pollName;
|
|
293
331
|
this.pollOptions = data.pollOptions;
|
|
294
|
-
this.allowMultipleAnswers = Boolean(
|
|
332
|
+
this.allowMultipleAnswers = Boolean(
|
|
333
|
+
!data.pollSelectableOptionsCount,
|
|
334
|
+
);
|
|
295
335
|
this.pollInvalidated = data.pollInvalidated;
|
|
296
336
|
this.isSentCagPollCreation = data.isSentCagPollCreation;
|
|
297
|
-
this.messageSecret = data.messageSecret
|
|
337
|
+
this.messageSecret = data.messageSecret
|
|
338
|
+
? Object.keys(data.messageSecret).map(
|
|
339
|
+
(key) => data.messageSecret[key],
|
|
340
|
+
)
|
|
341
|
+
: [];
|
|
298
342
|
}
|
|
299
343
|
|
|
300
344
|
return super._patch(data);
|
|
@@ -305,19 +349,25 @@ class Message extends Base {
|
|
|
305
349
|
}
|
|
306
350
|
|
|
307
351
|
/**
|
|
308
|
-
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
|
|
352
|
+
* Reloads this Message object's data in-place with the latest values from WhatsApp Web.
|
|
309
353
|
* Note that the Message must still be in the web app cache for this to work, otherwise will return null.
|
|
310
354
|
* @returns {Promise<Message>}
|
|
311
355
|
*/
|
|
312
356
|
async reload() {
|
|
313
357
|
const newData = await this.client.pupPage.evaluate(async (msgId) => {
|
|
314
|
-
const msg =
|
|
358
|
+
const msg =
|
|
359
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
360
|
+
(
|
|
361
|
+
await window
|
|
362
|
+
.require('WAWebCollections')
|
|
363
|
+
.Msg.getMessagesById([msgId])
|
|
364
|
+
)?.messages?.[0];
|
|
315
365
|
if (!msg) return null;
|
|
316
366
|
return window.WWebJS.getMessageModel(msg);
|
|
317
367
|
}, this.id._serialized);
|
|
318
368
|
|
|
319
|
-
if(!newData) return null;
|
|
320
|
-
|
|
369
|
+
if (!newData) return null;
|
|
370
|
+
|
|
321
371
|
this._patch(newData);
|
|
322
372
|
return this;
|
|
323
373
|
}
|
|
@@ -329,7 +379,7 @@ class Message extends Base {
|
|
|
329
379
|
get rawData() {
|
|
330
380
|
return this._data;
|
|
331
381
|
}
|
|
332
|
-
|
|
382
|
+
|
|
333
383
|
/**
|
|
334
384
|
* Returns the Chat this message was sent in
|
|
335
385
|
* @returns {Promise<Chat>}
|
|
@@ -351,15 +401,27 @@ class Message extends Base {
|
|
|
351
401
|
* @returns {Promise<Array<Contact>>}
|
|
352
402
|
*/
|
|
353
403
|
async getMentions() {
|
|
354
|
-
return await Promise.all(
|
|
404
|
+
return await Promise.all(
|
|
405
|
+
this.mentionedIds.map(
|
|
406
|
+
async (m) =>
|
|
407
|
+
await this.client.getContactById(
|
|
408
|
+
typeof m === 'string' ? m : m._serialized,
|
|
409
|
+
),
|
|
410
|
+
),
|
|
411
|
+
);
|
|
355
412
|
}
|
|
356
|
-
|
|
413
|
+
|
|
357
414
|
/**
|
|
358
415
|
* Returns groups mentioned in this message
|
|
359
416
|
* @returns {Promise<Array<GroupChat>>}
|
|
360
417
|
*/
|
|
361
418
|
async getGroupMentions() {
|
|
362
|
-
return await Promise.all(
|
|
419
|
+
return await Promise.all(
|
|
420
|
+
this.groupMentions.map(
|
|
421
|
+
async (m) =>
|
|
422
|
+
await this.client.getChatById(m.groupJid._serialized),
|
|
423
|
+
),
|
|
424
|
+
);
|
|
363
425
|
}
|
|
364
426
|
|
|
365
427
|
/**
|
|
@@ -370,8 +432,16 @@ class Message extends Base {
|
|
|
370
432
|
if (!this.hasQuotedMsg) return undefined;
|
|
371
433
|
|
|
372
434
|
const quotedMsg = await this.client.pupPage.evaluate(async (msgId) => {
|
|
373
|
-
const msg =
|
|
374
|
-
|
|
435
|
+
const msg =
|
|
436
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
437
|
+
(
|
|
438
|
+
await window
|
|
439
|
+
.require('WAWebCollections')
|
|
440
|
+
.Msg.getMessagesById([msgId])
|
|
441
|
+
)?.messages?.[0];
|
|
442
|
+
const quotedMsg = window
|
|
443
|
+
.require('WAWebQuotedMsgModelUtils')
|
|
444
|
+
.getQuotedMsgObj(msg);
|
|
375
445
|
return window.WWebJS.getMessageModel(quotedMsg);
|
|
376
446
|
}, this.id._serialized);
|
|
377
447
|
|
|
@@ -395,7 +465,7 @@ class Message extends Base {
|
|
|
395
465
|
|
|
396
466
|
options = {
|
|
397
467
|
...options,
|
|
398
|
-
quotedMessageId: this.id._serialized
|
|
468
|
+
quotedMessageId: this.id._serialized,
|
|
399
469
|
};
|
|
400
470
|
|
|
401
471
|
return this.client.sendMessage(chatId, content, options);
|
|
@@ -406,14 +476,8 @@ class Message extends Base {
|
|
|
406
476
|
* @param {string} reaction - Emoji to react with. Send an empty string to remove the reaction.
|
|
407
477
|
* @return {Promise}
|
|
408
478
|
*/
|
|
409
|
-
async react(reaction){
|
|
410
|
-
|
|
411
|
-
if (!messageId) return null;
|
|
412
|
-
const msg =
|
|
413
|
-
(window.require('WAWebCollections')).Msg.get(messageId) || (await (window.require('WAWebCollections')).Msg.getMessagesById([messageId]))?.messages?.[0];
|
|
414
|
-
if(!msg) return null;
|
|
415
|
-
await (window.require('WAWebSendReactionMsgAction'))(msg, reaction);
|
|
416
|
-
}, this.id._serialized, reaction);
|
|
479
|
+
async react(reaction) {
|
|
480
|
+
return this.client.sendReaction(this.id._serialized, reaction);
|
|
417
481
|
}
|
|
418
482
|
|
|
419
483
|
/**
|
|
@@ -433,9 +497,13 @@ class Message extends Base {
|
|
|
433
497
|
async forward(chat) {
|
|
434
498
|
const chatId = typeof chat === 'string' ? chat : chat.id._serialized;
|
|
435
499
|
|
|
436
|
-
await this.client.pupPage.evaluate(
|
|
437
|
-
|
|
438
|
-
|
|
500
|
+
await this.client.pupPage.evaluate(
|
|
501
|
+
async (msgId, chatId) => {
|
|
502
|
+
return window.WWebJS.forwardMessage(chatId, msgId);
|
|
503
|
+
},
|
|
504
|
+
this.id._serialized,
|
|
505
|
+
chatId,
|
|
506
|
+
);
|
|
439
507
|
}
|
|
440
508
|
|
|
441
509
|
/**
|
|
@@ -448,65 +516,84 @@ class Message extends Base {
|
|
|
448
516
|
}
|
|
449
517
|
|
|
450
518
|
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
519
|
+
const msg =
|
|
520
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
521
|
+
(
|
|
522
|
+
await window
|
|
523
|
+
.require('WAWebCollections')
|
|
524
|
+
.Msg.getMessagesById([msgId])
|
|
525
|
+
)?.messages?.[0];
|
|
455
526
|
|
|
456
527
|
// REUPLOADING mediaStage means the media is expired and the download button is spinning, cannot be downloaded now
|
|
457
|
-
|
|
458
|
-
|
|
528
|
+
if (
|
|
529
|
+
!msg ||
|
|
530
|
+
!msg.mediaData ||
|
|
531
|
+
msg.mediaData.mediaStage === 'REUPLOADING'
|
|
532
|
+
) {
|
|
459
533
|
return null;
|
|
460
534
|
}
|
|
461
535
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
|
462
536
|
// try to resolve media
|
|
463
537
|
await msg.downloadMedia({
|
|
464
538
|
downloadEvenIfExpensive: true,
|
|
465
|
-
rmrReason: 1
|
|
539
|
+
rmrReason: 1,
|
|
466
540
|
});
|
|
467
541
|
}
|
|
468
542
|
|
|
469
|
-
if (
|
|
543
|
+
if (
|
|
544
|
+
msg.mediaData.mediaStage.includes('ERROR') ||
|
|
545
|
+
msg.mediaData.mediaStage === 'FETCHING'
|
|
546
|
+
) {
|
|
470
547
|
// media could not be downloaded
|
|
471
548
|
return undefined;
|
|
472
549
|
}
|
|
473
550
|
|
|
474
551
|
try {
|
|
475
552
|
const mockQpl = {
|
|
476
|
-
addAnnotations: function() {
|
|
477
|
-
|
|
553
|
+
addAnnotations: function () {
|
|
554
|
+
return this;
|
|
555
|
+
},
|
|
556
|
+
addPoint: function () {
|
|
557
|
+
return this;
|
|
558
|
+
},
|
|
478
559
|
};
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
560
|
+
const decryptedMedia = await window
|
|
561
|
+
.require('WAWebDownloadManager')
|
|
562
|
+
.downloadManager.downloadAndMaybeDecrypt({
|
|
563
|
+
directPath: msg.directPath,
|
|
564
|
+
encFilehash: msg.encFilehash,
|
|
565
|
+
filehash: msg.filehash,
|
|
566
|
+
mediaKey: msg.mediaKey,
|
|
567
|
+
mediaKeyTimestamp: msg.mediaKeyTimestamp,
|
|
568
|
+
type: msg.type,
|
|
569
|
+
signal: new AbortController().signal,
|
|
570
|
+
downloadQpl: mockQpl,
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
const data =
|
|
574
|
+
await window.WWebJS.arrayBufferToBase64Async(
|
|
575
|
+
decryptedMedia,
|
|
576
|
+
);
|
|
495
577
|
|
|
496
578
|
return {
|
|
497
579
|
data,
|
|
498
580
|
mimetype: msg.mimetype,
|
|
499
581
|
filename: msg.filename,
|
|
500
|
-
filesize: msg.size
|
|
582
|
+
filesize: msg.size,
|
|
501
583
|
};
|
|
502
584
|
} catch (e) {
|
|
503
|
-
if(e.status && e.status === 404) return undefined;
|
|
585
|
+
if (e.status && e.status === 404) return undefined;
|
|
504
586
|
throw e;
|
|
505
587
|
}
|
|
506
588
|
}, this.id._serialized);
|
|
507
589
|
|
|
508
590
|
if (!result) return undefined;
|
|
509
|
-
return new MessageMedia(
|
|
591
|
+
return new MessageMedia(
|
|
592
|
+
result.mimetype,
|
|
593
|
+
result.data,
|
|
594
|
+
result.filename,
|
|
595
|
+
result.filesize,
|
|
596
|
+
);
|
|
510
597
|
}
|
|
511
598
|
|
|
512
599
|
/**
|
|
@@ -515,25 +602,66 @@ class Message extends Base {
|
|
|
515
602
|
* @param {?boolean} [clearMedia = true] If true, any associated media will also be deleted from a device.
|
|
516
603
|
*/
|
|
517
604
|
async delete(everyone, clearMedia = true) {
|
|
518
|
-
await this.client.pupPage.evaluate(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
605
|
+
await this.client.pupPage.evaluate(
|
|
606
|
+
async (msgId, everyone, clearMedia) => {
|
|
607
|
+
const msg =
|
|
608
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
609
|
+
(
|
|
610
|
+
await window
|
|
611
|
+
.require('WAWebCollections')
|
|
612
|
+
.Msg.getMessagesById([msgId])
|
|
613
|
+
)?.messages?.[0];
|
|
614
|
+
const chat =
|
|
615
|
+
window
|
|
616
|
+
.require('WAWebCollections')
|
|
617
|
+
.Chat.get(msg.id.remote) ||
|
|
618
|
+
(await window
|
|
619
|
+
.require('WAWebCollections')
|
|
620
|
+
.Chat.find(msg.id.remote));
|
|
621
|
+
|
|
622
|
+
const canRevoke =
|
|
623
|
+
window
|
|
624
|
+
.require('WAWebMsgActionCapability')
|
|
625
|
+
.canSenderRevokeMsg(msg) ||
|
|
626
|
+
window
|
|
627
|
+
.require('WAWebMsgActionCapability')
|
|
628
|
+
.canAdminRevokeMsg(msg);
|
|
629
|
+
|
|
630
|
+
const { Cmd } = window.require('WAWebCmd');
|
|
631
|
+
|
|
632
|
+
if (everyone && canRevoke) {
|
|
633
|
+
return window.WWebJS.compareWwebVersions(
|
|
634
|
+
window.Debug.VERSION,
|
|
635
|
+
'>=',
|
|
636
|
+
'2.3000.0',
|
|
637
|
+
)
|
|
638
|
+
? Cmd.sendRevokeMsgs(
|
|
639
|
+
chat,
|
|
640
|
+
{ list: [msg], type: 'message' },
|
|
641
|
+
{ clearMedia: clearMedia },
|
|
642
|
+
)
|
|
643
|
+
: Cmd.sendRevokeMsgs(chat, [msg], {
|
|
644
|
+
clearMedia: true,
|
|
645
|
+
type: msg.id.fromMe ? 'Sender' : 'Admin',
|
|
646
|
+
});
|
|
647
|
+
}
|
|
532
648
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
649
|
+
return window.WWebJS.compareWwebVersions(
|
|
650
|
+
window.Debug.VERSION,
|
|
651
|
+
'>=',
|
|
652
|
+
'2.3000.0',
|
|
653
|
+
)
|
|
654
|
+
? Cmd.sendDeleteMsgs(
|
|
655
|
+
chat,
|
|
656
|
+
{ list: [msg], type: 'message' },
|
|
657
|
+
clearMedia,
|
|
658
|
+
)
|
|
659
|
+
: Cmd.sendDeleteMsgs(chat, [msg], clearMedia);
|
|
660
|
+
},
|
|
661
|
+
this.id._serialized,
|
|
662
|
+
everyone,
|
|
663
|
+
clearMedia,
|
|
664
|
+
);
|
|
537
665
|
}
|
|
538
666
|
|
|
539
667
|
/**
|
|
@@ -541,10 +669,20 @@ class Message extends Base {
|
|
|
541
669
|
*/
|
|
542
670
|
async star() {
|
|
543
671
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
544
|
-
const msg =
|
|
672
|
+
const msg =
|
|
673
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
674
|
+
(
|
|
675
|
+
await window
|
|
676
|
+
.require('WAWebCollections')
|
|
677
|
+
.Msg.getMessagesById([msgId])
|
|
678
|
+
)?.messages?.[0];
|
|
545
679
|
if (window.require('WAWebMsgActionCapability').canStarMsg(msg)) {
|
|
546
|
-
let chat = await
|
|
547
|
-
|
|
680
|
+
let chat = await window
|
|
681
|
+
.require('WAWebCollections')
|
|
682
|
+
.Chat.find(msg.id.remote);
|
|
683
|
+
return window
|
|
684
|
+
.require('WAWebCmd')
|
|
685
|
+
.Cmd.sendStarMsgs(chat, [msg], false);
|
|
548
686
|
}
|
|
549
687
|
}, this.id._serialized);
|
|
550
688
|
}
|
|
@@ -554,10 +692,20 @@ class Message extends Base {
|
|
|
554
692
|
*/
|
|
555
693
|
async unstar() {
|
|
556
694
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
557
|
-
const msg =
|
|
695
|
+
const msg =
|
|
696
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
697
|
+
(
|
|
698
|
+
await window
|
|
699
|
+
.require('WAWebCollections')
|
|
700
|
+
.Msg.getMessagesById([msgId])
|
|
701
|
+
)?.messages?.[0];
|
|
558
702
|
if (window.require('WAWebMsgActionCapability').canStarMsg(msg)) {
|
|
559
|
-
let chat = await
|
|
560
|
-
|
|
703
|
+
let chat = await window
|
|
704
|
+
.require('WAWebCollections')
|
|
705
|
+
.Chat.find(msg.id.remote);
|
|
706
|
+
return window
|
|
707
|
+
.require('WAWebCmd')
|
|
708
|
+
.Cmd.sendUnstarMsgs(chat, [msg], false);
|
|
561
709
|
}
|
|
562
710
|
}, this.id._serialized);
|
|
563
711
|
}
|
|
@@ -568,9 +716,17 @@ class Message extends Base {
|
|
|
568
716
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
569
717
|
*/
|
|
570
718
|
async pin(duration) {
|
|
571
|
-
return await this.client.pupPage.evaluate(
|
|
572
|
-
|
|
573
|
-
|
|
719
|
+
return await this.client.pupPage.evaluate(
|
|
720
|
+
async (msgId, duration) => {
|
|
721
|
+
return await window.WWebJS.pinUnpinMsgAction(
|
|
722
|
+
msgId,
|
|
723
|
+
1,
|
|
724
|
+
duration,
|
|
725
|
+
);
|
|
726
|
+
},
|
|
727
|
+
this.id._serialized,
|
|
728
|
+
duration,
|
|
729
|
+
);
|
|
574
730
|
}
|
|
575
731
|
|
|
576
732
|
/**
|
|
@@ -601,13 +757,28 @@ class Message extends Base {
|
|
|
601
757
|
*/
|
|
602
758
|
async getInfo() {
|
|
603
759
|
const info = await this.client.pupPage.evaluate(async (msgId) => {
|
|
604
|
-
const msg =
|
|
760
|
+
const msg =
|
|
761
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
762
|
+
(
|
|
763
|
+
await window
|
|
764
|
+
.require('WAWebCollections')
|
|
765
|
+
.Msg.getMessagesById([msgId])
|
|
766
|
+
)?.messages?.[0];
|
|
605
767
|
if (!msg || !msg.id.fromMe) return null;
|
|
606
768
|
|
|
607
769
|
return new Promise((resolve) => {
|
|
608
|
-
setTimeout(
|
|
609
|
-
|
|
610
|
-
|
|
770
|
+
setTimeout(
|
|
771
|
+
async () => {
|
|
772
|
+
resolve(
|
|
773
|
+
await window
|
|
774
|
+
.require('WAWebApiMessageInfoStore')
|
|
775
|
+
.queryMsgInfo(msg.id),
|
|
776
|
+
);
|
|
777
|
+
},
|
|
778
|
+
(Date.now() - msg.t * 1000 < 1250 &&
|
|
779
|
+
Math.floor(Math.random() * (1200 - 1100 + 1)) + 1100) ||
|
|
780
|
+
0,
|
|
781
|
+
);
|
|
611
782
|
});
|
|
612
783
|
}, this.id._serialized);
|
|
613
784
|
|
|
@@ -620,14 +791,20 @@ class Message extends Base {
|
|
|
620
791
|
*/
|
|
621
792
|
async getOrder() {
|
|
622
793
|
if (this.type === MessageTypes.ORDER) {
|
|
623
|
-
const result = await this.client.pupPage.evaluate(
|
|
624
|
-
|
|
625
|
-
|
|
794
|
+
const result = await this.client.pupPage.evaluate(
|
|
795
|
+
(orderId, token, chatId) => {
|
|
796
|
+
return window.WWebJS.getOrderDetail(orderId, token, chatId);
|
|
797
|
+
},
|
|
798
|
+
this.orderId,
|
|
799
|
+
this.token,
|
|
800
|
+
this._getChatId(),
|
|
801
|
+
);
|
|
626
802
|
if (!result) return undefined;
|
|
627
803
|
return new Order(this.client, result);
|
|
628
804
|
}
|
|
629
805
|
return undefined;
|
|
630
806
|
}
|
|
807
|
+
|
|
631
808
|
/**
|
|
632
809
|
* Gets the payment details associated with a given message
|
|
633
810
|
* @return {Promise<Payment>}
|
|
@@ -635,8 +812,14 @@ class Message extends Base {
|
|
|
635
812
|
async getPayment() {
|
|
636
813
|
if (this.type === MessageTypes.PAYMENT) {
|
|
637
814
|
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
|
638
|
-
const msg =
|
|
639
|
-
|
|
815
|
+
const msg =
|
|
816
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
817
|
+
(
|
|
818
|
+
await window
|
|
819
|
+
.require('WAWebCollections')
|
|
820
|
+
.Msg.getMessagesById([msgId])
|
|
821
|
+
)?.messages?.[0];
|
|
822
|
+
if (!msg) return null;
|
|
640
823
|
return msg.serialize();
|
|
641
824
|
}, this.id._serialized);
|
|
642
825
|
return new Payment(this.client, msg);
|
|
@@ -644,7 +827,6 @@ class Message extends Base {
|
|
|
644
827
|
return undefined;
|
|
645
828
|
}
|
|
646
829
|
|
|
647
|
-
|
|
648
830
|
/**
|
|
649
831
|
* Reaction List
|
|
650
832
|
* @typedef {Object} ReactionList
|
|
@@ -664,7 +846,9 @@ class Message extends Base {
|
|
|
664
846
|
}
|
|
665
847
|
|
|
666
848
|
const reactions = await this.client.pupPage.evaluate(async (msgId) => {
|
|
667
|
-
const msgReactions = await
|
|
849
|
+
const msgReactions = await window
|
|
850
|
+
.require('WAWebCollections')
|
|
851
|
+
.Reactions.find(msgId);
|
|
668
852
|
if (!msgReactions || !msgReactions.reactions.length) return null;
|
|
669
853
|
return msgReactions.reactions.serialize();
|
|
670
854
|
}, this.id._serialized);
|
|
@@ -673,8 +857,8 @@ class Message extends Base {
|
|
|
673
857
|
return undefined;
|
|
674
858
|
}
|
|
675
859
|
|
|
676
|
-
return reactions.map(reaction => {
|
|
677
|
-
reaction.senders = reaction.senders.map(sender => {
|
|
860
|
+
return reactions.map((reaction) => {
|
|
861
|
+
reaction.senders = reaction.senders.map((sender) => {
|
|
678
862
|
sender.timestamp = Math.round(sender.timestamp / 1000);
|
|
679
863
|
return new Reaction(this.client, sender);
|
|
680
864
|
});
|
|
@@ -690,36 +874,68 @@ class Message extends Base {
|
|
|
690
874
|
*/
|
|
691
875
|
async edit(content, options = {}) {
|
|
692
876
|
if (options.mentions) {
|
|
693
|
-
!Array.isArray(options.mentions) &&
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
options.mentions
|
|
877
|
+
!Array.isArray(options.mentions) &&
|
|
878
|
+
(options.mentions = [options.mentions]);
|
|
879
|
+
if (
|
|
880
|
+
options.mentions.some(
|
|
881
|
+
(possiblyContact) => possiblyContact instanceof Contact,
|
|
882
|
+
)
|
|
883
|
+
) {
|
|
884
|
+
console.warn(
|
|
885
|
+
'Mentions with an array of Contact are now deprecated. See more at https://github.com/wwebjs/whatsapp-web.js/pull/2166.',
|
|
886
|
+
);
|
|
887
|
+
options.mentions = options.mentions.map(
|
|
888
|
+
(a) => a.id._serialized,
|
|
889
|
+
);
|
|
697
890
|
}
|
|
698
891
|
}
|
|
699
892
|
|
|
700
|
-
options.groupMentions &&
|
|
893
|
+
options.groupMentions &&
|
|
894
|
+
!Array.isArray(options.groupMentions) &&
|
|
895
|
+
(options.groupMentions = [options.groupMentions]);
|
|
701
896
|
|
|
702
897
|
let internalOptions = {
|
|
703
898
|
linkPreview: options.linkPreview === false ? undefined : true,
|
|
704
899
|
mentionedJidList: options.mentions || [],
|
|
705
900
|
groupMentions: options.groupMentions,
|
|
706
|
-
extraOptions: options.extra
|
|
901
|
+
extraOptions: options.extra,
|
|
707
902
|
};
|
|
708
|
-
|
|
903
|
+
|
|
709
904
|
if (!this.fromMe) {
|
|
710
905
|
return null;
|
|
711
906
|
}
|
|
712
|
-
const messageEdit = await this.client.pupPage.evaluate(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
907
|
+
const messageEdit = await this.client.pupPage.evaluate(
|
|
908
|
+
async (msgId, message, options) => {
|
|
909
|
+
const msg =
|
|
910
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
911
|
+
(
|
|
912
|
+
await window
|
|
913
|
+
.require('WAWebCollections')
|
|
914
|
+
.Msg.getMessagesById([msgId])
|
|
915
|
+
)?.messages?.[0];
|
|
916
|
+
if (!msg) return null;
|
|
917
|
+
|
|
918
|
+
let canEdit =
|
|
919
|
+
window
|
|
920
|
+
.require('WAWebMsgActionCapability')
|
|
921
|
+
.canEditText(msg) ||
|
|
922
|
+
window
|
|
923
|
+
.require('WAWebMsgActionCapability')
|
|
924
|
+
.canEditCaption(msg);
|
|
925
|
+
if (canEdit) {
|
|
926
|
+
const msgEdit = await window.WWebJS.editMessage(
|
|
927
|
+
msg,
|
|
928
|
+
message,
|
|
929
|
+
options,
|
|
930
|
+
);
|
|
931
|
+
return msgEdit.serialize();
|
|
932
|
+
}
|
|
933
|
+
return null;
|
|
934
|
+
},
|
|
935
|
+
this.id._serialized,
|
|
936
|
+
content,
|
|
937
|
+
internalOptions,
|
|
938
|
+
);
|
|
723
939
|
if (messageEdit) {
|
|
724
940
|
return new Message(this.client, messageEdit);
|
|
725
941
|
}
|
|
@@ -737,28 +953,44 @@ class Message extends Base {
|
|
|
737
953
|
return null;
|
|
738
954
|
}
|
|
739
955
|
|
|
740
|
-
const edittedEventMsg = await this.client.pupPage.evaluate(
|
|
741
|
-
|
|
742
|
-
|
|
956
|
+
const edittedEventMsg = await this.client.pupPage.evaluate(
|
|
957
|
+
async (msgId, editedEventObject) => {
|
|
958
|
+
const msg =
|
|
959
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
960
|
+
(
|
|
961
|
+
await window
|
|
962
|
+
.require('WAWebCollections')
|
|
963
|
+
.Msg.getMessagesById([msgId])
|
|
964
|
+
)?.messages?.[0];
|
|
965
|
+
if (!msg) return null;
|
|
966
|
+
|
|
967
|
+
const { name, startTimeTs, eventSendOptions } =
|
|
968
|
+
editedEventObject;
|
|
969
|
+
const eventOptions = {
|
|
970
|
+
name: name,
|
|
971
|
+
description: eventSendOptions.description,
|
|
972
|
+
startTime: startTimeTs,
|
|
973
|
+
endTime: eventSendOptions.endTimeTs,
|
|
974
|
+
location: eventSendOptions.location,
|
|
975
|
+
callType: eventSendOptions.callType,
|
|
976
|
+
isEventCanceled: eventSendOptions.isEventCanceled,
|
|
977
|
+
};
|
|
743
978
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
await (window.require('WAWebSendEventEditMsgAction')).sendEventEditMessage(eventOptions, msg);
|
|
756
|
-
const editedMsg = (window.require('WAWebCollections')).Msg.get(msg.id._serialized);
|
|
757
|
-
return editedMsg?.serialize();
|
|
758
|
-
}, this.id._serialized, editedEventObject);
|
|
979
|
+
await window
|
|
980
|
+
.require('WAWebSendEventEditMsgAction')
|
|
981
|
+
.sendEventEditMessage(eventOptions, msg);
|
|
982
|
+
const editedMsg = window
|
|
983
|
+
.require('WAWebCollections')
|
|
984
|
+
.Msg.get(msg.id._serialized);
|
|
985
|
+
return editedMsg?.serialize();
|
|
986
|
+
},
|
|
987
|
+
this.id._serialized,
|
|
988
|
+
editedEventObject,
|
|
989
|
+
);
|
|
759
990
|
|
|
760
991
|
return edittedEventMsg && new Message(this.client, edittedEventMsg);
|
|
761
992
|
}
|
|
993
|
+
|
|
762
994
|
/**
|
|
763
995
|
* Returns the PollVote this poll message
|
|
764
996
|
* @returns {Promise<PollVote[]>}
|
|
@@ -773,24 +1005,36 @@ class Message extends Base {
|
|
|
773
1005
|
* @returns {Promise}
|
|
774
1006
|
*/
|
|
775
1007
|
async vote(selectedOptions) {
|
|
776
|
-
if (this.type != MessageTypes.POLL_CREATION)
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
1008
|
+
if (this.type != MessageTypes.POLL_CREATION)
|
|
1009
|
+
throw 'Invalid usage! Can only be used with a pollCreation message';
|
|
1010
|
+
|
|
1011
|
+
await this.client.pupPage.evaluate(
|
|
1012
|
+
async (messageId, votes) => {
|
|
1013
|
+
if (!messageId) return null;
|
|
1014
|
+
if (!Array.isArray(votes)) votes = [votes];
|
|
1015
|
+
let localIdSet = new Set();
|
|
1016
|
+
const msg =
|
|
1017
|
+
window.require('WAWebCollections').Msg.get(messageId) ||
|
|
1018
|
+
(
|
|
1019
|
+
await window
|
|
1020
|
+
.require('WAWebCollections')
|
|
1021
|
+
.Msg.getMessagesById([messageId])
|
|
1022
|
+
)?.messages?.[0];
|
|
1023
|
+
if (!msg) return null;
|
|
1024
|
+
|
|
1025
|
+
msg.pollOptions.forEach((a) => {
|
|
1026
|
+
for (const option of votes) {
|
|
1027
|
+
if (a.name === option) localIdSet.add(a.localId);
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
791
1030
|
|
|
792
|
-
|
|
793
|
-
|
|
1031
|
+
await window
|
|
1032
|
+
.require('WAWebPollsSendVoteMsgAction')
|
|
1033
|
+
.sendVote(msg, localIdSet);
|
|
1034
|
+
},
|
|
1035
|
+
this.id._serialized,
|
|
1036
|
+
selectedOptions,
|
|
1037
|
+
);
|
|
794
1038
|
}
|
|
795
1039
|
}
|
|
796
1040
|
|