Overview
Baileys is a free, open-source WhatsApp Web API implementation that lets you connect to WhatsApp without official business API credentials. It works by emulating the WhatsApp Web client and uses QR code scanning for authentication.Baileys connects through WhatsApp Web, making it perfect for personal use, testing, or applications that don’t require official Meta Business API credentials.
How It Works
Baileys establishes a WebSocket connection to WhatsApp servers by:- Generating a QR code or pairing code for authentication
- Maintaining a persistent session with encrypted credentials
- Synchronizing messages, contacts, and chat history
- Handling reconnections automatically
Authentication Methods
- QR Code
- Pairing Code
The default authentication method displays a QR code that you scan with your WhatsApp mobile app.
QR Code Configuration
- QRCODE_LIMIT: Maximum number of QR code regenerations before timeout (default: 30)
- QRCODE_COLOR: HEX color for the QR code dark pixels (default: ‘#175197’)
Session Configuration
Configure how your instance appears in WhatsApp’s “Linked Devices”:.env
Connection Lifecycle
Authenticate
Scan the QR code or enter the pairing code in WhatsApp. The API monitors authentication status and emits connection events:
Session Persistence
Evolution API automatically saves your session to prevent re-authentication:
- Database: Prisma stores encrypted credentials
- Redis: Optional caching layer for faster reconnections
- File Provider: Alternative storage backend
Connection Events
Monitor connection status through webhook events:Connection States
| State | Description |
|---|---|
connecting | Establishing connection to WhatsApp servers |
open | Successfully connected and authenticated |
close | Disconnected (may attempt reconnection) |
Features
Message Synchronization
Baileys supports full history sync when enabled:.env
Group Support
Control whether to ignore group messages:Media Handling
Baileys automatically downloads and processes media messages:Limitations vs Business API
| Feature | Baileys | Business API |
|---|---|---|
| Cost | Free | Paid per conversation |
| Authentication | QR code/pairing | API credentials |
| Rate limits | WhatsApp Web limits | Higher API limits |
| Ban risk | Possible if misused | Lower risk |
| Message templates | Not supported | Supported |
| Official support | Community | Meta support |
| Multi-device | Limited | Full support |
| Business features | Basic | Advanced (catalogs, etc.) |
Best Practices
Avoid Spam
Don’t send bulk messages or automated spam. This can get your number banned from WhatsApp.
Session Backup
Regularly backup your session data to avoid re-authentication if the instance is deleted.
Troubleshooting
QR Code Not Appearing
Check your webhook configuration and ensure events are enabled:.env
Connection Keeps Closing
Verify your session is being saved:.env
Messages Not Syncing
Enable full history sync and check group settings:Advanced Configuration
Proxy Support
Configure proxy settings for Baileys connections:.env
Custom Baileys Version
The API automatically fetches the latest WhatsApp Web version:Logging
Control Baileys log output:.env
Next Steps
Send Messages
Learn how to send text, media, and interactive messages
Receive Messages
Set up webhooks to receive messages and events
Connection Management
Master connection lifecycle and reconnection strategies
Business API
Compare with official WhatsApp Business API