A simple WhatsApp bot that maintains session persistence so you don't lose connection.
- ✅ Session Persistence: Saves authentication data to disk, so you won't lose connection on restart
- ✅ Auto Reconnect: Automatically reconnects if connection is lost (unless logged out)
- ✅ QR Code Login: Scan QR code with WhatsApp to connect
- ✅ Simple Commands:
- Send "ping" → Bot responds with "🏓 Pong!"
- Send "hello" → Bot sends a greeting message
All dependencies are already installed. If you need to reinstall:
npm installnpm startOr directly:
node bot.js- Run the bot with
npm start - A QR code will appear in the terminal
- Open WhatsApp on your phone
- Go to Settings → Linked Devices → Link a Device
- Scan the QR code
- Once connected, you'll see "✅ Connected successfully!"
- Session data is stored in the
session/folder - The bot will automatically use saved session on restart
- To logout completely, delete the
session/folder and restart
- Authentication: Uses
useMultiFileAuthStateto save credentials to disk - Session Persistence: Credentials are saved every time they update
- Auto Reconnect: Detects disconnections and reconnects automatically (except when logged out)
- Message Handling: Listens for incoming messages and responds based on content
Edit the bot.js file to add your own commands:
// Add your custom logic in the messages.upsert event
if (messageType.toLowerCase() === 'your-command') {
await sock.sendMessage(senderId, { text: 'Your response' });
}- QR code not appearing: Make sure terminal supports it
- Connection lost: Check your internet connection
- Logged out: Delete the
session/folder and scan QR again - Messages not sending: Ensure you're connected and the recipient hasn't blocked you
- @whiskeysockets/baileys - WhatsApp Web API
- qrcode-terminal - Display QR codes in terminal
- pino - Logging utility