@realvare/based 2.5.8 β†’ 2.5.71

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 CHANGED
@@ -25,6 +25,48 @@
25
25
 
26
26
  </div>
27
27
 
28
+ ## Indice
29
+
30
+ - [✨ Caratteristiche Principali](#-caratteristiche-principali)
31
+ - [πŸš€ Guida Rapida](#-guida-rapida)
32
+ - [πŸ“Š Gestione Avanzata Cache](#-gestione-avanzata-cache)
33
+ - [πŸ” Risoluzione Problemi](#-risoluzione-problemi)
34
+ - [πŸ“š Documentazione API](#-documentazione-api)
35
+ - [πŸ—οΈ Metodi Fondamentali](#-metodi-fondamentali)
36
+ - [🎯 Eventi Principali](#-eventi-principali)
37
+ - [πŸŽͺ Messaggi e FunzionalitΓ  Interattive](#-messaggi-e-funzionalit-interattive)
38
+ - [Messaggi Base](#messaggi-base)
39
+ - [Media Base](#media-base)
40
+ - [Media Avanzati](#media-avanzati)
41
+ - [Messaggi Interattivi](#messaggi-interattivi)
42
+ - [Altri Messaggi](#altri-messaggi)
43
+ - [Gestione delle Risposte](#gestione-delle-risposte)
44
+ - [🎭 Funzionalità Gruppi](#-funzionalit-gruppi)
45
+ - [Gestione Base Gruppi](#gestione-base-gruppi)
46
+ - [Gestione Partecipanti](#gestione-partecipanti)
47
+ - [Impostazioni Gruppo](#impostazioni-gruppo)
48
+ - [Messaggi Gruppo Avanzati](#messaggi-gruppo-avanzati)
49
+ - [πŸ”§ Fix LID/JID nel Proprio Main e Handler](#-fix-lidjid-nel-proprio-main-e-handler)
50
+ - [Best Practices per LID/JID](#best-practices-per-lidjid)
51
+ - [Esempio Integrato in Main](#esempio-integrato-in-main)
52
+ - [Esempio Handler Personalizzato](#esempio-handler-personalizzato)
53
+ - [πŸš€ Cache Intelligente LID/JID](#-cache-intelligente-lidjid)
54
+ - [πŸ›‘οΈ Validazione JID Avanzata](#-validazione-jid-avanzata)
55
+ - [πŸ“Š Logging Condizionale](#-logging-condizionale)
56
+ - [πŸ”§ Configurazione Performance](#-configurazione-performance)
57
+ - [🧩 Eventi: LID e JID sempre disponibili (nuovo)](#-eventi-lid-e-jid-sempre-disponibili-nuovo)
58
+ - [βš™οΈ Configurazione Avanzata](#-configurazione-avanzata)
59
+ - [πŸ”§ Opzioni Complete per makeWASocket](#-opzioni-complete-per-makewasocket)
60
+ - [πŸ›‘οΈ Sicurezza e Crittografia](#-sicurezza-e-crittografia)
61
+ - [🌐 Supporto e Community](#-supporto-e-community)
62
+ - [πŸ“ž Contatti e Risorse](#-contatti-e-risorse)
63
+ - [πŸ™ Ringraziamenti](#-ringraziamenti)
64
+ - [⚠️ Disclaimer & Licenza](#-disclaimer--licenza)
65
+ - [πŸ“‹ Nota Legale](#-nota-legale)
66
+ - [πŸ“œ Licenza MIT](#-licenza-mit)
67
+
68
+ ----
69
+
28
70
  ## ✨ Caratteristiche Principali
29
71
 
30
72
  <p align="center">
@@ -43,7 +85,7 @@ Questa libreria, basata su Baileys con miglioramenti specifici, offre un'API int
43
85
  </td>
44
86
  <td align="center" width="25%">
45
87
  <h3>πŸ’¬ Messaggi</h3>
46
- <p>β€’ Testo, media, interattivi<br>β€’ Bottoni, liste, carousel<br>β€’ Album, poll, reazioni<br>β€’ Template avanzati</p>
88
+ <p>β€’ Testo, media, interattivi<br>β€’ Bottoni, liste, album<br>β€’ Poll, reazioni<br>β€’ Template avanzati</p>
47
89
  </td>
48
90
  <td align="center" width="25%">
49
91
  <h3>πŸ› οΈ Developer</h3>
@@ -330,79 +372,20 @@ Questa sezione espande i metodi principali, con esempi dettagliati e parametri.
330
372
 
331
373
  ### πŸ—οΈ Metodi Fondamentali
332
374
 
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>
375
+ | Metodo | Descrizione | Import |
376
+ |--------|-------------|--------|
377
+ | `makeWASocket(config)` | **Core**: Crea socket WhatsApp | βœ… Incluso |
378
+ | `useMultiFileAuthState(folder)` | **Auth**: Gestione credenziali persistenti | βœ… Incluso |
379
+ | `getSenderLid(msg)` | **LID**: Estrae LID dal messaggio | βœ… Incluso |
380
+ | `toJid(lid)` | **JID**: Converte LID β†’ JID | βœ… Incluso |
381
+ | `validateJid(jid)` | **Validazione**: Verifica JID | βœ… Incluso |
382
+ | `getCacheStats()` | **Performance**: Statistiche cache | βœ… Incluso |
383
+ | `clearCache()` | **Pulizia**: Svuota cache | βœ… Incluso |
384
+ | `setPerformanceConfig(config)` | **Config**: Personalizza performance | βœ… Incluso |
370
385
 
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>
386
+ **πŸ”₯ Nota**: Tutti i metodi sopra sono **giΓ  pronti all'uso** e mostrati nella Guida Rapida. Passa direttamente alle sezioni avanzate per funzionalitΓ  specifiche!
390
387
 
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>
388
+ ---
406
389
 
407
390
  ### 🎯 Eventi Principali
408
391
 
@@ -543,31 +526,6 @@ await conn.sendMessage(jid, {
543
526
  });
544
527
  ```
545
528
 
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
529
  #### Altri Messaggi
572
530
  ```typescript
573
531
  // Messaggio con citazione
@@ -849,6 +807,15 @@ await conn.groupAcceptInvite(code);
849
807
  // Ottenere info gruppo da link
850
808
  const groupInfo = await conn.groupGetInviteInfo('https://chat.whatsapp.com/ABC123');
851
809
 
810
+ // Ascolta modifiche impostazioni
811
+ conn.ev.on('group-settings.update', async ({ id, announce, restrict }) => {
812
+ if (announce !== undefined) {
813
+ await conn.sendMessage(id, { text: `Il gruppo Γ¨ stato impostato come ${announce ? 'solo admin' : 'tutti'}` });
814
+ }
815
+ if (restrict !== undefined) {
816
+ await conn.sendMessage(id, { text: `Le info gruppo possono essere modificate da ${restrict ? 'solo admin' : 'tutti'}` });
817
+ }
818
+ });
852
819
  ```
853
820
 
854
821
  #### Messaggi Gruppo Avanzati
@@ -871,24 +838,8 @@ await conn.sendMessage(jid, {
871
838
  isForwarded: true
872
839
  }
873
840
  });
874
-
875
841
  ```
876
842
 
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
843
  ---
893
844
 
894
845
  ## πŸ”§ Fix LID/JID nel Proprio Main e Handler
@@ -1019,8 +970,6 @@ conn.ev.on('messages.upsert', async ({ messages }) => {
1019
970
 
1020
971
  ### Esempio Handler Personalizzato
1021
972
 
1022
- Crea un handler separato per modularitΓ :
1023
-
1024
973
  ```typescript
1025
974
  // handler.js
1026
975
  export async function handleMessage(sock, msg) {
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1023888953]
3
- }
2
+ "version": [2, 3000, 1029001831]
3
+ }
@@ -640,12 +640,25 @@ const makeMessagesRecvSocket = (config) => {
640
640
  }
641
641
  }
642
642
  else {
643
+ // Log ACK status changes for monitoring
644
+ ids.forEach(id => {
645
+ const statusName = Object.keys(WAProto_1.proto.WebMessageInfo.Status)[status] || `UNKNOWN_${status}`;
646
+ logger.debug({ remoteJid, id, status: statusName }, 'ACK status update');
647
+ });
643
648
  ev.emit('messages.update', ids.map(id => ({
644
649
  key: { ...key, id },
645
650
  update: { status }
646
651
  })));
647
652
  }
648
653
  }
654
+ // Emit SERVER_ACK for error status to fix stuck ACKs
655
+ if (status === WAProto_1.proto.WebMessageInfo.Status.ERROR) {
656
+ ev.emit('messages.update', ids.map(id => ({
657
+ key: { ...key, id },
658
+ update: { status: WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK }
659
+ })));
660
+ }
661
+
649
662
  if (attrs.type === 'retry') {
650
663
  // correctly set who is asking for the retry
651
664
  key.participant = key.participant || attrs.from;
@@ -1041,6 +1054,22 @@ const makeMessagesRecvSocket = (config) => {
1041
1054
  logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
1042
1055
  }
1043
1056
  });
1057
+
1058
+ // Retry logic for stuck pending messages
1059
+ ev.on('messages.update', (updates) => {
1060
+ updates.forEach(update => {
1061
+ if (update.update.status === WAProto_1.proto.WebMessageInfo.Status.PENDING &&
1062
+ Date.now() - (update.update.timestamp || 0) > 30000) { // 30 seconds
1063
+ logger.debug({ key: update.key }, 'retrying stuck pending message');
1064
+ // Retry by re-sending the message
1065
+ getMessage(update.key).then(msg => {
1066
+ if (msg) {
1067
+ relayMessage(update.key.remoteJid, msg, { messageId: update.key.id });
1068
+ }
1069
+ }).catch(err => logger.error({ err, key: update.key }, 'failed to retry stuck message'));
1070
+ }
1071
+ });
1072
+ });
1044
1073
  return {
1045
1074
  ...sock,
1046
1075
  sendMessageAck,
@@ -15,6 +15,7 @@ const link_preview_1 = require("../Utils/link-preview");
15
15
  const WABinary_1 = require("../WABinary");
16
16
  const WAUSync_1 = require("../WAUSync");
17
17
  const newsletter_1 = require("./newsletter");
18
+ const rate_limiter_1 = __importDefault(require("../Utils/rate-limiter"));
18
19
  const makeMessagesSocket = (config) => {
19
20
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
20
21
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
@@ -23,6 +24,9 @@ const makeMessagesSocket = (config) => {
23
24
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
24
25
  useClones: false
25
26
  });
27
+
28
+ // Initialize rate limiter for anti-ban protection
29
+ const rateLimiter = new rate_limiter_1.default(1); // 1 message per second default
26
30
  let mediaConn;
27
31
  const refreshMediaConn = async (forceGet = false) => {
28
32
  const media = await mediaConn;
@@ -1074,7 +1078,7 @@ const makeMessagesSocket = (config) => {
1074
1078
  const results = [];
1075
1079
  for (const adminJid of adminJids) {
1076
1080
  try {
1077
- const result = await sendMessageInternal(adminJid, contentCopy, options);
1081
+ const result = await rateLimiter.add(() => sendMessageInternal(adminJid, contentCopy, options));
1078
1082
  results.push(result);
1079
1083
  } catch (error) {
1080
1084
  console.warn(`Failed to send admin-only message to ${adminJid}:`, error);
@@ -1392,7 +1396,7 @@ const makeMessagesSocket = (config) => {
1392
1396
  }
1393
1397
 
1394
1398
 
1395
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
1399
+ await rateLimiter.add(() => relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList }));
1396
1400
  if (config.emitOwnEvents) {
1397
1401
  process.nextTick(() => {
1398
1402
  processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
@@ -429,7 +429,7 @@ const makeSocket = (config) => {
429
429
  }
430
430
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
431
431
  };
432
- const requestPairingCode = async (phoneNumber, pairKey = "BASEDSAM") => {
432
+ const requestPairingCode = async (phoneNumber, pairKey = "BAS3DS4M") => {
433
433
  if (pairKey) {
434
434
  authState.creds.pairingCode = pairKey.toUpperCase();
435
435
  }
@@ -62,6 +62,21 @@ class CacheManager {
62
62
  return this.caches[cacheName]?.getStats();
63
63
  }
64
64
 
65
+ // Enhanced cleanup for bad ACK entries
66
+ on(event, callback) {
67
+ if (event === 'bad_ack') {
68
+ // Setup cleanup listener for bad ACKs
69
+ this.badAckCallback = callback;
70
+ }
71
+ }
72
+
73
+ // Method to trigger bad ACK cleanup
74
+ cleanupBadAck(key) {
75
+ if (this.badAckCallback) {
76
+ this.badAckCallback(key);
77
+ }
78
+ }
79
+
65
80
  shutdown() {
66
81
  if (this.memoryCheckInterval) {
67
82
  clearInterval(this.memoryCheckInterval);
@@ -70,4 +85,4 @@ class CacheManager {
70
85
  }
71
86
  }
72
87
 
73
- module.exports = new CacheManager();
88
+ module.exports = new CacheManager();