@pney/whatsapp-web 1.34.6-3 → 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 +1 -1
- package/shell.js +4 -4
- package/src/Client.js +1860 -921
- 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 -160
- 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,57 +516,84 @@ class Message extends Base {
|
|
|
448
516
|
}
|
|
449
517
|
|
|
450
518
|
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
|
451
|
-
const msg =
|
|
519
|
+
const msg =
|
|
520
|
+
window.require('WAWebCollections').Msg.get(msgId) ||
|
|
521
|
+
(
|
|
522
|
+
await window
|
|
523
|
+
.require('WAWebCollections')
|
|
524
|
+
.Msg.getMessagesById([msgId])
|
|
525
|
+
)?.messages?.[0];
|
|
452
526
|
|
|
453
527
|
// REUPLOADING mediaStage means the media is expired and the download button is spinning, cannot be downloaded now
|
|
454
|
-
if (
|
|
528
|
+
if (
|
|
529
|
+
!msg ||
|
|
530
|
+
!msg.mediaData ||
|
|
531
|
+
msg.mediaData.mediaStage === 'REUPLOADING'
|
|
532
|
+
) {
|
|
455
533
|
return null;
|
|
456
534
|
}
|
|
457
535
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
|
458
536
|
// try to resolve media
|
|
459
537
|
await msg.downloadMedia({
|
|
460
538
|
downloadEvenIfExpensive: true,
|
|
461
|
-
rmrReason: 1
|
|
539
|
+
rmrReason: 1,
|
|
462
540
|
});
|
|
463
541
|
}
|
|
464
542
|
|
|
465
|
-
if (
|
|
543
|
+
if (
|
|
544
|
+
msg.mediaData.mediaStage.includes('ERROR') ||
|
|
545
|
+
msg.mediaData.mediaStage === 'FETCHING'
|
|
546
|
+
) {
|
|
466
547
|
// media could not be downloaded
|
|
467
548
|
return undefined;
|
|
468
549
|
}
|
|
469
550
|
|
|
470
551
|
try {
|
|
471
552
|
const mockQpl = {
|
|
472
|
-
addAnnotations: function() {
|
|
473
|
-
|
|
553
|
+
addAnnotations: function () {
|
|
554
|
+
return this;
|
|
555
|
+
},
|
|
556
|
+
addPoint: function () {
|
|
557
|
+
return this;
|
|
558
|
+
},
|
|
474
559
|
};
|
|
475
|
-
const decryptedMedia = await
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
+
);
|
|
487
577
|
|
|
488
578
|
return {
|
|
489
579
|
data,
|
|
490
580
|
mimetype: msg.mimetype,
|
|
491
581
|
filename: msg.filename,
|
|
492
|
-
filesize: msg.size
|
|
582
|
+
filesize: msg.size,
|
|
493
583
|
};
|
|
494
584
|
} catch (e) {
|
|
495
|
-
if(e.status && e.status === 404) return undefined;
|
|
585
|
+
if (e.status && e.status === 404) return undefined;
|
|
496
586
|
throw e;
|
|
497
587
|
}
|
|
498
588
|
}, this.id._serialized);
|
|
499
589
|
|
|
500
590
|
if (!result) return undefined;
|
|
501
|
-
return new MessageMedia(
|
|
591
|
+
return new MessageMedia(
|
|
592
|
+
result.mimetype,
|
|
593
|
+
result.data,
|
|
594
|
+
result.filename,
|
|
595
|
+
result.filesize,
|
|
596
|
+
);
|
|
502
597
|
}
|
|
503
598
|
|
|
504
599
|
/**
|
|
@@ -507,25 +602,66 @@ class Message extends Base {
|
|
|
507
602
|
* @param {?boolean} [clearMedia = true] If true, any associated media will also be deleted from a device.
|
|
508
603
|
*/
|
|
509
604
|
async delete(everyone, clearMedia = true) {
|
|
510
|
-
await this.client.pupPage.evaluate(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
+
}
|
|
524
648
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
+
);
|
|
529
665
|
}
|
|
530
666
|
|
|
531
667
|
/**
|
|
@@ -533,10 +669,20 @@ class Message extends Base {
|
|
|
533
669
|
*/
|
|
534
670
|
async star() {
|
|
535
671
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
536
|
-
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];
|
|
537
679
|
if (window.require('WAWebMsgActionCapability').canStarMsg(msg)) {
|
|
538
|
-
let chat = await
|
|
539
|
-
|
|
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);
|
|
540
686
|
}
|
|
541
687
|
}, this.id._serialized);
|
|
542
688
|
}
|
|
@@ -546,10 +692,20 @@ class Message extends Base {
|
|
|
546
692
|
*/
|
|
547
693
|
async unstar() {
|
|
548
694
|
await this.client.pupPage.evaluate(async (msgId) => {
|
|
549
|
-
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];
|
|
550
702
|
if (window.require('WAWebMsgActionCapability').canStarMsg(msg)) {
|
|
551
|
-
let chat = await
|
|
552
|
-
|
|
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);
|
|
553
709
|
}
|
|
554
710
|
}, this.id._serialized);
|
|
555
711
|
}
|
|
@@ -560,9 +716,17 @@ class Message extends Base {
|
|
|
560
716
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
561
717
|
*/
|
|
562
718
|
async pin(duration) {
|
|
563
|
-
return await this.client.pupPage.evaluate(
|
|
564
|
-
|
|
565
|
-
|
|
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
|
+
);
|
|
566
730
|
}
|
|
567
731
|
|
|
568
732
|
/**
|
|
@@ -593,13 +757,28 @@ class Message extends Base {
|
|
|
593
757
|
*/
|
|
594
758
|
async getInfo() {
|
|
595
759
|
const info = await this.client.pupPage.evaluate(async (msgId) => {
|
|
596
|
-
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];
|
|
597
767
|
if (!msg || !msg.id.fromMe) return null;
|
|
598
768
|
|
|
599
769
|
return new Promise((resolve) => {
|
|
600
|
-
setTimeout(
|
|
601
|
-
|
|
602
|
-
|
|
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
|
+
);
|
|
603
782
|
});
|
|
604
783
|
}, this.id._serialized);
|
|
605
784
|
|
|
@@ -612,14 +791,20 @@ class Message extends Base {
|
|
|
612
791
|
*/
|
|
613
792
|
async getOrder() {
|
|
614
793
|
if (this.type === MessageTypes.ORDER) {
|
|
615
|
-
const result = await this.client.pupPage.evaluate(
|
|
616
|
-
|
|
617
|
-
|
|
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
|
+
);
|
|
618
802
|
if (!result) return undefined;
|
|
619
803
|
return new Order(this.client, result);
|
|
620
804
|
}
|
|
621
805
|
return undefined;
|
|
622
806
|
}
|
|
807
|
+
|
|
623
808
|
/**
|
|
624
809
|
* Gets the payment details associated with a given message
|
|
625
810
|
* @return {Promise<Payment>}
|
|
@@ -627,8 +812,14 @@ class Message extends Base {
|
|
|
627
812
|
async getPayment() {
|
|
628
813
|
if (this.type === MessageTypes.PAYMENT) {
|
|
629
814
|
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
|
630
|
-
const msg =
|
|
631
|
-
|
|
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;
|
|
632
823
|
return msg.serialize();
|
|
633
824
|
}, this.id._serialized);
|
|
634
825
|
return new Payment(this.client, msg);
|
|
@@ -636,7 +827,6 @@ class Message extends Base {
|
|
|
636
827
|
return undefined;
|
|
637
828
|
}
|
|
638
829
|
|
|
639
|
-
|
|
640
830
|
/**
|
|
641
831
|
* Reaction List
|
|
642
832
|
* @typedef {Object} ReactionList
|
|
@@ -656,7 +846,9 @@ class Message extends Base {
|
|
|
656
846
|
}
|
|
657
847
|
|
|
658
848
|
const reactions = await this.client.pupPage.evaluate(async (msgId) => {
|
|
659
|
-
const msgReactions = await
|
|
849
|
+
const msgReactions = await window
|
|
850
|
+
.require('WAWebCollections')
|
|
851
|
+
.Reactions.find(msgId);
|
|
660
852
|
if (!msgReactions || !msgReactions.reactions.length) return null;
|
|
661
853
|
return msgReactions.reactions.serialize();
|
|
662
854
|
}, this.id._serialized);
|
|
@@ -665,8 +857,8 @@ class Message extends Base {
|
|
|
665
857
|
return undefined;
|
|
666
858
|
}
|
|
667
859
|
|
|
668
|
-
return reactions.map(reaction => {
|
|
669
|
-
reaction.senders = reaction.senders.map(sender => {
|
|
860
|
+
return reactions.map((reaction) => {
|
|
861
|
+
reaction.senders = reaction.senders.map((sender) => {
|
|
670
862
|
sender.timestamp = Math.round(sender.timestamp / 1000);
|
|
671
863
|
return new Reaction(this.client, sender);
|
|
672
864
|
});
|
|
@@ -682,36 +874,68 @@ class Message extends Base {
|
|
|
682
874
|
*/
|
|
683
875
|
async edit(content, options = {}) {
|
|
684
876
|
if (options.mentions) {
|
|
685
|
-
!Array.isArray(options.mentions) &&
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
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
|
+
);
|
|
689
890
|
}
|
|
690
891
|
}
|
|
691
892
|
|
|
692
|
-
options.groupMentions &&
|
|
893
|
+
options.groupMentions &&
|
|
894
|
+
!Array.isArray(options.groupMentions) &&
|
|
895
|
+
(options.groupMentions = [options.groupMentions]);
|
|
693
896
|
|
|
694
897
|
let internalOptions = {
|
|
695
898
|
linkPreview: options.linkPreview === false ? undefined : true,
|
|
696
899
|
mentionedJidList: options.mentions || [],
|
|
697
900
|
groupMentions: options.groupMentions,
|
|
698
|
-
extraOptions: options.extra
|
|
901
|
+
extraOptions: options.extra,
|
|
699
902
|
};
|
|
700
|
-
|
|
903
|
+
|
|
701
904
|
if (!this.fromMe) {
|
|
702
905
|
return null;
|
|
703
906
|
}
|
|
704
|
-
const messageEdit = await this.client.pupPage.evaluate(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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
|
+
);
|
|
715
939
|
if (messageEdit) {
|
|
716
940
|
return new Message(this.client, messageEdit);
|
|
717
941
|
}
|
|
@@ -729,28 +953,44 @@ class Message extends Base {
|
|
|
729
953
|
return null;
|
|
730
954
|
}
|
|
731
955
|
|
|
732
|
-
const edittedEventMsg = await this.client.pupPage.evaluate(
|
|
733
|
-
|
|
734
|
-
|
|
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
|
+
};
|
|
735
978
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
await (window.require('WAWebSendEventEditMsgAction')).sendEventEditMessage(eventOptions, msg);
|
|
748
|
-
const editedMsg = (window.require('WAWebCollections')).Msg.get(msg.id._serialized);
|
|
749
|
-
return editedMsg?.serialize();
|
|
750
|
-
}, 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
|
+
);
|
|
751
990
|
|
|
752
991
|
return edittedEventMsg && new Message(this.client, edittedEventMsg);
|
|
753
992
|
}
|
|
993
|
+
|
|
754
994
|
/**
|
|
755
995
|
* Returns the PollVote this poll message
|
|
756
996
|
* @returns {Promise<PollVote[]>}
|
|
@@ -765,24 +1005,36 @@ class Message extends Base {
|
|
|
765
1005
|
* @returns {Promise}
|
|
766
1006
|
*/
|
|
767
1007
|
async vote(selectedOptions) {
|
|
768
|
-
if (this.type != MessageTypes.POLL_CREATION)
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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
|
+
});
|
|
783
1030
|
|
|
784
|
-
|
|
785
|
-
|
|
1031
|
+
await window
|
|
1032
|
+
.require('WAWebPollsSendVoteMsgAction')
|
|
1033
|
+
.sendVote(msg, localIdSet);
|
|
1034
|
+
},
|
|
1035
|
+
this.id._serialized,
|
|
1036
|
+
selectedOptions,
|
|
1037
|
+
);
|
|
786
1038
|
}
|
|
787
1039
|
}
|
|
788
1040
|
|