npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bottino/baileys

v1.0.14

Published

Whatsapp api by Bottino

Readme

Wave

Retro


✨ Funzionalità

La libreria ufficiale del progetto Bottino, basata su Baileys con miglioramenti specifici. Offre un'API intuitiva per interagire con WhatsApp Web.

Nota speciale: puoi collegare il bot anche senza scannerizzare il QR, usando un codice di pairing da WhatsApp > Dispositivi collegati.


🚀 Installazione

Installa la libreria con npm:

npm install @bottino/baileys

Avvio rapido

import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@bottino/baileys';

async function startBot() {
    // 🔐 Autenticazione multi-file per sessioni persistenti
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys');

    // 🌐 Creazione del socket
    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true,
        logger: console,
        browser: ['YourBotName', 'Chrome', '4.0.0'],
    });

    // 🔄 Sistema di riconnessione automatica
    let reconnectAttempts = 0;
    const maxRetries = 5;
    const retryDelay = 5000;
    const retryBackoffMultiplier = 1.5;
    const maxRetryDelay = 60000;

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update;

        if (connection === 'close') {
            const shouldReconnect = lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;

            if (shouldReconnect) {
                reconnectAttempts++;
                const delay = Math.min(
                    retryDelay * Math.pow(retryBackoffMultiplier, reconnectAttempts - 1),
                    maxRetryDelay
                );

                console.log(`🔄 Tentativo di riconnessione ${reconnectAttempts}/${maxRetries} tra ${delay}ms`);

                if (reconnectAttempts <= maxRetries) {
                    setTimeout(startBot, delay);
                } else {
                    console.log('❌ Numero massimo di tentativi di riconnessione raggiunto');
                }
            }
        } else if (connection === 'open') {
            console.log('🟢 Connesso con successo!');
            reconnectAttempts = 0;
        }
    });

    sock.ev.on('creds.update', saveCreds);
}

startBot().catch(console.error);

🛡️ Anti-Ban integrato

La libreria include un sistema anti-ban attivo di default che protegge il numero:

  • Rate limit: massimo 1 messaggio al secondo per chat (messagesSendRate, default 1).
  • Umanizzazione: ritardo casuale tra 800 e 2500ms prima di ogni invio (humanizeMessages, default true).
  • Indicatore di digitazione: invia lo stato "sta scrivendo…" prima di rispondere (antiBan.typingIndicator, default true).
const sock = makeWASocket({
    auth: state,
    printQRInTerminal: true,
    logger: console,
    markOnlineOnConnect: false,
    syncFullHistory: false,
    // 🛡️ Anti-ban configurabile
    messagesSendRate: 1,                    // msg/sec (default 1)
    humanizeMessages: true,                  // ritardi umani on/off
    antiBan: {
        typingIndicator: true,               // "sta scrivendo…" prima della risposta
        minDelayMs: 800,                     // ritardo minimo in ms
        maxDelayMs: 2500,                    // ritardo massimo in ms
    },
});

⚠️ Attenzione: aumentando messagesSendRate o disattivando humanizeMessages/typingIndicator il bot risponde più veloce, ma aumenta il rischio di ban. Disattiva l'anti-ban solo se sei sicuro.

🕐 Anti-Attesa integrato

Evita il messaggio "⏳ in attesa del messaggio" quando WhatsApp non riceve il contenuto di un invio. La libreria salva gli ultimi messaggi inviati e risponde da sola alle richieste di re-invio del server (receipt type: retry) usando la funzione nativa sendMessagesAgain.

Come attivarlo:

const sock = makeWASocket({
    auth: state,
    printQRInTerminal: true,
    logger: console,
    // 🕐 Anti-Attesa
    enableRecentMessageCache: true,   // abilita la cache dei messaggi recenti + retry nativo
    getMessage: async (key) => {
        // (facoltativo) contenuto del messaggio con key.id se non è in cache.
        // Deve restituire il campo message, es.:
        //   { conversation: "testo" }
        //   { extendedTextMessage: { text: "testo" } }
        return undefined;
    },
});

Come funziona:

  • enableRecentMessageCache: true — mantiene in memoria gli ultimi messaggi inviati, così la lib può rispondere da sola alle richieste di re-invio.
  • getMessage(key) — se WhatsApp chiede un messaggio non più in cache, la lib lo richiede qui. Se restituisci il contenuto, il retry funziona comunque.
  • Quando un messaggio resta nello stato PENDING, il retry avviene automaticamente senza duplicati (stesso messageId).

Chiamare manualmente sendMessagesAgain:

La funzione è esposta sul socket. Re-invia il messaggio originale con lo stesso messageId (idempotente):

await sock.sendMessagesAgain(
    { remoteJid: jid, fromMe: true, id: messageId }, // key
    [messageId],                                      // ids da reinviare
    undefined,                                        // retryNode (opzionale)
    undefined                                         // receiptNode (opzionale)
);

💡 Suggerimento: combina Anti-Attesa con Anti-Ban — i messaggi bloccati vengono re-inviati in automatico rispettando il rate limit.

Collegare il dispositivo

Scansiona il QR oppure usa il codice di pairing da WhatsApp > Dispositivi collegati.


📄 Licenza

MIT © Bottino