Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Bot with Baileys

A simple WhatsApp bot that maintains session persistence so you don't lose connection.

Features

  • 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

Installation

All dependencies are already installed. If you need to reinstall:

npm install

Usage

Start the Bot

npm start

Or directly:

node bot.js

First Time Setup

  1. Run the bot with npm start
  2. A QR code will appear in the terminal
  3. Open WhatsApp on your phone
  4. Go to Settings → Linked Devices → Link a Device
  5. Scan the QR code
  6. Once connected, you'll see "✅ Connected successfully!"

Session Management

  • 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

How It Works

  1. Authentication: Uses useMultiFileAuthState to save credentials to disk
  2. Session Persistence: Credentials are saved every time they update
  3. Auto Reconnect: Detects disconnections and reconnects automatically (except when logged out)
  4. Message Handling: Listens for incoming messages and responds based on content

Customization

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' });
}

Troubleshooting

  • 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

Dependencies

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages