@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 +64 -115
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Socket/messages-recv.js +29 -0
- package/lib/Socket/messages-send.js +6 -2
- package/lib/Socket/socket.js +1 -1
- package/lib/Utils/cache-manager.js +16 -1
- package/lib/Utils/messages.js +1373 -1338
- package/lib/Utils/performance-config.d.ts +4 -0
- package/lib/Utils/performance-config.js +8 -4
- package/lib/Utils/rate-limiter.js +95 -0
- package/package.json +3 -6
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,
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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')));
|
package/lib/Socket/socket.js
CHANGED
|
@@ -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 = "
|
|
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();
|