@realvare/based 2.5.2 → 2.5.6
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 +1288 -829
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/messages-send.js +1406 -901
- package/lib/Socket/socket.js +51 -3
- package/lib/Utils/cache-manager.js +73 -0
- package/lib/Utils/messages.js +1338 -1290
- package/lib/Utils/performance-config.d.ts +64 -60
- package/lib/Utils/performance-config.js +154 -150
- package/lib/Utils/retry.js +66 -66
- package/lib/WABinary/decode.js +24 -10
- package/lib/WABinary/encode.js +15 -1
- package/lib/WABinary/jid-utils.js +217 -140
- package/lib/index.js +3 -4
- package/package.json +111 -111
- package/lib/WABinary/jid-utils.js.bak +0 -83
package/README.MD
CHANGED
|
@@ -1,829 +1,1288 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
const sock = makeWASocket({
|
|
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
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
<img src="https://i.gifer.com/YdBN.gif" width="200">
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
<br>
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@realvare/based?style=for-the-badge&color=8a2be2&labelColor=2d1b69" alt="Versione NPM">
|
|
10
|
+
<img src="https://img.shields.io/npm/dm/@realvare/based?style=for-the-badge&color=8a2be2&labelColor=2d1b69" alt="Download NPM">
|
|
11
|
+
<img src="https://img.shields.io/badge/Licenza-MIT-8a2be2.svg?style=for-the-badge&labelColor=2d1b69" alt="Licenza MIT">
|
|
12
|
+
<img src="https://img.shields.io/github/stars/realvare/based?style=for-the-badge&color=8a2be2&labelColor=2d1b69" alt="GitHub Stelle">
|
|
13
|
+
<img src="https://img.shields.io/github/forks/realvare/based?style=for-the-badge&color=8a2be2&labelColor=2d1b69" alt="GitHub Forks">
|
|
14
|
+
</p>
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="#-caratteristiche-principali"><img src="https://img.shields.io/badge/_Caratteristiche-8a2be2?style=flat-square&logo=github&logoColor=white"/></a>
|
|
17
|
+
<a href="#-installazione"><img src="https://img.shields.io/badge/_Installazione-8a2be2?style=flat-square&logo=npm&logoColor=white"/></a>
|
|
18
|
+
<a href="#-guida-rapida"><img src="https://img.shields.io/badge/_Guida_Rapida-8a2be2?style=flat-square&logo=rocket&logoColor=white"/></a>
|
|
19
|
+
<a href="#-documentazione-api"><img src="https://img.shields.io/badge/_Documentazione_API-8a2be2?style=flat-square&logo=book&logoColor=white"/></a>
|
|
20
|
+
<a href="#-supporto-e-community"><img src="https://img.shields.io/badge/_Supporto-8a2be2?style=flat-square&logo=teamspeak&logoColor=white"/></a>
|
|
21
|
+
</p>
|
|
22
|
+
<img src="https://readme-typing-svg.herokuapp.com?font=Fira+Code&weight=600&size=20&duration=4000&pause=2500&color=8A2BE2¢er=true&vCenter=true&width=800&lines=💜+Una+libreria+WhatsApp+Web+API+moderna%2C+potente+e+veloce;🔄+Con+supporto+per+LID%2FJID+e+multi-dispositivo;">
|
|
23
|
+
|
|
24
|
+
----
|
|
25
|
+
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
## ✨ Caratteristiche Principali
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<img src="https://readme-typing-svg.herokuapp.com?font=Fira+Code&weight=600&size=18&duration=2500&pause=2500&color=8A2BE2¢er=true&vCenter=true&width=600&lines=🚀+Potente+e+Intuitiva;🔧+Basata+su+Baileys+con+Miglioramenti" alt="Features">
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<br>
|
|
35
|
+
|
|
36
|
+
Questa libreria, basata su Baileys con miglioramenti specifici, offre un'API intuitiva per interagire con WhatsApp Web. Ecco un riassunto delle funzionalità chiave:
|
|
37
|
+
|
|
38
|
+
<table align="center">
|
|
39
|
+
<tr>
|
|
40
|
+
<td align="center" width="25%">
|
|
41
|
+
<h3>🔄 Core Features</h3>
|
|
42
|
+
<p>• Mappatura intelligente LID/JID<br>• Supporto multi-dispositivo<br>• Crittografia E2E Signal<br>• TypeScript moderno</p>
|
|
43
|
+
</td>
|
|
44
|
+
<td align="center" width="25%">
|
|
45
|
+
<h3>💬 Messaggi</h3>
|
|
46
|
+
<p>• Testo, media, interattivi<br>• Bottoni, liste, carousel<br>• Album, poll, reazioni<br>• Template avanzati</p>
|
|
47
|
+
</td>
|
|
48
|
+
<td align="center" width="25%">
|
|
49
|
+
<h3>🛠️ Developer</h3>
|
|
50
|
+
<p>• Eventi real-time<br>• TypeScript completo<br>• Documentazione estesa<br>• API estendibili</p>
|
|
51
|
+
</td>
|
|
52
|
+
<td align="center" width="25%">
|
|
53
|
+
<h3>⚡ Performance</h3>
|
|
54
|
+
<p>• Riconnessione intelligente<br>• Cache avanzata TTL<br>• Monitoraggio prestazioni</p>
|
|
55
|
+
</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</table>
|
|
58
|
+
<p align="center">
|
|
59
|
+
<img src="https://64.media.tumblr.com/13bc9e3c3b332dfc008cb4b9e8571558/2a577b39b15547dc-cc/s400x600/3db051b3117b695a61ad8e0b686f2774b971d210.gifv" width="800">
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## 🚀 Guida Rapida
|
|
63
|
+
|
|
64
|
+
- Questa sezione include esempi base per l'autenticazione e la gestione delle connessioni.
|
|
65
|
+
|
|
66
|
+
### Esempio Base - Avvio Bot
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import makeWASocket, { DisconnectReason, useMultiFileAuthState, getPerformanceConfig, setPerformanceConfig } from '@realvare/based';
|
|
70
|
+
|
|
71
|
+
// Configura performance e cache
|
|
72
|
+
setPerformanceConfig({
|
|
73
|
+
performance: {
|
|
74
|
+
enableCache: true,
|
|
75
|
+
enableMetrics: true
|
|
76
|
+
},
|
|
77
|
+
debug: {
|
|
78
|
+
enableLidLogging: true,
|
|
79
|
+
logLevel: 'info'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
async function startBot() {
|
|
84
|
+
// 🔐 Setup autenticazione multi-file per sessioni persistenti
|
|
85
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');
|
|
86
|
+
|
|
87
|
+
// 🌐 Creazione del socket con configurazione base
|
|
88
|
+
const sock = makeWASocket({
|
|
89
|
+
auth: state,
|
|
90
|
+
printQRInTerminal: true,
|
|
91
|
+
logger: console,
|
|
92
|
+
browser: ['VareBot', 'Chrome', '4.0.0'],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Sistema di riconnessione migliorato
|
|
96
|
+
let reconnectAttempts = 0;
|
|
97
|
+
const config = getPerformanceConfig();
|
|
98
|
+
|
|
99
|
+
sock.ev.on('connection.update', (update) => {
|
|
100
|
+
const { connection, lastDisconnect } = update;
|
|
101
|
+
|
|
102
|
+
if (connection === 'close') {
|
|
103
|
+
const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
104
|
+
|
|
105
|
+
if (shouldReconnect) {
|
|
106
|
+
reconnectAttempts++;
|
|
107
|
+
const delay = Math.min(
|
|
108
|
+
config.performance.retryDelay * Math.pow(
|
|
109
|
+
config.performance.retryBackoffMultiplier,
|
|
110
|
+
reconnectAttempts - 1
|
|
111
|
+
),
|
|
112
|
+
config.performance.maxRetryDelay
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
console.log(`🔄 Tentativo di riconnessione ${reconnectAttempts}/${config.performance.maxRetries} tra ${delay}ms`);
|
|
116
|
+
|
|
117
|
+
if (reconnectAttempts <= config.performance.maxRetries) {
|
|
118
|
+
setTimeout(startBot, delay);
|
|
119
|
+
} else {
|
|
120
|
+
console.log('❌ Numero massimo di tentativi di riconnessione raggiunto');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else if (connection === 'open') {
|
|
124
|
+
console.log('🟢 Connesso con successo!');
|
|
125
|
+
reconnectAttempts = 0;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
sock.ev.on('creds.update', saveCreds);
|
|
130
|
+
}startBot().catch(console.error);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Esempio Anti-Ban - Configurazione consigliata per Evitare Ban
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import makeWASocket, { DisconnectReason, useMultiFileAuthState, getPerformanceConfig, setPerformanceConfig, getSenderLid, validateJid } from '@realvare/based';
|
|
137
|
+
|
|
138
|
+
// Configurazione anti-ban per ridurre rischi ban da acks impropri
|
|
139
|
+
setPerformanceConfig({
|
|
140
|
+
performance: {
|
|
141
|
+
enableCache: true, // Abilita cache TTL per ridurre chiamate API
|
|
142
|
+
enableMetrics: true, // Monitora performance per evitare sovraccarico
|
|
143
|
+
batchSize: 50, // Elabora messaggi in batch più piccoli per simulare velocità umana
|
|
144
|
+
maxRetries: 5, // Limita tentativi retry per evitare comportamento aggressivo
|
|
145
|
+
retryDelay: 5000, // Ritardo base in ms per riconnessioni
|
|
146
|
+
retryBackoffMultiplier: 1.5,// Backoff esponenziale per spaziare retry
|
|
147
|
+
maxRetryDelay: 60000, // Ritardo massimo per evitare riconnessioni rapide
|
|
148
|
+
maxMsgRetryCount: 3 // Limita tentativi rispedizione messaggi
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
async function startBot() {
|
|
153
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');
|
|
154
|
+
|
|
155
|
+
const sock = makeWASocket({
|
|
156
|
+
auth: state,
|
|
157
|
+
printQRInTerminal: true,
|
|
158
|
+
logger: console,
|
|
159
|
+
browser: ['YourBotName', 'Chrome', '4.0.0'], // Personalizza fingerprint browser
|
|
160
|
+
markOnlineOnConnect: false, // Cruciale: Previene apparire sempre online, riduce rischio ban
|
|
161
|
+
syncFullHistory: false // Evita sync dati non necessari che potrebbero segnalare attività
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
let reconnectAttempts = 0;
|
|
165
|
+
const config = getPerformanceConfig();
|
|
166
|
+
|
|
167
|
+
sock.ev.on('connection.update', (update) => {
|
|
168
|
+
const { connection, lastDisconnect } = update;
|
|
169
|
+
|
|
170
|
+
if (connection === 'close') {
|
|
171
|
+
const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
|
|
172
|
+
|
|
173
|
+
if (shouldReconnect) {
|
|
174
|
+
reconnectAttempts++;
|
|
175
|
+
const delay = Math.min(
|
|
176
|
+
config.performance.retryDelay * Math.pow(
|
|
177
|
+
config.performance.retryBackoffMultiplier,
|
|
178
|
+
reconnectAttempts - 1
|
|
179
|
+
),
|
|
180
|
+
config.performance.maxRetryDelay
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
console.log(`Reconnecting attempt ${reconnectAttempts}/${config.performance.maxRetries} in ${delay}ms`);
|
|
184
|
+
|
|
185
|
+
if (reconnectAttempts <= config.performance.maxRetries) {
|
|
186
|
+
setTimeout(startBot, delay);
|
|
187
|
+
} else {
|
|
188
|
+
console.log('Max reconnection attempts reached');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} else if (connection === 'open') {
|
|
192
|
+
console.log('Connected successfully!');
|
|
193
|
+
reconnectAttempts = 0;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Monitora acks tramite aggiornamenti messaggi per garantire gestione corretta
|
|
198
|
+
sock.ev.on('messages.update', (updates) => {
|
|
199
|
+
for (const update of updates) {
|
|
200
|
+
if (update.update.status) {
|
|
201
|
+
console.log(`Message ${update.key.id} status: ${update.update.status}`); // Traccia acks (1=sent, 2=delivered, 3=read)
|
|
202
|
+
// Aggiungi logica personalizzata se necessaria, ma evita override predefiniti per prevenire detection
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Utilità LID/JID avanzate per stabilità acks
|
|
208
|
+
sock.ev.on('messages.upsert', ({ messages }) => {
|
|
209
|
+
for (const msg of messages) {
|
|
210
|
+
const info = getSenderLid(msg);
|
|
211
|
+
const validation = validateJid(info.jid);
|
|
212
|
+
if (validation.isValid) {
|
|
213
|
+
// Elabora e ack in sicurezza
|
|
214
|
+
console.log(`Valid JID: ${info.jid}, LID: ${info.lid}`);
|
|
215
|
+
} else {
|
|
216
|
+
console.warn(`Invalid JID detected: ${info.jid}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
sock.ev.on('creds.update', saveCreds);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
startBot().catch(console.error);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## 📊 Gestione Avanzata Cache
|
|
228
|
+
|
|
229
|
+
La libreria ora include un sistema di cache avanzato con gestione automatica della memoria e TTL configurabile:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { CacheManager } from 'based/lib/Utils/cache-manager';
|
|
233
|
+
|
|
234
|
+
// Esempio di utilizzo della cache
|
|
235
|
+
const cache = CacheManager;
|
|
236
|
+
|
|
237
|
+
// Salva un valore nella cache
|
|
238
|
+
cache.set('lidCache', 'chiave', 'valore', 300); // TTL di 300 secondi
|
|
239
|
+
|
|
240
|
+
// Recupera un valore
|
|
241
|
+
const valore = cache.get('lidCache', 'chiave');
|
|
242
|
+
|
|
243
|
+
// Ottieni statistiche della cache
|
|
244
|
+
const stats = cache.getStats('lidCache');
|
|
245
|
+
console.log('Statistiche cache:', stats);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Configurazione Cache Avanzata
|
|
249
|
+
|
|
250
|
+
La cache può essere configurata con varie opzioni per ottimizzare le prestazioni:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
setPerformanceConfig({
|
|
254
|
+
cache: {
|
|
255
|
+
lidCache: {
|
|
256
|
+
ttl: 5 * 60 * 1000, // Tempo di vita delle entries
|
|
257
|
+
maxSize: 10000, // Numero massimo di entries
|
|
258
|
+
cleanupInterval: 2 * 60 * 1000 // Intervallo pulizia
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
performance: {
|
|
262
|
+
memoryThreshold: 0.85 // Soglia per pulizia automatica
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
## 🔍 Risoluzione Problemi
|
|
267
|
+
|
|
268
|
+
### Problemi di Connessione
|
|
269
|
+
- La libreria ora implementa un sistema di retry con backoff esponenziale
|
|
270
|
+
- Monitoraggio automatico dello stato della connessione
|
|
271
|
+
- Tentativi di riconnessione configurabili
|
|
272
|
+
|
|
273
|
+
### Gestione Memoria
|
|
274
|
+
- Monitoraggio automatico dell'uso della memoria
|
|
275
|
+
- Pulizia cache automatica quando necessario
|
|
276
|
+
- TTL configurabile per ogni tipo di cache
|
|
277
|
+
|
|
278
|
+
### Logging Avanzato
|
|
279
|
+
```typescript
|
|
280
|
+
setPerformanceConfig({
|
|
281
|
+
debug: {
|
|
282
|
+
enableLidLogging: true,
|
|
283
|
+
enablePerformanceLogging: true,
|
|
284
|
+
logLevel: 'debug'
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Gestione Messaggi Base con LID/JID
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import makeWASocket, { getSenderLid, toJid, getCacheStats, validateJid, Logger } from '@realvare/based';
|
|
293
|
+
|
|
294
|
+
// ... (codice di creazione sock qui)
|
|
295
|
+
|
|
296
|
+
conn.ev.on('messages.upsert', ({ messages }) => {
|
|
297
|
+
for (const msg of messages) {
|
|
298
|
+
// 🔍 Estrai LID del mittente con validazione
|
|
299
|
+
const info = getSenderLid(msg);
|
|
300
|
+
|
|
301
|
+
// ✅ Valida JID prima di usarlo
|
|
302
|
+
const validation = validateJid(info.jid);
|
|
303
|
+
if (!validation.isValid) {
|
|
304
|
+
Logger.error('JID non valido:', validation.error);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const jid = toJid(info.lid); // Normalizza in JID
|
|
309
|
+
|
|
310
|
+
Logger.info('💬 Messaggio da:', jid, 'Valid:', info.isValid);
|
|
311
|
+
console.log('📝 Contenuto:', msg.message?.conversation);
|
|
312
|
+
|
|
313
|
+
// Rispondi automaticamente solo se valido
|
|
314
|
+
if (info.isValid) {
|
|
315
|
+
conn.sendMessage(jid, { text: 'Messaggio ricevuto!' });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 📊 Monitora performance cache
|
|
320
|
+
const stats = getCacheStats();
|
|
321
|
+
Logger.performance('Cache stats:', stats);
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## 📚 Documentazione API
|
|
328
|
+
|
|
329
|
+
Questa sezione espande i metodi principali, con esempi dettagliati e parametri. Tutti i metodi sono tipizzati in TypeScript per un'esperienza di sviluppo sicura.
|
|
330
|
+
|
|
331
|
+
### 🏗️ Metodi Fondamentali
|
|
332
|
+
|
|
333
|
+
<details>
|
|
334
|
+
<summary><strong>📡 makeWASocket(config)</strong></summary>
|
|
335
|
+
|
|
336
|
+
Crea un'istanza del socket WhatsApp. È il punto di ingresso principale.
|
|
337
|
+
|
|
338
|
+
**Parametri:**
|
|
339
|
+
- `config`: Oggetto con opzioni (vedi sezione Configurazione Avanzata per dettagli completi).
|
|
340
|
+
|
|
341
|
+
**Restituisce:** Istanza del socket con metodi come `sendMessage` e `ev` per eventi.
|
|
342
|
+
|
|
343
|
+
**Esempio:**
|
|
344
|
+
```typescript
|
|
345
|
+
const sock = makeWASocket({
|
|
346
|
+
auth: state,
|
|
347
|
+
printQRInTerminal: true,
|
|
348
|
+
logger: console,
|
|
349
|
+
browser: ['Varebot', 'Chrome', '4.0.0'],
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
</details>
|
|
353
|
+
<details>
|
|
354
|
+
<summary><strong>🔐 useMultiFileAuthState(folder)</strong></summary>
|
|
355
|
+
|
|
356
|
+
Gestisce l'autenticazione persistente salvando credenziali in file multipli per sicurezza.
|
|
357
|
+
|
|
358
|
+
**Parametri:**
|
|
359
|
+
- `folder`: Stringa, path della cartella per i file di auth (es. 'auth_info').
|
|
360
|
+
|
|
361
|
+
**Restituisce:**
|
|
362
|
+
- `{ state, saveCreds }`: Stato autenticazione e funzione per salvare aggiornamenti.
|
|
363
|
+
|
|
364
|
+
**Esempio:**
|
|
365
|
+
```typescript
|
|
366
|
+
const { state, saveCreds } = await useMultiFileAuthState('auth_info');
|
|
367
|
+
conn.ev.on('creds.update', saveCreds); // Integra nel socket
|
|
368
|
+
```
|
|
369
|
+
</details>
|
|
370
|
+
|
|
371
|
+
<details>
|
|
372
|
+
<summary><strong>🔄 getSenderLid(message) & toJid(lid)</strong></summary>
|
|
373
|
+
|
|
374
|
+
Utilità per gestire LID/JID, risolvendo problemi comuni in gruppi e multi-dispositivo.
|
|
375
|
+
|
|
376
|
+
**getSenderLid(message):**
|
|
377
|
+
- Estrae LID dal messaggio.
|
|
378
|
+
- Restituisce: Oggetto con `lid` e altre info mittente.
|
|
379
|
+
|
|
380
|
+
**toJid(lid):**
|
|
381
|
+
- Converte LID in JID normalizzato (es. prende pn e aggiunge `@s.whatsapp.net`).
|
|
382
|
+
|
|
383
|
+
**Esempio:**
|
|
384
|
+
```typescript
|
|
385
|
+
const info = getSenderLid(msg);
|
|
386
|
+
const jid = toJid(info.lid);
|
|
387
|
+
conn.sendMessage(jid, { text: 'we ridin porsches in the rain' });
|
|
388
|
+
```
|
|
389
|
+
</details>
|
|
390
|
+
|
|
391
|
+
<details>
|
|
392
|
+
<summary><strong>📤 sendMessage(jid, content, options)</strong></summary>
|
|
393
|
+
|
|
394
|
+
Invia messaggi di vari tipi. Supporta testo, media, interattivi.
|
|
395
|
+
|
|
396
|
+
**Parametri:**
|
|
397
|
+
- `jid`: Stringa JID del destinatario.
|
|
398
|
+
- `content`: Oggetto messaggio (es. { text: 'finche vedo tutto violaviola' }).
|
|
399
|
+
- `options`: Opzionale, include `quoted`, `mentions`, ecc.
|
|
400
|
+
|
|
401
|
+
**Esempio Testo Semplice:**
|
|
402
|
+
```typescript
|
|
403
|
+
await conn.sendMessage(jid, { text: 'bankai!' });
|
|
404
|
+
```
|
|
405
|
+
</details>
|
|
406
|
+
|
|
407
|
+
### 🎯 Eventi Principali
|
|
408
|
+
|
|
409
|
+
| Evento | Descrizione | Callback Signature |
|
|
410
|
+
|---------------------|--------------------------------------|-------------------------------------|
|
|
411
|
+
| `connection.update` | Aggiornamenti stato connessione | `(update: Partial<ConnectionState>) => void` |
|
|
412
|
+
| `creds.update` | Aggiornamento credenziali | `() => void` |
|
|
413
|
+
| `messages.upsert` | Nuovi messaggi o aggiornamenti | `({ messages: WAMessage[], type: MessageUpsertType }) => void` |
|
|
414
|
+
| `messages.update` | Modifiche a messaggi esistenti | `(update: WAMessageUpdate[]) => void` |
|
|
415
|
+
| `group-participants.update` | Cambiamenti partecipanti gruppo | `(update: GroupParticipantEvent) => void` |
|
|
416
|
+
|
|
417
|
+
**Esempio Registrazione Evento:**
|
|
418
|
+
```typescript
|
|
419
|
+
conn.ev.on('group-participants.update', (update) => {
|
|
420
|
+
console.log('Partecipante aggiornato:', update);
|
|
421
|
+
});
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## 🎪 Messaggi e Funzionalità Interattive
|
|
427
|
+
|
|
428
|
+
### Messaggi Base
|
|
429
|
+
|
|
430
|
+
#### Testo con Formattazione
|
|
431
|
+
```typescript
|
|
432
|
+
// Testo con formattazione e menzioni
|
|
433
|
+
await conn.sendMessage(jid, {
|
|
434
|
+
text: `*Bold* _italic_ ~strikethrough~ \`monospace\`\n@menzione`,
|
|
435
|
+
mentions: ['393476686131@s.whatsapp.net']
|
|
436
|
+
});
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
#### Media Base
|
|
440
|
+
```typescript
|
|
441
|
+
// Immagine
|
|
442
|
+
await conn.sendMessage(jid, {
|
|
443
|
+
image: { url: './media/varebot.jpg' }, // Supporta anche Buffer
|
|
444
|
+
caption: 'zwag'
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// Video
|
|
448
|
+
await conn.sendMessage(jid, {
|
|
449
|
+
video: { url: './media/oppastoppa.mp4' },
|
|
450
|
+
caption: 'brrrr',
|
|
451
|
+
gifPlayback: false // true per riprodurre come GIF
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// Audio
|
|
455
|
+
await conn.sendMessage(jid, {
|
|
456
|
+
audio: { url: './media/audio.mp3' },
|
|
457
|
+
mimetype: 'audio/mp4',
|
|
458
|
+
ptt: true // true per messaggio vocale, false per audio normale
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// Documento
|
|
462
|
+
await conn.sendMessage(jid, {
|
|
463
|
+
document: { url: './media/doc.pdf' },
|
|
464
|
+
mimetype: 'application/pdf',
|
|
465
|
+
fileName: 'documento.pdf'
|
|
466
|
+
});
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
#### Media Avanzati
|
|
470
|
+
```typescript
|
|
471
|
+
// Album (Multiple immagini)
|
|
472
|
+
await conn.sendMessage(jid, {
|
|
473
|
+
album: imageBuffers.map(buffer => ({ image: buffer })),
|
|
474
|
+
caption: 'ts gettin real'
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// Sticker
|
|
478
|
+
await conn.sendMessage(jid, {
|
|
479
|
+
sticker: { url: './stickers/sticker.webp' }
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// Messaggio con posizione
|
|
483
|
+
await conn.sendMessage(jid, {
|
|
484
|
+
location: {
|
|
485
|
+
degreesLatitude: 45.4642,
|
|
486
|
+
degreesLongitude: 9.1900,
|
|
487
|
+
name: "Milano",
|
|
488
|
+
address: "Piazza del Duomo, Milano"
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### Messaggi Interattivi
|
|
494
|
+
Questi messaggi includono elementi interattivi come bottoni, liste e template.
|
|
495
|
+
|
|
496
|
+
##### Messaggi con Bottoni Semplici
|
|
497
|
+
Invia bottoni di risposta rapida.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
await conn.sendMessage(jid, {
|
|
501
|
+
text: 'Scegli un\'opzione:',
|
|
502
|
+
footer: 'Footer',
|
|
503
|
+
buttons: [
|
|
504
|
+
{ buttonId: 'cmd1', buttonText: { displayText: 'testo1' }, type: 1 },
|
|
505
|
+
{ buttonId: 'cmd2', buttonText: { displayText: 'testo2' }, type: 1 },
|
|
506
|
+
],
|
|
507
|
+
headerType: 1,
|
|
508
|
+
});
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
##### Messaggi con Bottoni e Immagine
|
|
512
|
+
Combina immagine con bottoni.
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
await conn.sendMessage(jid, {
|
|
516
|
+
image: { url: 'https://i.ibb.co/hJW7WwxV/varebot.jpg' },
|
|
517
|
+
caption: 'Messaggio con bottoni e immagine',
|
|
518
|
+
footer: 'vare ✧ bot',
|
|
519
|
+
buttons: [
|
|
520
|
+
{ buttonId: 'cmd', buttonText: { displayText: 'testo1' }, type: 1 },
|
|
521
|
+
],
|
|
522
|
+
});
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
##### Messaggi Liste
|
|
526
|
+
Invia una lista di opzioni (solo in privato).
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
await conn.sendMessage(jid, {
|
|
530
|
+
text: 'Questa è una lista!',
|
|
531
|
+
footer: 'purplepurplepurple!',
|
|
532
|
+
title: 'Titolo Lista',
|
|
533
|
+
buttonText: 'Visualizza Lista',
|
|
534
|
+
sections: [
|
|
535
|
+
{
|
|
536
|
+
title: 'Sezione 1',
|
|
537
|
+
rows: [
|
|
538
|
+
{ title: 'Opzione 1', rowId: 'opt1',description: 'Descrizionex' },
|
|
539
|
+
{ title: 'Opzione 2', rowId: 'opt2', description: 'Descrizioney' }
|
|
540
|
+
]
|
|
541
|
+
},
|
|
542
|
+
],
|
|
543
|
+
});
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
##### Carousel e Card Messages
|
|
547
|
+
Il carousel è un tipo speciale di messaggio che permette di mostrare una serie di card scorrevoli.
|
|
548
|
+
```typescript
|
|
549
|
+
await conn.sendMessage(jid, {
|
|
550
|
+
text: '〖 🌸 〗 Benvenuto in VareBot!',
|
|
551
|
+
title: '',
|
|
552
|
+
footer: '',
|
|
553
|
+
cards: [
|
|
554
|
+
{
|
|
555
|
+
image: { url: 'https://i.ibb.co/hJW7WwxV/varebot.jpg' },
|
|
556
|
+
title: 'by sam aka vare',
|
|
557
|
+
body: '〖 💫 〗 Esplora funzionalità\n〖 🚀 〗 Bot aggiornato',
|
|
558
|
+
footer: '˗ˏˋ ☾ 𝚟𝚊𝚛𝚎𝚋𝚘𝚝 ☽ ˎˊ˗',
|
|
559
|
+
buttons: [
|
|
560
|
+
{ name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: 'Sito VareBot', url: 'https://varebot.netlify.app' }) },
|
|
561
|
+
{ name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: '💻 GitHub', url: 'https://github.com/realvare' }) },
|
|
562
|
+
{ name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: '💬 WhatsApp', url: 'https://wa.me/393476686131' }) },
|
|
563
|
+
{ name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: '📸 Instagram', url: 'https://instagram.com/samakavare' }) },
|
|
564
|
+
{ name: 'cta_url', buttonParamsJson: JSON.stringify({ display_text: '📧 Email', url: 'mailto:samakavare1@gmail.com' }) },
|
|
565
|
+
],
|
|
566
|
+
},
|
|
567
|
+
],
|
|
568
|
+
}, { quoted: m });
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
#### Altri Messaggi
|
|
572
|
+
```typescript
|
|
573
|
+
// Messaggio con citazione
|
|
574
|
+
await conn.sendMessage(jid, {
|
|
575
|
+
text: 'bang bang',
|
|
576
|
+
quoted: quotedMessage // Il messaggio da quotare/rispondere/citare
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// Messaggi Contatto
|
|
580
|
+
await conn.sendMessage(jid, {
|
|
581
|
+
contacts: {
|
|
582
|
+
displayName: 'Sam aka vare',
|
|
583
|
+
contacts: [{ vcard: 'BEGIN:VCARD\nVERSION:3.0\nFN:Sam aka vare\nTEL;waid=393476686131:+39 347 6686131\nEND:VCARD' }]
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
// Messaggi Poll (Sondaggio)
|
|
588
|
+
await conn.sendMessage(jid, {
|
|
589
|
+
poll: {
|
|
590
|
+
name: 'Anime preferito?',
|
|
591
|
+
values: ['Aot', 'Bleach', 'Death note'],
|
|
592
|
+
selectableCount: 1 // quante scelte possibili
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// Messaggi Ephemeral (Che si Autodistruggono)
|
|
597
|
+
await conn.sendMessage(jid, {
|
|
598
|
+
text: "Questo messaggio si autodistruggerà {speriamo come israele}"
|
|
599
|
+
}, {
|
|
600
|
+
ephemeralExpiration: 7 * 24 * 60 * 60
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
// Messaggi con Risposta a Visualizzazione
|
|
604
|
+
await conn.sendMessage(
|
|
605
|
+
jid,
|
|
606
|
+
{
|
|
607
|
+
video: { url: './media/hado90.mp4' },
|
|
608
|
+
viewOnce: true,
|
|
609
|
+
caption: 'tuff'
|
|
610
|
+
}
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
// Messaggi di Status (Stato)
|
|
614
|
+
await conn.sendMessage('status@broadcast', {
|
|
615
|
+
text: 'god forgive em'
|
|
616
|
+
}, {
|
|
617
|
+
statusJidList: contatti
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// Invia uno stato con media (visibile solo a contatti selezionati)
|
|
621
|
+
await conn.sendMessage('status@broadcast', {
|
|
622
|
+
image: { url: './media/menu/menu.jpg' },
|
|
623
|
+
caption: 'all i need in this life of sin is-',
|
|
624
|
+
}, {
|
|
625
|
+
statusJidList: contatti
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
// Messaggi Newsletter
|
|
629
|
+
await conn.sendMessage('120363418582531215@newsletter', {
|
|
630
|
+
text: 'ay yo',
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// Messaggi di Pagamento
|
|
634
|
+
await conn.sendMessage(jid, {
|
|
635
|
+
requestPayment: {
|
|
636
|
+
currency: 'EUR',
|
|
637
|
+
amount1000: 5000,
|
|
638
|
+
requestFrom: '393514357738@s.whatsapp.net',
|
|
639
|
+
note: 'js gimme my money' // https://paypal.me/samakavare
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
// Messaggi di Chiamata
|
|
644
|
+
await conn.sendMessage(jid, {
|
|
645
|
+
call: {
|
|
646
|
+
callKey: {
|
|
647
|
+
fromMe: true,
|
|
648
|
+
id: Date.now().toString(),
|
|
649
|
+
remoteJid: jid
|
|
650
|
+
},
|
|
651
|
+
type: 'ACCEPT' // 'MISSED', 'OFFER', 'ACCEPT', 'REJECT'..
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// Messaggi con Live Location
|
|
656
|
+
await conn.sendMessage(jid, {
|
|
657
|
+
liveLocation: {
|
|
658
|
+
degreesLatitude: 45.4642,
|
|
659
|
+
degreesLongitude: 9.1900,
|
|
660
|
+
accuracyInMeters: 50,
|
|
661
|
+
speedInMps: 5,
|
|
662
|
+
degreesClockwiseFromMagneticNorth: 359,
|
|
663
|
+
caption: "kmt im mean kiss my teeth",
|
|
664
|
+
sequenceNumber: 21,
|
|
665
|
+
timeOffset: 2000,
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// Messaggi di Ordini/Prodotti
|
|
670
|
+
await conn.sendMessage(jid, {
|
|
671
|
+
order: {
|
|
672
|
+
id: 'bysamakavare',
|
|
673
|
+
thumbnail: buffer, // immagine buffer
|
|
674
|
+
itemCount: 67,
|
|
675
|
+
surface: 'CATALOG',
|
|
676
|
+
title: 'heh',
|
|
677
|
+
text: 'gotta make it happen',
|
|
678
|
+
seller: '393514357738@s.whatsapp.net',
|
|
679
|
+
amount: 67000,
|
|
680
|
+
currency: 'EUR'
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
// Prodotto
|
|
685
|
+
await conn.sendMessage(jid, {
|
|
686
|
+
product: {
|
|
687
|
+
productImage: { url: './media/menu/menu.jpg' },
|
|
688
|
+
productId: 'prod123',
|
|
689
|
+
title: 'titolo',
|
|
690
|
+
description: 'Desc',
|
|
691
|
+
currency: 'EUR',
|
|
692
|
+
priceAmount1000: 67000,
|
|
693
|
+
retailerId: 'bysamakavare',
|
|
694
|
+
url: 'https://varebot.netlify.app',
|
|
695
|
+
},
|
|
696
|
+
businessOwnerJid: m.sender
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// Messaggi con Intestazione Personalizzata
|
|
700
|
+
await conn.sendMessage(jid, {
|
|
701
|
+
text: 'dilemma',
|
|
702
|
+
contextInfo: {
|
|
703
|
+
externalAdReply: {
|
|
704
|
+
title: `titolo`,
|
|
705
|
+
body: `desc`,
|
|
706
|
+
thumbnailUrl: 'https://i.ibb.co/hJW7WwxV/sam.jpg', // immagine
|
|
707
|
+
sourceUrl: '', // sconsiglio di metterla
|
|
708
|
+
mediaType: 1,
|
|
709
|
+
renderLargerThumbnail: false
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
> nota: non usate showAdAttribution o tenetela in false, poiche con essa attiva non viene visualizzato il messaggio
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
### Gestione delle Risposte
|
|
717
|
+
|
|
718
|
+
Per gestire le risposte ai messaggi interattivi, usa il listener `messages.upsert` e controlla il tipo di risposta:
|
|
719
|
+
|
|
720
|
+
```typescript
|
|
721
|
+
conn.ev.on('messages.upsert', async ({ messages }) => {
|
|
722
|
+
const msg = messages[0];
|
|
723
|
+
|
|
724
|
+
// Risposta a bottoni
|
|
725
|
+
if (msg.message?.buttonsResponseMessage) {
|
|
726
|
+
const selectedId = msg.message.buttonsResponseMessage.selectedButtonId;
|
|
727
|
+
console.log(`Bottone selezionato: ${selectedId}`);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Risposta a liste
|
|
731
|
+
if (msg.message?.listResponseMessage) {
|
|
732
|
+
const selectedId = msg.message.listResponseMessage.singleSelectReply.selectedRowId;
|
|
733
|
+
console.log(`Opzione selezionata: ${selectedId}`);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Risposta a sondaggio
|
|
737
|
+
if (msg.message?.pollResponseMessage) {
|
|
738
|
+
const selectedOptions = msg.message.pollResponseMessage.selectedOptions;
|
|
739
|
+
console.log('Opzioni selezionate:', selectedOptions);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
### 🎭 Funzionalità Gruppi
|
|
745
|
+
|
|
746
|
+
#### Gestione Base Gruppi
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
// Creazione gruppo - il jid sta per l'aggiunta di partecipanti
|
|
750
|
+
const group = await conn.groupCreate('Angels 🩸🕊️', ['user@s.whatsapp.net']);
|
|
751
|
+
|
|
752
|
+
// Ottenere info gruppo
|
|
753
|
+
const metadata = await conn.groupMetadata(jid);
|
|
754
|
+
|
|
755
|
+
// Ottenere codice invito
|
|
756
|
+
const code = await conn.groupInviteCode(jid);
|
|
757
|
+
|
|
758
|
+
// Revocare link invito
|
|
759
|
+
await conn.groupRevokeInvite(jid);
|
|
760
|
+
|
|
761
|
+
// Lasciare gruppo
|
|
762
|
+
await conn.groupLeave(jid);
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
#### Gestione Partecipanti
|
|
766
|
+
|
|
767
|
+
```typescript
|
|
768
|
+
// Aggiungere partecipanti
|
|
769
|
+
await conn.groupParticipantsUpdate(
|
|
770
|
+
jid,
|
|
771
|
+
['user@s.whatsapp.net'],
|
|
772
|
+
'add'
|
|
773
|
+
);
|
|
774
|
+
|
|
775
|
+
// Rimuovere partecipanti
|
|
776
|
+
await conn.groupParticipantsUpdate(
|
|
777
|
+
jid,
|
|
778
|
+
['user@s.whatsapp.net'],
|
|
779
|
+
'remove'
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
// Promuovere ad admin
|
|
783
|
+
await conn.groupParticipantsUpdate(
|
|
784
|
+
jid,
|
|
785
|
+
['user@s.whatsapp.net'],
|
|
786
|
+
'promote'
|
|
787
|
+
);
|
|
788
|
+
|
|
789
|
+
// Degradare da admin
|
|
790
|
+
await conn.groupParticipantsUpdate(
|
|
791
|
+
jid,
|
|
792
|
+
['user@s.whatsapp.net'],
|
|
793
|
+
'demote'
|
|
794
|
+
);
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
#### Impostazioni Gruppo
|
|
798
|
+
|
|
799
|
+
```typescript
|
|
800
|
+
// Modificare nome gruppo
|
|
801
|
+
await conn.groupUpdateSubject(jid, 'Nuovo Nome');
|
|
802
|
+
|
|
803
|
+
// Modificare descrizione
|
|
804
|
+
await conn.groupUpdateDescription(jid, 'Nuova descrizione');
|
|
805
|
+
|
|
806
|
+
// Modificare foto gruppo
|
|
807
|
+
await conn.updateProfilePicture(jid, { url: './img/group.jpg' });
|
|
808
|
+
|
|
809
|
+
// Rimuovere foto gruppo
|
|
810
|
+
await conn.removeProfilePicture(jid);
|
|
811
|
+
|
|
812
|
+
// Impostare gruppo come solo admin
|
|
813
|
+
await conn.groupSettingUpdate(jid, 'announcement');
|
|
814
|
+
|
|
815
|
+
// Impostare gruppo come aperto a tutti
|
|
816
|
+
await conn.groupSettingUpdate(jid, 'not_announcement');
|
|
817
|
+
|
|
818
|
+
// Impostare chi può modificare le info - solo admin
|
|
819
|
+
await conn.groupSettingUpdate(jid, 'locked');
|
|
820
|
+
|
|
821
|
+
// Impostare chi può modificare le info - tutti
|
|
822
|
+
await conn.groupSettingUpdate(jid, 'unlocked');
|
|
823
|
+
|
|
824
|
+
// Impostare chi può aggiungere membri - solo admin
|
|
825
|
+
await conn.groupMemberAddMode(jid, 'admin_add');
|
|
826
|
+
|
|
827
|
+
// Impostare chi può aggiungere membri - tutti
|
|
828
|
+
await conn.groupMemberAddMode(jid, 'all_member_add');
|
|
829
|
+
|
|
830
|
+
// Attivare/disattivare messaggi temporanei (24 ore)
|
|
831
|
+
await conn.groupToggleEphemeral(jid, 86400); // secondi
|
|
832
|
+
|
|
833
|
+
// Disattivare messaggi temporanei
|
|
834
|
+
await conn.groupToggleEphemeral(jid, 0);
|
|
835
|
+
|
|
836
|
+
// Attivare/disattivare modalità approvazione adesioni
|
|
837
|
+
await conn.groupJoinApprovalMode(jid, 'on'); // richiede approvazione
|
|
838
|
+
await conn.groupJoinApprovalMode(jid, 'off'); // aperta
|
|
839
|
+
|
|
840
|
+
// Ottenere tutti i gruppi
|
|
841
|
+
const groups = await conn.groupFetchAllParticipating();
|
|
842
|
+
|
|
843
|
+
// Ottenere inviti pendenti
|
|
844
|
+
const invites = await conn.groupGetInviteInfo(code);
|
|
845
|
+
|
|
846
|
+
// Accettare invito gruppo
|
|
847
|
+
await conn.groupAcceptInvite(code);
|
|
848
|
+
|
|
849
|
+
// Ottenere info gruppo da link
|
|
850
|
+
const groupInfo = await conn.groupGetInviteInfo('https://chat.whatsapp.com/ABC123');
|
|
851
|
+
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
#### Messaggi Gruppo Avanzati
|
|
855
|
+
|
|
856
|
+
```typescript
|
|
857
|
+
// Messaggio con menzione multipla
|
|
858
|
+
await conn.sendMessage(jid, {
|
|
859
|
+
text: '@user1 @user2 @user3',
|
|
860
|
+
mentions: [user1, user2, user3],
|
|
861
|
+
contextInfo: {
|
|
862
|
+
mentionedJid: [user1, user2, user3]
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
// Messaggio con ricerca google
|
|
867
|
+
await conn.sendMessage(jid, {
|
|
868
|
+
text: 'ZWAG',
|
|
869
|
+
contextInfo: {
|
|
870
|
+
forwardingScore: 999,
|
|
871
|
+
isForwarded: true
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
// Ascolta modifiche impostazioni
|
|
878
|
+
conn.ev.on('group-settings.update', async ({ jid, announce, restrict }) => {
|
|
879
|
+
if(announce !== undefined) {
|
|
880
|
+
await conn.sendMessage(jid, {
|
|
881
|
+
text: `Il gruppo è stato impostato come ${announce ? 'solo admin' : 'tutti'}`
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
if(restrict !== undefined) {
|
|
885
|
+
await conn.sendMessage(jid, {
|
|
886
|
+
text: `Le info gruppo possono essere modificate da ${restrict ? 'solo admin' : 'tutti'}`
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
```
|
|
891
|
+
```
|
|
892
|
+
---
|
|
893
|
+
|
|
894
|
+
## 🔧 Fix LID/JID nel Proprio Main e Handler
|
|
895
|
+
|
|
896
|
+
*Il supporto LID/JID è un punto di forza di questa libreria, risolvendo problemi comuni come l'identificazione mittenti in gruppi e chat privata. Ecco come integrarlo nel tuo codice principale e handler.*
|
|
897
|
+
|
|
898
|
+
### Best Practices per LID/JID
|
|
899
|
+
|
|
900
|
+
- **decodeJid(jid)**: Funzione principale per normalizzare JID/LID. Gestisce:
|
|
901
|
+
- Formati con `:\d+@` (usa `jidNormalizedUser`).
|
|
902
|
+
- Decodifica user/server in `${user}@${server}`.
|
|
903
|
+
- Converti `@lid` in `@s.whatsapp.net`.
|
|
904
|
+
|
|
905
|
+
**Esempio di Implementazione (da main.js):**
|
|
906
|
+
```typescript
|
|
907
|
+
decodeJid: (jid) => {
|
|
908
|
+
if (!jid) return jid;
|
|
909
|
+
let decoded = jid;
|
|
910
|
+
if (/:\d+@/gi.test(jid)) {
|
|
911
|
+
decoded = jidNormalizedUser(jid);
|
|
912
|
+
}
|
|
913
|
+
if (typeof decoded === 'object' && decoded.user && decoded.server) {
|
|
914
|
+
decoded = `${decoded.user}@${decoded.server}`;
|
|
915
|
+
}
|
|
916
|
+
if (decoded.endsWith('@lid')) {
|
|
917
|
+
decoded = decoded.replace('@lid', '@s.whatsapp.net');
|
|
918
|
+
}
|
|
919
|
+
return decoded;
|
|
920
|
+
},
|
|
921
|
+
```
|
|
922
|
+
Usa `conn.decodeJid(jid)` ovunque per normalizzare IDs (es. sender, participant, quoted).
|
|
923
|
+
|
|
924
|
+
- **Monkey-Patch per groupParticipantsUpdate**: Corregge aggiornamenti partecipanti gruppo trovando il JID reale dal metadata.
|
|
925
|
+
|
|
926
|
+
**Esempio (da handler.js):**
|
|
927
|
+
```typescript
|
|
928
|
+
if (!this.originalGroupParticipantsUpdate) {
|
|
929
|
+
this.originalGroupParticipantsUpdate = this.groupParticipantsUpdate;
|
|
930
|
+
this.groupParticipantsUpdate = async function(chatId, users, action) {
|
|
931
|
+
try {
|
|
932
|
+
let metadata = global.groupCache.get(chatId);
|
|
933
|
+
if (!metadata) {
|
|
934
|
+
metadata = await fetchGroupMetadataWithRetry(this, chatId);
|
|
935
|
+
if (metadata) global.groupCache.set(chatId, metadata);
|
|
936
|
+
}
|
|
937
|
+
if (!metadata) {
|
|
938
|
+
console.error('[ERRORE] Nessun metadato del gruppo disponibile per un aggiornamento sicuro');
|
|
939
|
+
return this.originalGroupParticipantsUpdate.call(this, chatId, users, action);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
const correctedUsers = users.map(userJid => {
|
|
943
|
+
const decoded = this.decodeJid(userJid);
|
|
944
|
+
const phone = decoded.split('@')[0].split(':')[0];
|
|
945
|
+
const participant = metadata.participants.find(p => {
|
|
946
|
+
const pId = this.decodeJid(p.id || p.jid || '');
|
|
947
|
+
const pPhone = pId.split('@')[0].split(':')[0];
|
|
948
|
+
return pPhone === phone;
|
|
949
|
+
});
|
|
950
|
+
return participant ? participant.id : userJid; // Fallback all'originale se non trovato
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
return this.originalGroupParticipantsUpdate.call(this, chatId, correctedUsers, action);
|
|
954
|
+
} catch (e) {
|
|
955
|
+
console.error('[ERRORE] Errore in safeGroupParticipantsUpdate:', e);
|
|
956
|
+
throw e;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
- **Cache per Metadata Gruppo**: Usa NodeCache per memorizzare metadata, normalizzando con `decodeJid`.
|
|
963
|
+
|
|
964
|
+
**Esempio (da handler.js):**
|
|
965
|
+
```typescript
|
|
966
|
+
global.groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false });
|
|
967
|
+
|
|
968
|
+
// In participantsUpdate o groups.update:
|
|
969
|
+
metadata.participants.forEach(u => {
|
|
970
|
+
const normId = this.decodeJid(u.id);
|
|
971
|
+
const jid = u.jid || normId;
|
|
972
|
+
});
|
|
973
|
+
global.groupCache.set(update.id, metadata);
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
- **Normalizzazione in Print/Log**: Rimuovi `:xx` dai numeri telefono per clean display.
|
|
977
|
+
|
|
978
|
+
**Esempio (da print.js):**
|
|
979
|
+
```typescript
|
|
980
|
+
function formatPhoneNumber(jid, name) {
|
|
981
|
+
if (!jid) return 'Sconosciuto';
|
|
982
|
+
let userPart = jid.split('@')[0];
|
|
983
|
+
let cleanNumber = userPart.split(':')[0]; // Rimuovi la parte :xx per ottenere il numero reale
|
|
984
|
+
try {
|
|
985
|
+
const number = PhoneNumber('+' + cleanNumber).getNumber('international');
|
|
986
|
+
return number + (name ? ` ~${name}` : '');
|
|
987
|
+
} catch {
|
|
988
|
+
return (cleanNumber || '') + (name ? ` ~${name}` : '');
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
- **Problemi Comuni e Fix:**
|
|
994
|
+
- **LID Mancante in Gruppi:** Usa `decodeJid` e cache metadata per trovare JID reali.
|
|
995
|
+
- **Conversione JID:** Sempre applica `decodeJid` prima di `sendMessage` o query.
|
|
996
|
+
- **Multi-Dispositivo:** Imposta `syncFullHistory: true` in config per sync LID.
|
|
997
|
+
- **Errori in Mention/Quoted:** Normalizza con `decodeJid` in handler per quoted.sender e mentionedJid.
|
|
998
|
+
|
|
999
|
+
### Esempio Integrato in Main
|
|
1000
|
+
|
|
1001
|
+
```typescript
|
|
1002
|
+
// Nel tuo file main
|
|
1003
|
+
import makeWASocket, { getSenderLid, toJid } from '@realvare/based';
|
|
1004
|
+
// ... (autenticazione e creazione sock)
|
|
1005
|
+
|
|
1006
|
+
conn.ev.on('messages.upsert', async ({ messages }) => {
|
|
1007
|
+
const msg = messages[0];
|
|
1008
|
+
if (!msg.message) return;
|
|
1009
|
+
|
|
1010
|
+
const info = getSenderLid(msg);
|
|
1011
|
+
const senderJid = toJid(info.lid); // Fix LID -> JID
|
|
1012
|
+
|
|
1013
|
+
// Esempio: Rispondi solo se JID valido
|
|
1014
|
+
if (senderJid.endsWith('@s.whatsapp.net')) {
|
|
1015
|
+
await conn.sendMessage(senderJid, { text: `Ciao da ${senderJid}!` }, { quoted: msg });
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
### Esempio Handler Personalizzato
|
|
1021
|
+
|
|
1022
|
+
Crea un handler separato per modularità:
|
|
1023
|
+
|
|
1024
|
+
```typescript
|
|
1025
|
+
// handler.js
|
|
1026
|
+
export async function handleMessage(sock, msg) {
|
|
1027
|
+
const info = getSenderLid(msg);
|
|
1028
|
+
const jid = toJid(info.lid);
|
|
1029
|
+
|
|
1030
|
+
// Log e risposta
|
|
1031
|
+
console.log(`Messaggio da ${jid}`);
|
|
1032
|
+
await conn.sendMessage(jid, { text: 'Handler attivato!' });
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// Nel main: conn.ev.on('messages.upsert', ({ messages }) => handleMessage(sock, messages[0]));
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
**Consiglio:** Testa in gruppi per verificare LID, poiché Baileys upstream ha migliorato il supporto nativo nel 2025, ma i fix personalizzati qui garantiscono retrocompatibilità.
|
|
1039
|
+
|
|
1040
|
+
---
|
|
1041
|
+
|
|
1042
|
+
### 🚀 Cache Intelligente LID/JID
|
|
1043
|
+
|
|
1044
|
+
La libreria ora include un sistema di cache avanzato per ottimizzare le conversioni LID/JID:
|
|
1045
|
+
|
|
1046
|
+
```typescript
|
|
1047
|
+
import { getCacheStats, clearCache, setPerformanceConfig } from '@realvare/based';
|
|
1048
|
+
|
|
1049
|
+
// Configura cache personalizzata
|
|
1050
|
+
setPerformanceConfig({
|
|
1051
|
+
cache: {
|
|
1052
|
+
lidCache: {
|
|
1053
|
+
ttl: 10 * 60 * 1000, // 10 minuti
|
|
1054
|
+
maxSize: 15000
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
// Monitora performance
|
|
1060
|
+
const stats = getCacheStats();
|
|
1061
|
+
console.log('Cache LID:', stats.lidCache.size, '/', stats.lidCache.maxSize);
|
|
1062
|
+
|
|
1063
|
+
// Pulisci cache se necessario
|
|
1064
|
+
clearCache();
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
### 🛡️ Validazione JID Avanzata
|
|
1068
|
+
|
|
1069
|
+
```typescript
|
|
1070
|
+
import { validateJid, Logger } from '@realvare/based';
|
|
1071
|
+
|
|
1072
|
+
const jid = '1234567890@s.whatsapp.net';
|
|
1073
|
+
const validation = validateJid(jid);
|
|
1074
|
+
|
|
1075
|
+
if (validation.isValid) {
|
|
1076
|
+
Logger.info('JID valido:', jid);
|
|
1077
|
+
} else {
|
|
1078
|
+
Logger.error('JID non valido:', validation.error);
|
|
1079
|
+
}
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
### 📊 Logging Condizionale
|
|
1083
|
+
|
|
1084
|
+
```typescript
|
|
1085
|
+
import { Logger, setPerformanceConfig } from '@realvare/based';
|
|
1086
|
+
|
|
1087
|
+
// Configura logging
|
|
1088
|
+
setPerformanceConfig({
|
|
1089
|
+
debug: {
|
|
1090
|
+
enableLidLogging: true,
|
|
1091
|
+
enablePerformanceLogging: true,
|
|
1092
|
+
logLevel: 'debug' // 'error', 'warn', 'info', 'debug'
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
// Usa logger condizionale
|
|
1097
|
+
Logger.debug('Debug info');
|
|
1098
|
+
Logger.performance('Performance metrics');
|
|
1099
|
+
Logger.error('Error occurred');
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1102
|
+
### 🔧 Configurazione Performance
|
|
1103
|
+
|
|
1104
|
+
```typescript
|
|
1105
|
+
import { setPerformanceConfig, getPerformanceConfig } from '@realvare/based';
|
|
1106
|
+
|
|
1107
|
+
// Configurazione completa
|
|
1108
|
+
setPerformanceConfig({
|
|
1109
|
+
performance: {
|
|
1110
|
+
enableCache: true,
|
|
1111
|
+
enableMetrics: true,
|
|
1112
|
+
batchSize: 100,
|
|
1113
|
+
maxRetries: 3
|
|
1114
|
+
},
|
|
1115
|
+
cache: {
|
|
1116
|
+
lidCache: { ttl: 5 * 60 * 1000, maxSize: 10000 },
|
|
1117
|
+
jidCache: { ttl: 5 * 60 * 1000, maxSize: 10000 }
|
|
1118
|
+
},
|
|
1119
|
+
debug: {
|
|
1120
|
+
enableLidLogging: false,
|
|
1121
|
+
logLevel: 'warn'
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
// Ottieni configurazione corrente
|
|
1126
|
+
const config = getPerformanceConfig();
|
|
1127
|
+
console.log('Cache abilitata:', config.performance.enableCache);
|
|
1128
|
+
```
|
|
1129
|
+
|
|
1130
|
+
---
|
|
1131
|
+
|
|
1132
|
+
## 🧩 Eventi: LID e JID sempre disponibili (nuovo)
|
|
1133
|
+
|
|
1134
|
+
Gli eventi emessi includono campi ausiliari sui messaggi per accedere facilmente sia al JID sia al LID del mittente/partecipante.
|
|
1135
|
+
|
|
1136
|
+
```typescript
|
|
1137
|
+
conn.ev.on('messages.upsert', ({ messages, type }) => {
|
|
1138
|
+
for (const msg of messages) {
|
|
1139
|
+
// Campi aggiuntivi su msg.key
|
|
1140
|
+
// - remoteJidNormalized: JID normalizzato (es. @s.whatsapp.net)
|
|
1141
|
+
// - remoteLid: LID equivalente del remoteJid
|
|
1142
|
+
// - participantLid: LID equivalente del participant (se presente)
|
|
1143
|
+
const jid = msg.key.remoteJidNormalized || msg.key.remoteJid;
|
|
1144
|
+
const remoteLid = msg.key.remoteLid;
|
|
1145
|
+
const participantLid = msg.key.participantLid;
|
|
1146
|
+
|
|
1147
|
+
if (jid?.endsWith('@s.whatsapp.net')) {
|
|
1148
|
+
conn.sendMessage(jid, { text: `Ciao! LID: ${remoteLid || 'n/d'}` });
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
Questi campi eliminano ambiguità in gruppi e contesti multi-dispositivo dove alcuni eventi riportano LID, altri JID.
|
|
1155
|
+
|
|
1156
|
+
---
|
|
1157
|
+
|
|
1158
|
+
## ⚙️ Configurazione Avanzata
|
|
1159
|
+
|
|
1160
|
+
Personalizza il socket per performance e comportamento.
|
|
1161
|
+
|
|
1162
|
+
### 🔧 Opzioni Complete per makeWASocket
|
|
1163
|
+
|
|
1164
|
+
```typescript
|
|
1165
|
+
const sock = makeWASocket({
|
|
1166
|
+
// 🔐 Autenticazione
|
|
1167
|
+
auth: state,
|
|
1168
|
+
|
|
1169
|
+
// 🖥️ UI e Debug
|
|
1170
|
+
printQRInTerminal: true,
|
|
1171
|
+
logger: console,
|
|
1172
|
+
browser: ['VareBot', 'Chrome', '4.0.0'],
|
|
1173
|
+
|
|
1174
|
+
// ⏱️ Timeout e Connessione
|
|
1175
|
+
defaultQueryTimeoutMs: 60000,
|
|
1176
|
+
keepAliveIntervalMs: 30000,
|
|
1177
|
+
connectTimeoutMs: 60000,
|
|
1178
|
+
retryRequestDelayMs: 250,
|
|
1179
|
+
maxMsgRetryCount: 5,
|
|
1180
|
+
|
|
1181
|
+
// 🎛️ Comportamento
|
|
1182
|
+
markOnlineOnConnect: true,
|
|
1183
|
+
syncFullHistory: false, // Attiva per sync completo (consuma dati)
|
|
1184
|
+
fireInitQueries: true,
|
|
1185
|
+
generateHighQualityLinkPreview: true,
|
|
1186
|
+
});
|
|
1187
|
+
```
|
|
1188
|
+
<div align="center">
|
|
1189
|
+
|
|
1190
|
+
### 🛡️ Sicurezza e Crittografia
|
|
1191
|
+
|
|
1192
|
+
| Caratteristica | Descrizione |
|
|
1193
|
+
|---------------------------|------------------------------------------|
|
|
1194
|
+
| 🔐 End-to-End Encryption | Protocollo Signal per messaggi sicuri |
|
|
1195
|
+
| 🔑 Key Management | Generazione/rotazione automatica chiavi |
|
|
1196
|
+
| 🔍 Authentication | Sicurezza tramite QR code o pairing code |
|
|
1197
|
+
| 🛡️ Data Protection | Archiviazione sicura credenziali locali |
|
|
1198
|
+
|
|
1199
|
+
---
|
|
1200
|
+
|
|
1201
|
+
## 🌐 Supporto e Community
|
|
1202
|
+
|
|
1203
|
+
Unisciti alla community per aiuto e contributi.
|
|
1204
|
+
|
|
1205
|
+
### 📞 Contatti e Risorse
|
|
1206
|
+
|
|
1207
|
+
| Canale | Link/Info |
|
|
1208
|
+
|------------------|------------------------------------------|
|
|
1209
|
+
| **Email** | [samakavare1@gmail.com](mailto:samakavare1@gmail.com) |
|
|
1210
|
+
| **GitHub Issues**| [Segnala Bug](https://github.com/realvare/based/issues) |
|
|
1211
|
+
| **PayPal** | [Dona](https://www.paypal.me/samakavare) |
|
|
1212
|
+
| **Canale whatsapp**| [Canale](https://www.whatsapp.com/channel/0029VbB41Sa1Hsq1JhsC1Z1z) |
|
|
1213
|
+
|
|
1214
|
+
---
|
|
1215
|
+
|
|
1216
|
+
## 🙏 Ringraziamenti
|
|
1217
|
+
|
|
1218
|
+
Grazie ai progetti che ispirano Based:
|
|
1219
|
+
|
|
1220
|
+
| Progetto | Contributo |
|
|
1221
|
+
|---------------------------|------------------------------------------|
|
|
1222
|
+
| [Baileys](https://github.com/WhiskeySockets/Baileys) | API WhatsApp Web originale |
|
|
1223
|
+
| [Yupra](https://www.npmjs.com/package/@yupra/baileys) | Fix LID/JID |
|
|
1224
|
+
| [Signal Protocol](https://signal.org/) | Crittografia end-to-end |
|
|
1225
|
+
|
|
1226
|
+
---
|
|
1227
|
+
|
|
1228
|
+
## ⚠️ Disclaimer & Licenza
|
|
1229
|
+
|
|
1230
|
+
### 📋 Nota Legale
|
|
1231
|
+
|
|
1232
|
+
⚠️ **Importante**: Non affiliato a WhatsApp Inc. o Meta. Uso educativo/sviluppo solo.
|
|
1233
|
+
|
|
1234
|
+
🛡️ **Uso Responsabile**: Evita spam, violazioni ToS WhatsApp. Rischio ban account.
|
|
1235
|
+
|
|
1236
|
+
### 📜 Licenza MIT
|
|
1237
|
+
|
|
1238
|
+
MIT License © 2025 [realvare](https://github.com/realvare)
|
|
1239
|
+
|
|
1240
|
+
Vedi [LICENSE](LICENSE) per dettagli.
|
|
1241
|
+
|
|
1242
|
+
---
|
|
1243
|
+
|
|
1244
|
+
<div align="center">
|
|
1245
|
+
<table align="center">
|
|
1246
|
+
<tr>
|
|
1247
|
+
<td align="center">
|
|
1248
|
+
<img src="https://i.ibb.co/Cp0SQznC/sam2.png" width="120" height="120" alt="pfp" style="bysamakavare"/>
|
|
1249
|
+
<br><br>
|
|
1250
|
+
<h2>👨💻 Creato da <a href="https://github.com/realvare" style="color: #8a2be2; text-decoration: none;">realvare</a></h2>
|
|
1251
|
+
<p><em>sam aka vare</em></p>
|
|
1252
|
+
</td>
|
|
1253
|
+
</tr>
|
|
1254
|
+
</table>
|
|
1255
|
+
|
|
1256
|
+
<br>
|
|
1257
|
+
<p align="center">
|
|
1258
|
+
<a href="https://github.com/realvare/based">
|
|
1259
|
+
<img src="https://img.shields.io/badge/⭐_Stella_il_Progetto-8a2be2?style=for-the-badge&logo=github&logoColor=white&labelColor=2d1b69"/>
|
|
1260
|
+
</a>
|
|
1261
|
+
<a href="https://github.com/realvare/based/fork">
|
|
1262
|
+
<img src="https://img.shields.io/badge/🔄_Fork_Repository-8a2be2?style=for-the-badge&logo=github&logoColor=white&labelColor=2d1b69"/>
|
|
1263
|
+
</a>
|
|
1264
|
+
<a href="https://paypal.me/samakavare">
|
|
1265
|
+
<img src="https://img.shields.io/badge/💰_Dona-8a2be2?style=for-the-badge&logo=paypal&logoColor=white&labelColor=2d1b69"/>
|
|
1266
|
+
</a>
|
|
1267
|
+
</p>
|
|
1268
|
+
<p align="center">
|
|
1269
|
+
<a href="https://github.com/realvare">
|
|
1270
|
+
<img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white&color=8a2be2"/>
|
|
1271
|
+
</a>
|
|
1272
|
+
<a href="https://wa.me/393476686131">
|
|
1273
|
+
<img src="https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge&logo=whatsapp&logoColor=white&color=8a2be2"/>
|
|
1274
|
+
</a>
|
|
1275
|
+
<a href="https://instagram.com/samakavare">
|
|
1276
|
+
<img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white&color=8a2be2"/>
|
|
1277
|
+
</a>
|
|
1278
|
+
<a href="mailto:samakavare1@gmail.com">
|
|
1279
|
+
<img src="https://img.shields.io/badge/Email-D14836?style=for-the-badge&logo=gmail&logoColor=white&color=8a2be2"/>
|
|
1280
|
+
</a>
|
|
1281
|
+
</p>
|
|
1282
|
+
<div align="center">
|
|
1283
|
+
<p><strong>Se ti è stato utile, lascia una stella e/o considera una donazione! ✧</strong></p>
|
|
1284
|
+
|
|
1285
|
+
<br>
|
|
1286
|
+
<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&customColorList=24&height=120§ion=footer&text=&fontSize=30&fontColor=ffffff&animation=fadeIn&fontAlignY=35"/>
|
|
1287
|
+
|
|
1288
|
+
</div>
|