Baileys adalah library Node.js yang powerful untuk membuat koneksi ke WhatsApp Web (multi-device).
{
"dependencies": {
"@whiskeysockets/baileys": "github:Codemen-0/DesaBail"
}
}
const { default: makeWASocket, useMultiFileAuthState, DisconnectReason } = require('@whiskeysockets/baileys');
async function startBot() {
const { state, saveCreds } = await useMultiFileAuthState('auth_info');
const sock = makeWASocket({
auth: state,
printQRInTerminal: true
});
sock.ev.on('connection.update', (update) => {
const { connection } = update;
if (connection === 'open') console.log('✅ Bot WhatsApp Aktif!');
});
sock.ev.on('creds.update', saveCreds);
sock.ev.on('messages.upsert', async (m) => {
const msg = m.messages[0];
if (!msg.key.fromMe && msg.message) {
const sender = msg.key.remoteJid;
const text = msg.message.conversation || '';
if (text.toLowerCase() === 'ping') {
await sock.sendMessage(sender, { text: 'pong!' });
}
}
});
}
startBot();
Cara install: npm init -y && npm install @whiskeysockets/baileys @hapi/boom pino