sauruslord-baileys 2.1.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +2 -4
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/baileys-version.json +3 -0
- package/lib/Signal/index.d.ts +53 -0
- package/lib/Signal/index.js +147 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +3 -22
- package/lib/Socket/dugong.js +9 -148
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/lordsaurus.d.ts +266 -0
- package/lib/Socket/lordsaurus.js +580 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1085 -1085
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +257 -391
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +53 -159
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +7 -23
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +0 -1
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +47 -135
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +24 -70
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +4 -180
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +40 -19
- package/package.json +9 -9
- package/LICENSE +0 -21
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesRecvSocket = void 0;
|
|
@@ -16,1089 +16,1089 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const groups_1 = require("./groups");
|
|
17
17
|
const messages_send_1 = require("./messages-send");
|
|
18
18
|
const makeMessagesRecvSocket = (config) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
19
|
+
const {
|
|
20
|
+
logger,
|
|
21
|
+
retryRequestDelayMs,
|
|
22
|
+
maxMsgRetryCount,
|
|
23
|
+
getMessage,
|
|
24
|
+
shouldIgnoreJid
|
|
25
|
+
} = config;
|
|
26
|
+
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
27
|
+
const {
|
|
28
|
+
ev,
|
|
29
|
+
authState,
|
|
30
|
+
ws,
|
|
31
|
+
processingMutex,
|
|
32
|
+
signalRepository,
|
|
33
|
+
query,
|
|
34
|
+
upsertMessage,
|
|
35
|
+
resyncAppState,
|
|
36
|
+
groupMetadata,
|
|
37
|
+
onUnexpectedError,
|
|
38
|
+
assertSessions,
|
|
39
|
+
sendNode,
|
|
40
|
+
relayMessage,
|
|
41
|
+
sendReceipt,
|
|
42
|
+
uploadPreKeys,
|
|
43
|
+
createParticipantNodes,
|
|
44
|
+
getUSyncDevices,
|
|
45
|
+
sendPeerDataOperationMessage
|
|
46
|
+
} = sock;
|
|
47
|
+
const retryMutex = (0, make_mutex_1.makeMutex)();
|
|
48
|
+
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
|
49
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
50
|
+
useClones: false
|
|
51
|
+
});
|
|
52
|
+
const callOfferCache = config.callOfferCache || new node_cache_1.default({
|
|
53
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
54
|
+
useClones: false
|
|
55
|
+
});
|
|
56
|
+
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
57
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
58
|
+
useClones: false
|
|
59
|
+
});
|
|
60
|
+
let sendActiveReceipts = false;
|
|
61
|
+
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
62
|
+
const stanza = {
|
|
63
|
+
tag: 'ack',
|
|
64
|
+
attrs: {
|
|
65
|
+
id: attrs.id,
|
|
66
|
+
to: attrs.from,
|
|
67
|
+
class: tag
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!!errorCode) {
|
|
71
|
+
stanza.attrs.error = errorCode.toString();
|
|
72
|
+
}
|
|
73
|
+
if (!!attrs.participant) {
|
|
74
|
+
stanza.attrs.participant = attrs.participant;
|
|
75
|
+
}
|
|
76
|
+
if (!!attrs.recipient) {
|
|
77
|
+
stanza.attrs.recipient = attrs.recipient;
|
|
78
|
+
}
|
|
79
|
+
if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
|
|
80
|
+
stanza.attrs.type = attrs.type;
|
|
81
|
+
}
|
|
82
|
+
if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
|
|
83
|
+
stanza.attrs.from = authState.creds.me.id;
|
|
84
|
+
}
|
|
85
|
+
logger.debug({
|
|
86
|
+
recv: {
|
|
87
|
+
tag,
|
|
88
|
+
attrs
|
|
89
|
+
},
|
|
90
|
+
sent: stanza.attrs }, 'sent ack');
|
|
91
|
+
await sendNode(stanza);
|
|
92
|
+
};
|
|
93
|
+
const offerCall = async (toJid, isVideo = false) => {
|
|
94
|
+
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
|
95
|
+
const offerContent = [];
|
|
96
|
+
offerContent.push({
|
|
97
|
+
tag: 'audio',
|
|
98
|
+
attrs: {
|
|
99
|
+
enc: 'opus',
|
|
100
|
+
rate: '16000'
|
|
101
|
+
}, content: undefined
|
|
102
|
+
});
|
|
103
|
+
offerContent.push({
|
|
104
|
+
tag: 'audio',
|
|
105
|
+
attrs: {
|
|
106
|
+
enc: 'opus',
|
|
107
|
+
rate: '8000'
|
|
108
|
+
}, content: undefined
|
|
109
|
+
});
|
|
110
|
+
if (isVideo) {
|
|
111
|
+
offerContent.push({
|
|
112
|
+
tag: 'video',
|
|
113
|
+
attrs: {
|
|
114
|
+
orientation: '0',
|
|
115
|
+
'screen_width': '1920',
|
|
116
|
+
'screen_height': '1080',
|
|
117
|
+
'device_orientation': '0',
|
|
118
|
+
enc: 'vp8',
|
|
119
|
+
dec: 'vp8',
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
offerContent.push({
|
|
124
|
+
tag: 'net',
|
|
125
|
+
attrs: {
|
|
126
|
+
medium: '3'
|
|
127
|
+
}, content: undefined
|
|
128
|
+
});
|
|
129
|
+
offerContent.push({
|
|
130
|
+
tag: 'capability',
|
|
131
|
+
attrs: {
|
|
132
|
+
ver: '1'
|
|
133
|
+
}, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
|
|
134
|
+
offerContent.push({
|
|
135
|
+
tag: 'encopt',
|
|
136
|
+
attrs: {
|
|
137
|
+
keygen: '2'
|
|
138
|
+
}, content: undefined
|
|
139
|
+
})
|
|
140
|
+
const encKey = (0, crypto_1.randomBytes)(32);
|
|
141
|
+
const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device));
|
|
142
|
+
await assertSessions(devices, true);
|
|
143
|
+
const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
|
|
144
|
+
call: {
|
|
145
|
+
callKey: encKey
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
|
|
149
|
+
if (shouldIncludeDeviceIdentity) {
|
|
150
|
+
offerContent.push({
|
|
151
|
+
tag: 'device-identity',
|
|
152
|
+
attrs: {},
|
|
153
|
+
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const stanza = ({
|
|
157
|
+
tag: 'call',
|
|
158
|
+
attrs: {
|
|
159
|
+
to: toJid,
|
|
160
|
+
},
|
|
161
|
+
content: [{
|
|
162
|
+
tag: 'offer',
|
|
163
|
+
attrs: {
|
|
164
|
+
'call-id': callId,
|
|
165
|
+
'call-creator': authState.creds.me.id,
|
|
166
|
+
},
|
|
167
|
+
content: offerContent,
|
|
168
|
+
}],
|
|
169
|
+
});
|
|
170
|
+
await query(stanza);
|
|
171
|
+
return {
|
|
172
|
+
callId,
|
|
173
|
+
toJid,
|
|
174
|
+
isVideo,
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
const rejectCall = async (callId, callFrom) => {
|
|
178
|
+
const stanza = ({
|
|
179
|
+
tag: 'call',
|
|
180
|
+
attrs: {
|
|
181
|
+
from: authState.creds.me.id,
|
|
182
|
+
to: callFrom,
|
|
183
|
+
},
|
|
184
|
+
content: [{
|
|
185
|
+
tag: 'reject',
|
|
186
|
+
attrs: {
|
|
187
|
+
'call-id': callId,
|
|
188
|
+
'call-creator': callFrom,
|
|
189
|
+
count: '0',
|
|
190
|
+
},
|
|
191
|
+
content: undefined,
|
|
192
|
+
}],
|
|
193
|
+
});
|
|
194
|
+
await query(stanza);
|
|
195
|
+
};
|
|
196
|
+
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
197
|
+
const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
198
|
+
const { key: msgKey } = fullMessage;
|
|
199
|
+
const msgId = msgKey.id;
|
|
200
|
+
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
|
201
|
+
let retryCount = msgRetryCache.get(key) || 0;
|
|
202
|
+
if (retryCount >= maxMsgRetryCount) {
|
|
203
|
+
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
204
|
+
msgRetryCache.del(key);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
retryCount += 1;
|
|
208
|
+
msgRetryCache.set(key, retryCount);
|
|
209
|
+
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
|
|
210
|
+
if (retryCount === 1) {
|
|
211
|
+
const msgId = await requestPlaceholderResend(msgKey);
|
|
212
|
+
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
213
|
+
}
|
|
214
|
+
const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
|
|
215
|
+
await authState.keys.transaction(async () => {
|
|
216
|
+
const receipt = {
|
|
217
|
+
tag: 'receipt',
|
|
218
|
+
attrs: {
|
|
219
|
+
id: msgId,
|
|
220
|
+
type: 'retry',
|
|
221
|
+
to: node.attrs.from
|
|
222
|
+
},
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
tag: 'retry',
|
|
226
|
+
attrs: {
|
|
227
|
+
count: retryCount.toString(),
|
|
228
|
+
id: node.attrs.id,
|
|
229
|
+
t: node.attrs.t,
|
|
230
|
+
v: '1'
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
tag: 'registration',
|
|
235
|
+
attrs: {},
|
|
236
|
+
content: (0, Utils_1.encodeBigEndian)(authState.creds.registrationId)
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
};
|
|
240
|
+
if (node.attrs.recipient) {
|
|
241
|
+
receipt.attrs.recipient = node.attrs.recipient;
|
|
242
|
+
}
|
|
243
|
+
if (node.attrs.participant) {
|
|
244
|
+
receipt.attrs.participant = node.attrs.participant;
|
|
245
|
+
}
|
|
246
|
+
if (retryCount > 1 || forceIncludeKeys) {
|
|
247
|
+
const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
|
|
248
|
+
const [keyId] = Object.keys(preKeys);
|
|
249
|
+
const key = preKeys[+keyId];
|
|
250
|
+
const content = receipt.content;
|
|
251
|
+
content.push({
|
|
252
|
+
tag: 'keys',
|
|
253
|
+
attrs: {},
|
|
254
|
+
content: [
|
|
255
|
+
{ tag: 'type', attrs: {}, content: Buffer.from(Defaults_1.KEY_BUNDLE_TYPE) },
|
|
256
|
+
{ tag: 'identity', attrs: {}, content: identityKey.public },
|
|
257
|
+
(0, Utils_1.xmppPreKey)(key, +keyId),
|
|
258
|
+
(0, Utils_1.xmppSignedPreKey)(signedPreKey),
|
|
259
|
+
{ tag: 'device-identity', attrs: {}, content: deviceIdentity }
|
|
260
|
+
]
|
|
261
|
+
});
|
|
262
|
+
ev.emit('creds.update', update);
|
|
263
|
+
}
|
|
264
|
+
await sendNode(receipt);
|
|
265
|
+
logger.info({ msgAttrs: node.attrs, retryCount }, 'sent retry receipt');
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
const handleEncryptNotification = async (node) => {
|
|
269
|
+
const from = node.attrs.from;
|
|
270
|
+
if (from === WABinary_1.S_WHATSAPP_NET) {
|
|
271
|
+
const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
|
|
272
|
+
const count = +countChild.attrs.value;
|
|
273
|
+
const shouldUploadMorePreKeys = count < Defaults_1.MIN_PREKEY_COUNT;
|
|
274
|
+
logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
|
|
275
|
+
if (shouldUploadMorePreKeys) {
|
|
276
|
+
await uploadPreKeys();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
const identityNode = (0, WABinary_1.getBinaryNodeChild)(node, 'identity');
|
|
281
|
+
if (identityNode) {
|
|
282
|
+
logger.info({ jid: from }, 'identity changed');
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
logger.info({ node }, 'unknown encrypt notification');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const handleGroupNotification = (participant, child, msg) => {
|
|
290
|
+
var _a, _b, _c, _d;
|
|
291
|
+
const participantJid = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant;
|
|
292
|
+
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
293
|
+
case 'create':
|
|
294
|
+
const metadata = (0, groups_1.extractGroupMetadata)(child);
|
|
295
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
|
|
296
|
+
msg.messageStubParameters = [metadata.subject];
|
|
297
|
+
msg.key = { participant: metadata.owner };
|
|
298
|
+
ev.emit('chats.upsert', [{
|
|
299
|
+
id: metadata.id,
|
|
300
|
+
name: metadata.subject,
|
|
301
|
+
conversationTimestamp: metadata.creation,
|
|
302
|
+
}]);
|
|
303
|
+
ev.emit('groups.upsert', [{
|
|
304
|
+
...metadata,
|
|
305
|
+
author: participant
|
|
306
|
+
}]);
|
|
307
|
+
break;
|
|
308
|
+
case 'ephemeral':
|
|
309
|
+
case 'not_ephemeral':
|
|
310
|
+
msg.message = {
|
|
311
|
+
protocolMessage: {
|
|
312
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
313
|
+
ephemeralExpiration: +(child.attrs.expiration || 0)
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
break;
|
|
317
|
+
case 'modify':
|
|
318
|
+
const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
|
319
|
+
msg.messageStubParameters = oldNumber || [];
|
|
320
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
321
|
+
break;
|
|
322
|
+
case 'promote':
|
|
323
|
+
case 'demote':
|
|
324
|
+
case 'remove':
|
|
325
|
+
case 'add':
|
|
326
|
+
case 'leave':
|
|
327
|
+
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
328
|
+
msg.messageStubType = Types_1.WAMessageStubType[stubType];
|
|
329
|
+
const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
|
330
|
+
if (participants.length === 1 &&
|
|
331
|
+
(0, WABinary_1.areJidsSameUser)(participants[0], participant) &&
|
|
332
|
+
child.tag === 'remove') {
|
|
333
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
334
|
+
}
|
|
335
|
+
msg.messageStubParameters = participants;
|
|
336
|
+
break;
|
|
337
|
+
case 'subject':
|
|
338
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
339
|
+
msg.messageStubParameters = [child.attrs.subject];
|
|
340
|
+
break;
|
|
341
|
+
case 'description':
|
|
342
|
+
const description = (_d = (_c = (0, WABinary_1.getBinaryNodeChild)(child, 'body')) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.toString();
|
|
343
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
344
|
+
msg.messageStubParameters = description ? [description] : undefined;
|
|
345
|
+
break;
|
|
346
|
+
case 'announcement':
|
|
347
|
+
case 'not_announcement':
|
|
348
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
349
|
+
msg.messageStubParameters = [(child.tag === 'announcement') ? 'on' : 'off'];
|
|
350
|
+
break;
|
|
351
|
+
case 'locked':
|
|
352
|
+
case 'unlocked':
|
|
353
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
|
|
354
|
+
msg.messageStubParameters = [(child.tag === 'locked') ? 'on' : 'off'];
|
|
355
|
+
break;
|
|
356
|
+
case 'invite':
|
|
357
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
358
|
+
msg.messageStubParameters = [child.attrs.code];
|
|
359
|
+
break;
|
|
360
|
+
case 'member_add_mode':
|
|
361
|
+
const addMode = child.content;
|
|
362
|
+
if (addMode) {
|
|
363
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
364
|
+
msg.messageStubParameters = [addMode.toString()];
|
|
365
|
+
}
|
|
366
|
+
break;
|
|
367
|
+
case 'membership_approval_mode':
|
|
368
|
+
const approvalMode = (0, WABinary_1.getBinaryNodeChild)(child, 'group_join');
|
|
369
|
+
if (approvalMode) {
|
|
370
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
371
|
+
msg.messageStubParameters = [approvalMode.attrs.state];
|
|
372
|
+
}
|
|
373
|
+
break;
|
|
374
|
+
case 'created_membership_requests':
|
|
375
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
376
|
+
msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
|
|
377
|
+
break;
|
|
378
|
+
case 'revoked_membership_requests':
|
|
379
|
+
const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
|
|
380
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
381
|
+
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
382
|
+
break;
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const handleNewsletterNotification = (id, node) => {
|
|
388
|
+
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
389
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
|
|
390
|
+
const serverId = message.attrs.server_id;
|
|
391
|
+
const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
|
|
392
|
+
const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
|
|
393
|
+
if (reactionsList) {
|
|
394
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
|
|
395
|
+
if (reactions.length === 0) {
|
|
396
|
+
ev.emit('newsletter.reaction', { id, 'server_id': serverId, reaction: { removed: true } });
|
|
397
|
+
}
|
|
398
|
+
reactions.forEach(item => {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
ev.emit('newsletter.reaction', { id, 'server_id': serverId, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (viewsList.length) {
|
|
404
|
+
viewsList.forEach(item => {
|
|
405
|
+
ev.emit('newsletter.view', { id, 'server_id': serverId, count: +item.attrs.count });
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
const handleMexNewsletterNotification = (id, node) => {
|
|
410
|
+
var _a;
|
|
411
|
+
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
|
412
|
+
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
|
413
|
+
let contentPath;
|
|
414
|
+
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
|
415
|
+
let action;
|
|
416
|
+
if (operation === Types_1.MexOperations.PROMOTE) {
|
|
417
|
+
action = 'promote';
|
|
418
|
+
contentPath = content.data[Types_1.XWAPaths.PROMOTE];
|
|
419
|
+
}
|
|
420
|
+
if (operation === Types_1.MexOperations.DEMOTE) {
|
|
421
|
+
action = 'demote';
|
|
422
|
+
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
|
423
|
+
}
|
|
424
|
+
ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
|
|
425
|
+
}
|
|
426
|
+
if (operation === Types_1.MexOperations.UPDATE) {
|
|
427
|
+
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
|
428
|
+
ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
const processNotification = async (node) => {
|
|
432
|
+
var _a, _b;
|
|
433
|
+
const result = {};
|
|
434
|
+
const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
435
|
+
const nodeType = node.attrs.type;
|
|
436
|
+
const from = (0, WABinary_1.jidNormalizedUser)(node.attrs.from);
|
|
437
|
+
switch (nodeType) {
|
|
438
|
+
case 'privacy_token':
|
|
439
|
+
const tokenList = (0, WABinary_1.getBinaryNodeChildren)(child, 'token');
|
|
440
|
+
for (const { attrs, content } of tokenList) {
|
|
441
|
+
const jid = attrs.jid;
|
|
442
|
+
ev.emit('chats.update', [
|
|
443
|
+
{
|
|
444
|
+
id: jid,
|
|
445
|
+
tcToken: content
|
|
446
|
+
}
|
|
447
|
+
]);
|
|
448
|
+
logger.debug({ jid }, 'got privacy token update');
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
case 'newsletter':
|
|
452
|
+
handleNewsletterNotification(node.attrs.from, child);
|
|
453
|
+
break;
|
|
454
|
+
case 'mex':
|
|
455
|
+
handleMexNewsletterNotification(node.attrs.from, child);
|
|
456
|
+
break;
|
|
457
|
+
case 'w:gp2':
|
|
458
|
+
handleGroupNotification(node.attrs.participant, child, result);
|
|
459
|
+
break;
|
|
460
|
+
case 'mediaretry':
|
|
461
|
+
const event = (0, Utils_1.decodeMediaRetryNode)(node);
|
|
462
|
+
ev.emit('messages.media-update', [event]);
|
|
463
|
+
break;
|
|
464
|
+
case 'encrypt':
|
|
465
|
+
await handleEncryptNotification(node);
|
|
466
|
+
break;
|
|
467
|
+
case 'devices':
|
|
468
|
+
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
|
469
|
+
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
|
470
|
+
const deviceJids = devices.map(d => d.attrs.jid);
|
|
471
|
+
logger.info({ deviceJids }, 'got my own devices');
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
case 'server_sync':
|
|
475
|
+
const update = (0, WABinary_1.getBinaryNodeChild)(node, 'collection');
|
|
476
|
+
if (update) {
|
|
477
|
+
const name = update.attrs.name;
|
|
478
|
+
await resyncAppState([name], false);
|
|
479
|
+
}
|
|
480
|
+
break;
|
|
481
|
+
case 'picture':
|
|
482
|
+
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
483
|
+
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
484
|
+
ev.emit('contacts.update', [{
|
|
485
|
+
id: from || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
|
|
486
|
+
imgUrl: setPicture ? 'changed' : 'removed'
|
|
487
|
+
}]);
|
|
488
|
+
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
489
|
+
const node = setPicture || delPicture;
|
|
490
|
+
result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
|
|
491
|
+
if (setPicture) {
|
|
492
|
+
result.messageStubParameters = [setPicture.attrs.id];
|
|
493
|
+
}
|
|
494
|
+
result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
|
|
495
|
+
result.key = {
|
|
496
|
+
...result.key || {},
|
|
497
|
+
participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
case 'account_sync':
|
|
502
|
+
if (child.tag === 'disappearing_mode') {
|
|
503
|
+
const newDuration = +child.attrs.duration;
|
|
504
|
+
const timestamp = +child.attrs.t;
|
|
505
|
+
logger.info({ newDuration }, 'updated account disappearing mode');
|
|
506
|
+
ev.emit('creds.update', {
|
|
507
|
+
accountSettings: {
|
|
508
|
+
...authState.creds.accountSettings,
|
|
509
|
+
defaultDisappearingMode: {
|
|
510
|
+
ephemeralExpiration: newDuration,
|
|
511
|
+
ephemeralSettingTimestamp: timestamp,
|
|
512
|
+
},
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
else if (child.tag === 'blocklist') {
|
|
517
|
+
const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
|
|
518
|
+
for (const { attrs } of blocklists) {
|
|
519
|
+
const blocklist = [attrs.jid];
|
|
520
|
+
const type = (attrs.action === 'block') ? 'add' : 'remove';
|
|
521
|
+
ev.emit('blocklist.update', { blocklist, type });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
case 'link_code_companion_reg':
|
|
526
|
+
const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
|
|
527
|
+
const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
528
|
+
const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
529
|
+
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
530
|
+
const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
|
531
|
+
const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
532
|
+
const random = (0, crypto_1.randomBytes)(32);
|
|
533
|
+
const linkCodeSalt = (0, crypto_1.randomBytes)(32);
|
|
534
|
+
const linkCodePairingExpanded = await (0, Utils_1.hkdf)(companionSharedKey, 32, {
|
|
535
|
+
salt: linkCodeSalt,
|
|
536
|
+
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
537
|
+
});
|
|
538
|
+
const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
|
|
539
|
+
const encryptIv = (0, crypto_1.randomBytes)(12);
|
|
540
|
+
const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
541
|
+
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
542
|
+
const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
543
|
+
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
544
|
+
authState.creds.advSecretKey = (await (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
|
|
545
|
+
await query({
|
|
546
|
+
tag: 'iq',
|
|
547
|
+
attrs: {
|
|
548
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
549
|
+
type: 'set',
|
|
550
|
+
id: sock.generateMessageTag(),
|
|
551
|
+
xmlns: 'md'
|
|
552
|
+
},
|
|
553
|
+
content: [
|
|
554
|
+
{
|
|
555
|
+
tag: 'link_code_companion_reg',
|
|
556
|
+
attrs: {
|
|
557
|
+
jid: authState.creds.me.id,
|
|
558
|
+
stage: 'companion_finish',
|
|
559
|
+
},
|
|
560
|
+
content: [
|
|
561
|
+
{
|
|
562
|
+
tag: 'link_code_pairing_wrapped_key_bundle',
|
|
563
|
+
attrs: {},
|
|
564
|
+
content: encryptedPayload
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
tag: 'companion_identity_public',
|
|
568
|
+
attrs: {},
|
|
569
|
+
content: authState.creds.signedIdentityKey.public
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
tag: 'link_code_pairing_ref',
|
|
573
|
+
attrs: {},
|
|
574
|
+
content: ref
|
|
575
|
+
}
|
|
576
|
+
]
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
});
|
|
580
|
+
authState.creds.registered = true;
|
|
581
|
+
ev.emit('creds.update', authState.creds);
|
|
582
|
+
}
|
|
583
|
+
if (Object.keys(result).length) {
|
|
584
|
+
return result;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
async function decipherLinkPublicKey(data) {
|
|
588
|
+
const buffer = toRequiredBuffer(data);
|
|
589
|
+
const salt = buffer.slice(0, 32);
|
|
590
|
+
const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
591
|
+
const iv = buffer.slice(32, 48);
|
|
592
|
+
const payload = buffer.slice(48, 80);
|
|
593
|
+
return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
|
|
594
|
+
}
|
|
595
|
+
function toRequiredBuffer(data) {
|
|
596
|
+
if (data === undefined) {
|
|
597
|
+
throw new boom_1.Boom('Invalid buffer', { statusCode: 400 });
|
|
598
|
+
}
|
|
599
|
+
return data instanceof Buffer ? data : Buffer.from(data);
|
|
600
|
+
}
|
|
601
|
+
const willSendMessageAgain = (id, participant) => {
|
|
602
|
+
const key = `${id}:${participant}`;
|
|
603
|
+
const retryCount = msgRetryCache.get(key) || 0;
|
|
604
|
+
return retryCount < maxMsgRetryCount;
|
|
605
|
+
};
|
|
606
|
+
const updateSendMessageAgainCount = (id, participant) => {
|
|
607
|
+
const key = `${id}:${participant}`;
|
|
608
|
+
const newValue = (msgRetryCache.get(key) || 0) + 1;
|
|
609
|
+
msgRetryCache.set(key, newValue);
|
|
610
|
+
};
|
|
611
|
+
const sendMessagesAgain = async (key, ids, retryNode) => {
|
|
612
|
+
var _a;
|
|
613
|
+
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
|
614
|
+
const remoteJid = key.remoteJid;
|
|
615
|
+
const participant = key.participant || remoteJid;
|
|
616
|
+
const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
|
|
617
|
+
await assertSessions([participant], true);
|
|
618
|
+
if ((0, WABinary_1.isJidGroup)(remoteJid)) {
|
|
619
|
+
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
|
620
|
+
}
|
|
621
|
+
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
|
622
|
+
for (const [i, msg] of msgs.entries()) {
|
|
623
|
+
if (msg) {
|
|
624
|
+
updateSendMessageAgainCount(ids[i], participant);
|
|
625
|
+
const msgRelayOpts = { messageId: ids[i] };
|
|
626
|
+
if (sendToAll) {
|
|
627
|
+
msgRelayOpts.useUserDevicesCache = false;
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
msgRelayOpts.participant = {
|
|
631
|
+
jid: participant,
|
|
632
|
+
count: +retryNode.attrs.count
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
await relayMessage(key.remoteJid, msg, msgRelayOpts);
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
const handleReceipt = async (node) => {
|
|
643
|
+
var _a, _b;
|
|
644
|
+
const { attrs, content } = node;
|
|
645
|
+
const isLid = attrs.from.includes('lid');
|
|
646
|
+
const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
|
|
647
|
+
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
648
|
+
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
|
649
|
+
const key = {
|
|
650
|
+
remoteJid,
|
|
651
|
+
id: '',
|
|
652
|
+
fromMe,
|
|
653
|
+
participant: attrs.participant
|
|
654
|
+
};
|
|
655
|
+
if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
|
|
656
|
+
logger.debug({ remoteJid }, 'ignoring receipt from jid');
|
|
657
|
+
await sendMessageAck(node);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const ids = [attrs.id];
|
|
661
|
+
if (Array.isArray(content)) {
|
|
662
|
+
const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
|
|
663
|
+
ids.push(...items.map(i => i.attrs.id));
|
|
664
|
+
}
|
|
665
|
+
try {
|
|
666
|
+
await Promise.all([
|
|
667
|
+
processingMutex.mutex(async () => {
|
|
668
|
+
const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
|
|
669
|
+
if (typeof status !== 'undefined' &&
|
|
670
|
+
(status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK ||
|
|
671
|
+
!isNodeFromMe)) {
|
|
672
|
+
if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
|
|
673
|
+
if (attrs.participant) {
|
|
674
|
+
const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
675
|
+
ev.emit('message-receipt.update', ids.map(id => ({
|
|
676
|
+
key: { ...key, id },
|
|
677
|
+
receipt: {
|
|
678
|
+
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
|
679
|
+
[updateKey]: +attrs.t
|
|
680
|
+
}
|
|
681
|
+
})));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
ev.emit('messages.update', ids.map(id => ({
|
|
686
|
+
key: { ...key, id },
|
|
687
|
+
update: { status }
|
|
688
|
+
})));
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (attrs.type === 'retry') {
|
|
692
|
+
key.participant = key.participant || attrs.from;
|
|
693
|
+
const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
|
|
694
|
+
if (willSendMessageAgain(ids[0], key.participant)) {
|
|
695
|
+
if (key.fromMe) {
|
|
696
|
+
try {
|
|
697
|
+
logger.debug({ attrs, key }, 'recv retry request');
|
|
698
|
+
await sendMessagesAgain(key, ids, retryNode);
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
logger.info({ attrs, key }, 'recv retry for not fromMe message');
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
logger.info({ attrs, key }, 'will not send message again, as sent too many times');
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
})
|
|
713
|
+
]);
|
|
714
|
+
}
|
|
715
|
+
finally {
|
|
716
|
+
await sendMessageAck(node);
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
const handleNotification = async (node) => {
|
|
720
|
+
const remoteJid = node.attrs.from;
|
|
721
|
+
if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
|
|
722
|
+
logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
|
|
723
|
+
await sendMessageAck(node);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
try {
|
|
727
|
+
await Promise.all([
|
|
728
|
+
processingMutex.mutex(async () => {
|
|
729
|
+
var _a;
|
|
730
|
+
const msg = await processNotification(node);
|
|
731
|
+
if (msg) {
|
|
732
|
+
const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
733
|
+
msg.key = {
|
|
734
|
+
remoteJid,
|
|
735
|
+
fromMe,
|
|
736
|
+
participant: node.attrs.participant,
|
|
737
|
+
id: node.attrs.id,
|
|
738
|
+
...(msg.key || {})
|
|
739
|
+
};
|
|
740
|
+
(_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
|
|
741
|
+
msg.messageTimestamp = +node.attrs.t;
|
|
742
|
+
const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
|
|
743
|
+
await upsertMessage(fullMsg, 'append');
|
|
744
|
+
}
|
|
745
|
+
})
|
|
746
|
+
]);
|
|
747
|
+
}
|
|
748
|
+
finally {
|
|
749
|
+
await sendMessageAck(node);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
const handleMessage = async (node) => {
|
|
753
|
+
var _a, _b, _c;
|
|
754
|
+
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
755
|
+
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
756
|
+
await sendMessageAck(node);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
760
|
+
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
761
|
+
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
|
762
|
+
await sendMessageAck(node);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
let response;
|
|
766
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
|
|
767
|
+
await sendMessageAck(node);
|
|
768
|
+
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
769
|
+
response = await requestPlaceholderResend(key);
|
|
770
|
+
if (response === 'RESOLVED') {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
logger.debug('received unavailable message, acked and requested resend from phone');
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
if (placeholderResendCache.get(node.attrs.id)) {
|
|
777
|
+
placeholderResendCache.del(node.attrs.id);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
781
|
+
if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
782
|
+
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
783
|
+
}
|
|
784
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
|
|
785
|
+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
786
|
+
}
|
|
787
|
+
try {
|
|
788
|
+
await Promise.all([
|
|
789
|
+
processingMutex.mutex(async () => {
|
|
790
|
+
var _a, _b, _c, _d, _e, _f;
|
|
791
|
+
await decrypt();
|
|
792
|
+
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
793
|
+
if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
|
|
794
|
+
return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
|
|
795
|
+
}
|
|
796
|
+
retryMutex.mutex(async () => {
|
|
797
|
+
if (ws.isOpen) {
|
|
798
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
802
|
+
await sendRetryRequest(node, !encNode);
|
|
803
|
+
if (retryRequestDelayMs) {
|
|
804
|
+
await (0, Utils_1.delay)(retryRequestDelayMs);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
logger.debug({ node }, 'connection closed, ignoring retry req');
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
let type = undefined;
|
|
814
|
+
if ((_b = msg.key.participant) === null || _b === void 0 ? void 0 : _b.endsWith('@lid')) {
|
|
815
|
+
msg.key.participant = node.attrs.participant_pn || authState.creds.me.id;
|
|
816
|
+
}
|
|
817
|
+
if ((0, WABinary_1.isJidGroup)(msg.key.remoteJid) && ((_f = (_e = (_d = (_c = msg.message) === null || _c === void 0 ? void 0 : _c.extendedTextMessage) === null || _d === void 0 ? void 0 : _d.contextInfo) === null || _e === void 0 ? void 0 : _e.participant) === null || _f === void 0 ? void 0 : _f.endsWith('@lid'))) {
|
|
818
|
+
if (msg.message.extendedTextMessage.contextInfo) {
|
|
819
|
+
const metadata = await groupMetadata(msg.key.remoteJid);
|
|
820
|
+
const sender = msg.message.extendedTextMessage.contextInfo.participant;
|
|
821
|
+
const found = metadata.participants.find(p => p.id === sender);
|
|
822
|
+
msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || sender;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
|
|
826
|
+
msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
|
|
827
|
+
}
|
|
828
|
+
let participant = msg.key.participant;
|
|
829
|
+
if (category === 'peer') {
|
|
830
|
+
type = 'peer_msg';
|
|
831
|
+
}
|
|
832
|
+
else if (msg.key.fromMe) {
|
|
833
|
+
type = 'sender';
|
|
834
|
+
if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
|
|
835
|
+
participant = author;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
else if (!sendActiveReceipts) {
|
|
839
|
+
type = 'inactive';
|
|
840
|
+
}
|
|
841
|
+
await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
|
|
842
|
+
const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
843
|
+
if (isAnyHistoryMsg) {
|
|
844
|
+
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
845
|
+
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
(0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
|
|
849
|
+
await sendMessageAck(node);
|
|
850
|
+
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
851
|
+
})
|
|
852
|
+
]);
|
|
853
|
+
}
|
|
854
|
+
catch (error) {
|
|
855
|
+
logger.error({ error, node }, 'error in handling message');
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
859
|
+
var _a;
|
|
860
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
861
|
+
throw new boom_1.Boom('Not authenticated');
|
|
862
|
+
}
|
|
863
|
+
const pdoMessage = {
|
|
864
|
+
historySyncOnDemandRequest: {
|
|
865
|
+
chatJid: oldestMsgKey.remoteJid,
|
|
866
|
+
oldestMsgFromMe: oldestMsgKey.fromMe,
|
|
867
|
+
oldestMsgId: oldestMsgKey.id,
|
|
868
|
+
oldestMsgTimestampMs: oldestMsgTimestamp,
|
|
869
|
+
onDemandMsgCount: count
|
|
870
|
+
},
|
|
871
|
+
peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
872
|
+
};
|
|
873
|
+
return sendPeerDataOperationMessage(pdoMessage);
|
|
874
|
+
};
|
|
875
|
+
const requestPlaceholderResend = async (messageKey) => {
|
|
876
|
+
var _a;
|
|
877
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
878
|
+
throw new boom_1.Boom('Not authenticated');
|
|
879
|
+
}
|
|
880
|
+
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
881
|
+
logger.debug({ messageKey }, 'already requested resend');
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
placeholderResendCache.set(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id, true);
|
|
886
|
+
}
|
|
887
|
+
await (0, Utils_1.delay)(5000);
|
|
888
|
+
if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
889
|
+
logger.debug({ messageKey }, 'message received while resend requested');
|
|
890
|
+
return 'RESOLVED';
|
|
891
|
+
}
|
|
892
|
+
const pdoMessage = {
|
|
893
|
+
placeholderMessageResendRequest: [{
|
|
894
|
+
messageKey
|
|
895
|
+
}],
|
|
896
|
+
peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
897
|
+
};
|
|
898
|
+
setTimeout(() => {
|
|
899
|
+
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
900
|
+
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
|
|
901
|
+
placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
|
|
902
|
+
}
|
|
903
|
+
}, 15000);
|
|
904
|
+
return sendPeerDataOperationMessage(pdoMessage);
|
|
905
|
+
};
|
|
906
|
+
const handleCall = async (node) => {
|
|
907
|
+
const { attrs } = node;
|
|
908
|
+
const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
909
|
+
const callId = infoChild.attrs['call-id'];
|
|
910
|
+
const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
|
|
911
|
+
const status = (0, Utils_1.getCallStatusFromNode)(infoChild);
|
|
912
|
+
let groupJid = null;
|
|
913
|
+
let chatId = attrs.from;
|
|
914
|
+
if (status === 'offer') {
|
|
915
|
+
const isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
916
|
+
if (isGroup) {
|
|
917
|
+
groupJid = infoChild.attrs['group-jid'] || attrs.from;
|
|
918
|
+
if (groupJid && groupJid.includes('@lid')) {
|
|
919
|
+
try {
|
|
920
|
+
const metadata = await groupMetadata(groupJid);
|
|
921
|
+
groupJid = metadata.id;
|
|
922
|
+
chatId = metadata.id;
|
|
923
|
+
} catch(e) {
|
|
924
|
+
logger.warn({ groupJid }, 'Failed to convert LID to JID');
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
const call = {
|
|
930
|
+
chatId: chatId,
|
|
931
|
+
from,
|
|
932
|
+
id: callId,
|
|
933
|
+
date: new Date(+attrs.t * 1000),
|
|
934
|
+
offline: !!attrs.offline,
|
|
935
|
+
status,
|
|
936
|
+
isVideo: false,
|
|
937
|
+
isGroup: false,
|
|
938
|
+
groupJid: null
|
|
939
|
+
};
|
|
940
|
+
if (status === 'offer') {
|
|
941
|
+
call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
|
|
942
|
+
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
943
|
+
call.groupJid = groupJid;
|
|
944
|
+
callOfferCache.set(call.id, call);
|
|
945
|
+
}
|
|
946
|
+
const existingCall = callOfferCache.get(call.id);
|
|
947
|
+
if (existingCall) {
|
|
948
|
+
call.isVideo = existingCall.isVideo;
|
|
949
|
+
call.isGroup = existingCall.isGroup;
|
|
950
|
+
call.groupJid = existingCall.groupJid;
|
|
951
|
+
}
|
|
952
|
+
if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
|
|
953
|
+
callOfferCache.del(call.id);
|
|
954
|
+
}
|
|
955
|
+
ev.emit('call', [call]);
|
|
956
|
+
await sendMessageAck(node);
|
|
957
|
+
};
|
|
958
|
+
const handleBadAck = async ({ attrs }) => {
|
|
959
|
+
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
|
960
|
+
if (attrs.phash) {
|
|
961
|
+
logger.info({ attrs }, 'received phash in ack, resending message...');
|
|
962
|
+
const cacheKey = `${key.remoteJid}:${key.id}`;
|
|
963
|
+
if ((msgRetryCache.get(cacheKey) || 0) >= maxMsgRetryCount) {
|
|
964
|
+
logger.warn({ attrs }, 'reached max retry count, not sending message again');
|
|
965
|
+
msgRetryCache.del(cacheKey);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
const retryCount = msgRetryCache.get(cacheKey) || 0;
|
|
969
|
+
const msg = await getMessage(key);
|
|
970
|
+
if (msg) {
|
|
971
|
+
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
|
972
|
+
msgRetryCache.set(cacheKey, retryCount + 1);
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if (attrs.error) {
|
|
979
|
+
logger.warn({ attrs }, 'received error in ack');
|
|
980
|
+
ev.emit('messages.update', [
|
|
981
|
+
{
|
|
982
|
+
key,
|
|
983
|
+
update: {
|
|
984
|
+
status: Types_1.WAMessageStatus.ERROR,
|
|
985
|
+
messageStubParameters: [
|
|
986
|
+
attrs.error
|
|
987
|
+
]
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
]);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
const processNodeWithBuffer = async (node, identifier, exec) => {
|
|
994
|
+
ev.buffer();
|
|
995
|
+
await execTask();
|
|
996
|
+
ev.flush();
|
|
997
|
+
function execTask() {
|
|
998
|
+
return exec(node, false)
|
|
999
|
+
.catch(err => onUnexpectedError(err, identifier));
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
const makeOfflineNodeProcessor = () => {
|
|
1003
|
+
const nodeProcessorMap = new Map([
|
|
1004
|
+
['message', handleMessage],
|
|
1005
|
+
['call', handleCall],
|
|
1006
|
+
['receipt', handleReceipt],
|
|
1007
|
+
['notification', handleNotification]
|
|
1008
|
+
]);
|
|
1009
|
+
const nodes = [];
|
|
1010
|
+
let isProcessing = false;
|
|
1011
|
+
const enqueue = (type, node) => {
|
|
1012
|
+
nodes.push({ type, node });
|
|
1013
|
+
if (isProcessing) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
isProcessing = true;
|
|
1017
|
+
const promise = async () => {
|
|
1018
|
+
while (nodes.length && ws.isOpen) {
|
|
1019
|
+
const { type, node } = nodes.shift();
|
|
1020
|
+
const nodeProcessor = nodeProcessorMap.get(type);
|
|
1021
|
+
if (!nodeProcessor) {
|
|
1022
|
+
onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
await nodeProcessor(node);
|
|
1026
|
+
}
|
|
1027
|
+
isProcessing = false;
|
|
1028
|
+
};
|
|
1029
|
+
promise().catch(error => onUnexpectedError(error, 'processing offline nodes'));
|
|
1030
|
+
};
|
|
1031
|
+
return { enqueue };
|
|
1032
|
+
};
|
|
1033
|
+
const offlineNodeProcessor = makeOfflineNodeProcessor();
|
|
1034
|
+
const processNode = (type, node, identifier, exec) => {
|
|
1035
|
+
const isOffline = !!node.attrs.offline;
|
|
1036
|
+
if (isOffline) {
|
|
1037
|
+
offlineNodeProcessor.enqueue(type, node);
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
processNodeWithBuffer(node, identifier, exec);
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
ws.on('CB:message', (node) => {
|
|
1044
|
+
processNode('message', node, 'processing message', handleMessage);
|
|
1045
|
+
});
|
|
1046
|
+
ws.on('CB:call', async (node) => {
|
|
1047
|
+
processNode('call', node, 'handling call', handleCall);
|
|
1048
|
+
});
|
|
1049
|
+
ws.on('CB:receipt', node => {
|
|
1050
|
+
processNode('receipt', node, 'handling receipt', handleReceipt);
|
|
1051
|
+
});
|
|
1052
|
+
ws.on('CB:notification', async (node) => {
|
|
1053
|
+
processNode('notification', node, 'handling notification', handleNotification);
|
|
1054
|
+
});
|
|
1055
|
+
ws.on('CB:ack,class:message', (node) => {
|
|
1056
|
+
handleBadAck(node)
|
|
1057
|
+
.catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
1058
|
+
});
|
|
1059
|
+
ev.on('call', ([call]) => {
|
|
1060
|
+
if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
|
|
1061
|
+
let remoteJid = call.chatId;
|
|
1062
|
+
if (call.isGroup && call.groupJid) {
|
|
1063
|
+
remoteJid = call.groupJid;
|
|
1064
|
+
}
|
|
1065
|
+
const msg = {
|
|
1066
|
+
key: {
|
|
1067
|
+
remoteJid: remoteJid,
|
|
1068
|
+
id: call.id,
|
|
1069
|
+
fromMe: false
|
|
1070
|
+
},
|
|
1071
|
+
messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date),
|
|
1072
|
+
};
|
|
1073
|
+
if (call.status === 'timeout') {
|
|
1074
|
+
if (call.isGroup) {
|
|
1075
|
+
msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
msg.message = { call: { callKey: Buffer.from(call.id) } };
|
|
1083
|
+
}
|
|
1084
|
+
const protoMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
|
|
1085
|
+
upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
ev.on('connection.update', ({ isOnline }) => {
|
|
1089
|
+
if (typeof isOnline !== 'undefined') {
|
|
1090
|
+
sendActiveReceipts = isOnline;
|
|
1091
|
+
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
return {
|
|
1095
|
+
...sock,
|
|
1096
|
+
sendMessageAck,
|
|
1097
|
+
sendRetryRequest,
|
|
1098
|
+
rejectCall,
|
|
1099
|
+
offerCall,
|
|
1100
|
+
fetchMessageHistory,
|
|
1101
|
+
requestPlaceholderResend,
|
|
1102
|
+
};
|
|
1103
1103
|
};
|
|
1104
1104
|
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|