@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
package/example.js
CHANGED
|
@@ -14,7 +14,7 @@ const client = new Client({
|
|
|
14
14
|
* If another value is provided, the browser icon in 'linked devices' section will be gray.
|
|
15
15
|
*/
|
|
16
16
|
// browserName: 'Firefox',
|
|
17
|
-
puppeteer: {
|
|
17
|
+
puppeteer: {
|
|
18
18
|
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
|
|
19
19
|
headless: false,
|
|
20
20
|
},
|
|
@@ -38,14 +38,14 @@ client.on('qr', async (qr) => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
client.on('code', (code) => {
|
|
41
|
-
console.log('Pairing code:',code);
|
|
41
|
+
console.log('Pairing code:', code);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
client.on('authenticated', () => {
|
|
45
45
|
console.log('AUTHENTICATED');
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
client.on('auth_failure', msg => {
|
|
48
|
+
client.on('auth_failure', (msg) => {
|
|
49
49
|
// Fired if session restore was unsuccessful
|
|
50
50
|
console.error('AUTHENTICATION FAILURE', msg);
|
|
51
51
|
});
|
|
@@ -55,26 +55,23 @@ client.on('ready', async () => {
|
|
|
55
55
|
const debugWWebVersion = await client.getWWebVersion();
|
|
56
56
|
console.log(`WWebVersion = ${debugWWebVersion}`);
|
|
57
57
|
|
|
58
|
-
client.pupPage.on('pageerror', function(err) {
|
|
58
|
+
client.pupPage.on('pageerror', function (err) {
|
|
59
59
|
console.log('Page error: ' + err.toString());
|
|
60
60
|
});
|
|
61
|
-
client.pupPage.on('error', function(err) {
|
|
61
|
+
client.pupPage.on('error', function (err) {
|
|
62
62
|
console.log('Page error: ' + err.toString());
|
|
63
63
|
});
|
|
64
|
-
|
|
65
64
|
});
|
|
66
65
|
|
|
67
|
-
client.on('message', async msg => {
|
|
66
|
+
client.on('message', async (msg) => {
|
|
68
67
|
console.log('MESSAGE RECEIVED', msg);
|
|
69
68
|
|
|
70
69
|
if (msg.body === '!ping reply') {
|
|
71
70
|
// Send a new message as a reply to the current one
|
|
72
71
|
msg.reply('pong');
|
|
73
|
-
|
|
74
72
|
} else if (msg.body === '!ping') {
|
|
75
73
|
// Send a new message to the same chat
|
|
76
74
|
client.sendMessage(msg.from, 'pong');
|
|
77
|
-
|
|
78
75
|
} else if (msg.body.startsWith('!sendto ')) {
|
|
79
76
|
// Direct send a new message to specific id
|
|
80
77
|
let number = msg.body.split(' ')[1];
|
|
@@ -84,7 +81,6 @@ client.on('message', async msg => {
|
|
|
84
81
|
let chat = await msg.getChat();
|
|
85
82
|
chat.sendSeen();
|
|
86
83
|
client.sendMessage(number, message);
|
|
87
|
-
|
|
88
84
|
} else if (msg.body.startsWith('!subject ')) {
|
|
89
85
|
// Change the group subject
|
|
90
86
|
let chat = await msg.getChat();
|
|
@@ -123,11 +119,16 @@ client.on('message', async msg => {
|
|
|
123
119
|
await client.acceptInvite(inviteCode);
|
|
124
120
|
msg.reply('Joined the group!');
|
|
125
121
|
} catch (e) {
|
|
122
|
+
console.error(e);
|
|
126
123
|
msg.reply('That invite code seems to be invalid.');
|
|
127
124
|
}
|
|
128
125
|
} else if (msg.body.startsWith('!addmembers')) {
|
|
129
126
|
const group = await msg.getChat();
|
|
130
|
-
const result = await group.addParticipants([
|
|
127
|
+
const result = await group.addParticipants([
|
|
128
|
+
'number1@c.us',
|
|
129
|
+
'number2@c.us',
|
|
130
|
+
'number3@c.us',
|
|
131
|
+
]);
|
|
131
132
|
/**
|
|
132
133
|
* The example of the {@link result} output:
|
|
133
134
|
*
|
|
@@ -150,12 +151,19 @@ client.on('message', async msg => {
|
|
|
150
151
|
* }
|
|
151
152
|
*
|
|
152
153
|
* For more usage examples:
|
|
153
|
-
* @see https://github.com/
|
|
154
|
+
* @see https://github.com/wwebjs/whatsapp-web.js/pull/2344#usage-example1
|
|
154
155
|
*/
|
|
155
156
|
console.log(result);
|
|
156
157
|
} else if (msg.body === '!creategroup') {
|
|
157
|
-
const partitipantsToAdd = [
|
|
158
|
-
|
|
158
|
+
const partitipantsToAdd = [
|
|
159
|
+
'number1@c.us',
|
|
160
|
+
'number2@c.us',
|
|
161
|
+
'number3@c.us',
|
|
162
|
+
];
|
|
163
|
+
const result = await client.createGroup(
|
|
164
|
+
'Group Title',
|
|
165
|
+
partitipantsToAdd,
|
|
166
|
+
);
|
|
159
167
|
/**
|
|
160
168
|
* The example of the {@link result} output:
|
|
161
169
|
* {
|
|
@@ -194,7 +202,7 @@ client.on('message', async msg => {
|
|
|
194
202
|
* }
|
|
195
203
|
*
|
|
196
204
|
* For more usage examples:
|
|
197
|
-
* @see https://github.com/
|
|
205
|
+
* @see https://github.com/wwebjs/whatsapp-web.js/pull/2344#usage-example2
|
|
198
206
|
*/
|
|
199
207
|
console.log(result);
|
|
200
208
|
} else if (msg.body === '!groupinfo') {
|
|
@@ -216,12 +224,15 @@ client.on('message', async msg => {
|
|
|
216
224
|
client.sendMessage(msg.from, `The bot has ${chats.length} chats open.`);
|
|
217
225
|
} else if (msg.body === '!info') {
|
|
218
226
|
let info = client.info;
|
|
219
|
-
client.sendMessage(
|
|
227
|
+
client.sendMessage(
|
|
228
|
+
msg.from,
|
|
229
|
+
`
|
|
220
230
|
*Connection info*
|
|
221
231
|
User name: ${info.pushname}
|
|
222
232
|
My number: ${info.wid.user}
|
|
223
233
|
Platform: ${info.platform}
|
|
224
|
-
|
|
234
|
+
`,
|
|
235
|
+
);
|
|
225
236
|
} else if (msg.body === '!mediainfo' && msg.hasMedia) {
|
|
226
237
|
const attachmentData = await msg.downloadMedia();
|
|
227
238
|
msg.reply(`
|
|
@@ -244,11 +255,15 @@ client.on('message', async msg => {
|
|
|
244
255
|
const quotedMsg = await msg.getQuotedMessage();
|
|
245
256
|
if (quotedMsg.hasMedia) {
|
|
246
257
|
const attachmentData = await quotedMsg.downloadMedia();
|
|
247
|
-
client.sendMessage(msg.from, attachmentData, {
|
|
258
|
+
client.sendMessage(msg.from, attachmentData, {
|
|
259
|
+
caption: "Here's your requested media.",
|
|
260
|
+
});
|
|
248
261
|
}
|
|
249
262
|
if (quotedMsg.hasMedia && quotedMsg.type === 'audio') {
|
|
250
263
|
const audio = await quotedMsg.downloadMedia();
|
|
251
|
-
await client.sendMessage(msg.from, audio, {
|
|
264
|
+
await client.sendMessage(msg.from, audio, {
|
|
265
|
+
sendAudioAsVoice: true,
|
|
266
|
+
});
|
|
252
267
|
}
|
|
253
268
|
} else if (msg.body === '!isviewonce' && msg.hasQuotedMsg) {
|
|
254
269
|
const quotedMsg = await msg.getQuotedMessage();
|
|
@@ -262,9 +277,19 @@ client.on('message', async msg => {
|
|
|
262
277
|
// location with name only
|
|
263
278
|
await msg.reply(new Location(37.422, -122.084, { name: 'Googleplex' }));
|
|
264
279
|
// location with address only
|
|
265
|
-
await msg.reply(
|
|
280
|
+
await msg.reply(
|
|
281
|
+
new Location(37.422, -122.084, {
|
|
282
|
+
address: '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA',
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
266
285
|
// location with name, address and url
|
|
267
|
-
await msg.reply(
|
|
286
|
+
await msg.reply(
|
|
287
|
+
new Location(37.422, -122.084, {
|
|
288
|
+
name: 'Googleplex',
|
|
289
|
+
address: '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA',
|
|
290
|
+
url: 'https://google.com',
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
268
293
|
} else if (msg.location) {
|
|
269
294
|
msg.reply(msg.location);
|
|
270
295
|
} else if (msg.body.startsWith('!status ')) {
|
|
@@ -279,11 +304,11 @@ client.on('message', async msg => {
|
|
|
279
304
|
* without wrapping it in Array, and a user's phone number to the message body:
|
|
280
305
|
*/
|
|
281
306
|
await chat.sendMessage(`Hi @${userNumber}`, {
|
|
282
|
-
mentions: userNumber + '@c.us'
|
|
307
|
+
mentions: userNumber + '@c.us',
|
|
283
308
|
});
|
|
284
309
|
// To mention a list of users:
|
|
285
310
|
await chat.sendMessage(`Hi @${userNumber}, @${userNumber}`, {
|
|
286
|
-
mentions: [userNumber + '@c.us', userNumber + '@c.us']
|
|
311
|
+
mentions: [userNumber + '@c.us', userNumber + '@c.us'],
|
|
287
312
|
});
|
|
288
313
|
} else if (msg.body === '!mentionGroups') {
|
|
289
314
|
const chat = await msg.getChat();
|
|
@@ -292,28 +317,35 @@ client.on('message', async msg => {
|
|
|
292
317
|
* Sends clickable group mentions, the same as user mentions.
|
|
293
318
|
* When the mentions are clicked, it opens a chat with the mentioned group.
|
|
294
319
|
* The 'groupMentions.subject' can be custom
|
|
295
|
-
*
|
|
320
|
+
*
|
|
296
321
|
* @note The user that does not participate in the mentioned group,
|
|
297
322
|
* will not be able to click on that mentioned group, the same if the group does not exist
|
|
298
323
|
*
|
|
299
324
|
* To mention one group:
|
|
300
325
|
*/
|
|
301
326
|
await chat.sendMessage(`Check the last message here: @${groupId}`, {
|
|
302
|
-
groupMentions: { subject: 'GroupSubject', id: groupId }
|
|
327
|
+
groupMentions: { subject: 'GroupSubject', id: groupId },
|
|
303
328
|
});
|
|
304
329
|
// To mention a list of groups:
|
|
305
|
-
await chat.sendMessage(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
330
|
+
await chat.sendMessage(
|
|
331
|
+
`Check the last message in these groups: @${groupId}, @${groupId}`,
|
|
332
|
+
{
|
|
333
|
+
groupMentions: [
|
|
334
|
+
{ subject: 'FirstGroup', id: groupId },
|
|
335
|
+
{ subject: 'SecondGroup', id: groupId },
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
);
|
|
311
339
|
} else if (msg.body === '!getGroupMentions') {
|
|
312
340
|
// To get group mentions from a message:
|
|
313
341
|
const groupId = 'ZZZZZZZZZZ@g.us';
|
|
314
|
-
const msg = await client.sendMessage(
|
|
315
|
-
|
|
316
|
-
|
|
342
|
+
const msg = await client.sendMessage(
|
|
343
|
+
'chatId',
|
|
344
|
+
`Check the last message here: @${groupId}`,
|
|
345
|
+
{
|
|
346
|
+
groupMentions: { subject: 'GroupSubject', id: groupId },
|
|
347
|
+
},
|
|
348
|
+
);
|
|
317
349
|
/** {@link groupMentions} is an array of `GroupChat` */
|
|
318
350
|
const groupMentions = await msg.getGroupMentions();
|
|
319
351
|
console.log(groupMentions);
|
|
@@ -356,13 +388,30 @@ client.on('message', async msg => {
|
|
|
356
388
|
client.interface.openChatWindowAt(quotedMsg.id._serialized);
|
|
357
389
|
}
|
|
358
390
|
} else if (msg.body === '!buttons') {
|
|
359
|
-
let button = new Buttons(
|
|
391
|
+
let button = new Buttons(
|
|
392
|
+
'Button body',
|
|
393
|
+
[{ body: 'bt1' }, { body: 'bt2' }, { body: 'bt3' }],
|
|
394
|
+
'title',
|
|
395
|
+
'footer',
|
|
396
|
+
);
|
|
360
397
|
client.sendMessage(msg.from, button);
|
|
361
398
|
} else if (msg.body === '!list') {
|
|
362
399
|
let sections = [
|
|
363
|
-
{
|
|
400
|
+
{
|
|
401
|
+
title: 'sectionTitle',
|
|
402
|
+
rows: [
|
|
403
|
+
{ title: 'ListItem1', description: 'desc' },
|
|
404
|
+
{ title: 'ListItem2' },
|
|
405
|
+
],
|
|
406
|
+
},
|
|
364
407
|
];
|
|
365
|
-
let list = new List(
|
|
408
|
+
let list = new List(
|
|
409
|
+
'List body',
|
|
410
|
+
'btnText',
|
|
411
|
+
sections,
|
|
412
|
+
'Title',
|
|
413
|
+
'footer',
|
|
414
|
+
);
|
|
366
415
|
client.sendMessage(msg.from, list);
|
|
367
416
|
} else if (msg.body === '!reaction') {
|
|
368
417
|
await msg.react('👍');
|
|
@@ -370,7 +419,11 @@ client.on('message', async msg => {
|
|
|
370
419
|
/** By default the poll is created as a single choice poll: */
|
|
371
420
|
await msg.reply(new Poll('Winter or Summer?', ['Winter', 'Summer']));
|
|
372
421
|
/** If you want to provide a multiple choice poll, add allowMultipleAnswers as true: */
|
|
373
|
-
await msg.reply(
|
|
422
|
+
await msg.reply(
|
|
423
|
+
new Poll('Cats or Dogs?', ['Cats', 'Dogs'], {
|
|
424
|
+
allowMultipleAnswers: true,
|
|
425
|
+
}),
|
|
426
|
+
);
|
|
374
427
|
/**
|
|
375
428
|
* You can provide a custom message secret, it can be used as a poll ID:
|
|
376
429
|
* @note It has to be a unique vector with a length of 32
|
|
@@ -378,9 +431,10 @@ client.on('message', async msg => {
|
|
|
378
431
|
await msg.reply(
|
|
379
432
|
new Poll('Cats or Dogs?', ['Cats', 'Dogs'], {
|
|
380
433
|
messageSecret: [
|
|
381
|
-
1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
382
|
-
|
|
383
|
-
|
|
434
|
+
1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
435
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
436
|
+
],
|
|
437
|
+
}),
|
|
384
438
|
);
|
|
385
439
|
} else if (msg.body === '!vote') {
|
|
386
440
|
if (msg.hasQuotedMsg) {
|
|
@@ -417,13 +471,17 @@ client.on('message', async msg => {
|
|
|
417
471
|
* Presented an example for membership request approvals, the same examples are for the request rejections.
|
|
418
472
|
* To approve the membership request from a specific user:
|
|
419
473
|
*/
|
|
420
|
-
await client.approveGroupMembershipRequests(msg.from, {
|
|
474
|
+
await client.approveGroupMembershipRequests(msg.from, {
|
|
475
|
+
requesterIds: 'number@c.us',
|
|
476
|
+
});
|
|
421
477
|
/** The same for execution on group object (no need to provide the group ID): */
|
|
422
478
|
const group = await msg.getChat();
|
|
423
|
-
await group.approveGroupMembershipRequests({
|
|
479
|
+
await group.approveGroupMembershipRequests({
|
|
480
|
+
requesterIds: 'number@c.us',
|
|
481
|
+
});
|
|
424
482
|
/** To approve several membership requests: */
|
|
425
483
|
const approval = await client.approveGroupMembershipRequests(msg.from, {
|
|
426
|
-
requesterIds: ['number1@c.us', 'number2@c.us']
|
|
484
|
+
requesterIds: ['number1@c.us', 'number2@c.us'],
|
|
427
485
|
});
|
|
428
486
|
/**
|
|
429
487
|
* The example of the {@link approval} output:
|
|
@@ -446,17 +504,17 @@ client.on('message', async msg => {
|
|
|
446
504
|
/** To change the sleep value to 300 ms: */
|
|
447
505
|
await client.approveGroupMembershipRequests(msg.from, {
|
|
448
506
|
requesterIds: ['number1@c.us', 'number2@c.us'],
|
|
449
|
-
sleep: 300
|
|
507
|
+
sleep: 300,
|
|
450
508
|
});
|
|
451
509
|
/** To change the sleep value to random value between 100 and 300 ms: */
|
|
452
510
|
await client.approveGroupMembershipRequests(msg.from, {
|
|
453
511
|
requesterIds: ['number1@c.us', 'number2@c.us'],
|
|
454
|
-
sleep: [100, 300]
|
|
512
|
+
sleep: [100, 300],
|
|
455
513
|
});
|
|
456
514
|
/** To explicitly disable the sleep: */
|
|
457
515
|
await client.approveGroupMembershipRequests(msg.from, {
|
|
458
516
|
requesterIds: ['number1@c.us', 'number2@c.us'],
|
|
459
|
-
sleep: null
|
|
517
|
+
sleep: null,
|
|
460
518
|
});
|
|
461
519
|
} else if (msg.body === '!pinmsg') {
|
|
462
520
|
/**
|
|
@@ -482,8 +540,12 @@ client.on('message', async msg => {
|
|
|
482
540
|
// Or through the Chat object:
|
|
483
541
|
// const chat = await client.getChatById(msg.from);
|
|
484
542
|
// const isSynced = await chat.syncHistory();
|
|
485
|
-
|
|
486
|
-
await msg.reply(
|
|
543
|
+
|
|
544
|
+
await msg.reply(
|
|
545
|
+
isSynced
|
|
546
|
+
? 'Historical chat is syncing..'
|
|
547
|
+
: 'There is no historical chat to sync.',
|
|
548
|
+
);
|
|
487
549
|
} else if (msg.body === '!statuses') {
|
|
488
550
|
const statuses = await client.getBroadcasts();
|
|
489
551
|
console.log(statuses);
|
|
@@ -526,10 +588,14 @@ client.on('message', async msg => {
|
|
|
526
588
|
} else if (msg.body === '!postStatus') {
|
|
527
589
|
await client.sendMessage('status@broadcast', 'Hello there!');
|
|
528
590
|
// send with a different style
|
|
529
|
-
await client.sendMessage(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
591
|
+
await client.sendMessage(
|
|
592
|
+
'status@broadcast',
|
|
593
|
+
'Hello again! Looks different?',
|
|
594
|
+
{
|
|
595
|
+
fontStyle: 1,
|
|
596
|
+
backgroundColor: '#0b3296',
|
|
597
|
+
},
|
|
598
|
+
);
|
|
533
599
|
}
|
|
534
600
|
});
|
|
535
601
|
|
|
@@ -554,7 +620,7 @@ client.on('message_ciphertext', (msg) => {
|
|
|
554
620
|
// Receiving new incoming messages that have been encrypted
|
|
555
621
|
// msg.type === 'ciphertext'
|
|
556
622
|
msg.body = 'Waiting for this message. Check your phone.';
|
|
557
|
-
|
|
623
|
+
|
|
558
624
|
// do stuff here
|
|
559
625
|
});
|
|
560
626
|
|
|
@@ -604,7 +670,7 @@ client.on('group_update', (notification) => {
|
|
|
604
670
|
console.log('update', notification);
|
|
605
671
|
});
|
|
606
672
|
|
|
607
|
-
client.on('change_state', state => {
|
|
673
|
+
client.on('change_state', (state) => {
|
|
608
674
|
console.log('CHANGE STATE', state);
|
|
609
675
|
});
|
|
610
676
|
|
|
@@ -614,7 +680,10 @@ let rejectCalls = true;
|
|
|
614
680
|
client.on('call', async (call) => {
|
|
615
681
|
console.log('Call received, rejecting. GOTO Line 261 to disable', call);
|
|
616
682
|
if (rejectCalls) await call.reject();
|
|
617
|
-
await client.sendMessage(
|
|
683
|
+
await client.sendMessage(
|
|
684
|
+
call.from,
|
|
685
|
+
`[${call.fromMe ? 'Outgoing' : 'Incoming'}] Phone call from ${call.from}, type ${call.isGroup ? 'group' : ''} ${call.isVideo ? 'video' : 'audio'} call. ${rejectCalls ? 'This call was automatically rejected by the script.' : ''}`,
|
|
686
|
+
);
|
|
618
687
|
});
|
|
619
688
|
|
|
620
689
|
client.on('disconnected', (reason) => {
|
|
@@ -623,32 +692,37 @@ client.on('disconnected', (reason) => {
|
|
|
623
692
|
|
|
624
693
|
client.on('contact_changed', async (message, oldId, newId, isContact) => {
|
|
625
694
|
/** The time the event occurred. */
|
|
626
|
-
const eventTime =
|
|
695
|
+
const eventTime = new Date(message.timestamp * 1000).toLocaleString();
|
|
627
696
|
|
|
628
697
|
console.log(
|
|
629
698
|
`The contact ${oldId.slice(0, -5)}` +
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
699
|
+
`${
|
|
700
|
+
!isContact
|
|
701
|
+
? ' that participates in group ' +
|
|
702
|
+
`${(await client.getChatById(message.to ?? message.from)).name} `
|
|
703
|
+
: ' '
|
|
704
|
+
}` +
|
|
705
|
+
`changed their phone number\nat ${eventTime}.\n` +
|
|
706
|
+
`Their new phone number is ${newId.slice(0, -5)}.\n`,
|
|
707
|
+
);
|
|
634
708
|
|
|
635
709
|
/**
|
|
636
710
|
* Information about the @param {message}:
|
|
637
|
-
*
|
|
711
|
+
*
|
|
638
712
|
* 1. If a notification was emitted due to a group participant changing their phone number:
|
|
639
713
|
* @param {message.author} is a participant's id before the change.
|
|
640
714
|
* @param {message.recipients[0]} is a participant's id after the change (a new one).
|
|
641
|
-
*
|
|
715
|
+
*
|
|
642
716
|
* 1.1 If the contact who changed their number WAS in the current user's contact list at the time of the change:
|
|
643
717
|
* @param {message.to} is a group chat id the event was emitted in.
|
|
644
718
|
* @param {message.from} is a current user's id that got an notification message in the group.
|
|
645
719
|
* Also the @param {message.fromMe} is TRUE.
|
|
646
|
-
*
|
|
720
|
+
*
|
|
647
721
|
* 1.2 Otherwise:
|
|
648
722
|
* @param {message.from} is a group chat id the event was emitted in.
|
|
649
723
|
* @param {message.to} is @type {undefined}.
|
|
650
724
|
* Also @param {message.fromMe} is FALSE.
|
|
651
|
-
*
|
|
725
|
+
*
|
|
652
726
|
* 2. If a notification was emitted due to a contact changing their phone number:
|
|
653
727
|
* @param {message.templateParams} is an array of two user's ids:
|
|
654
728
|
* the old (before the change) and a new one, stored in alphabetical order.
|
|
@@ -660,10 +734,10 @@ client.on('contact_changed', async (message, oldId, newId, isContact) => {
|
|
|
660
734
|
|
|
661
735
|
client.on('group_admin_changed', (notification) => {
|
|
662
736
|
if (notification.type === 'promote') {
|
|
663
|
-
/**
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
737
|
+
/**
|
|
738
|
+
* Emitted when a current user is promoted to an admin.
|
|
739
|
+
* {@link notification.author} is a user who performs the action of promoting/demoting the current user.
|
|
740
|
+
*/
|
|
667
741
|
console.log(`You were promoted by ${notification.author}`);
|
|
668
742
|
} else if (notification.type === 'demote')
|
|
669
743
|
/** Emitted when a current user is demoted to a regular user. */
|
|
@@ -692,8 +766,14 @@ client.on('group_membership_request', async (notification) => {
|
|
|
692
766
|
*/
|
|
693
767
|
console.log(notification);
|
|
694
768
|
/** You can approve or reject the newly appeared membership request: */
|
|
695
|
-
await client.approveGroupMembershipRequestss(
|
|
696
|
-
|
|
769
|
+
await client.approveGroupMembershipRequestss(
|
|
770
|
+
notification.chatId,
|
|
771
|
+
notification.author,
|
|
772
|
+
);
|
|
773
|
+
await client.rejectGroupMembershipRequests(
|
|
774
|
+
notification.chatId,
|
|
775
|
+
notification.author,
|
|
776
|
+
);
|
|
697
777
|
});
|
|
698
778
|
|
|
699
779
|
client.on('message_reaction', async (reaction) => {
|