This guide walks you through setting up WhatsApp as a channel for LettaBot.
LettaBot connects to WhatsApp using Baileys, which uses the WhatsApp Web protocol. This means:
- Uses your personal WhatsApp account (or a dedicated number)
- No WhatsApp Business API required
- Free to use
- Requires QR code scan on first setup
- A phone with WhatsApp installed
- LettaBot installed and configured with at least
LETTA_API_KEY
Add to your .env file:
# WhatsApp Configuration
WHATSAPP_ENABLED=true
# Optional: Custom session storage path (default: ./data/whatsapp-session)
# WHATSAPP_SESSION_PATH=./data/whatsapp-session
# Optional: Restrict to specific phone numbers
# WHATSAPP_ALLOWED_USERS=+15551234567,+15559876543npm run devYou'll see output like:
Registered channel: WhatsApp
[WhatsApp] Scan the QR code above to login
A QR code will be displayed in your terminal.
- Open WhatsApp on your phone
- Go to Settings → Linked Devices
- Tap "Link a Device"
- Scan the QR code displayed in your terminal
Once connected, you'll see:
[WhatsApp] Connected!
- From another phone (or WhatsApp Web with a different account), send a message to the number you just linked
- The bot should respond
Or test with yourself:
- Open a note-to-self chat (message yourself)
- Send a test message
After the first QR scan, your session is saved to disk (default: ./data/whatsapp-session/).
On subsequent restarts:
- No QR scan needed
- Bot reconnects automatically
- If session expires, a new QR code will be shown
To restrict which phone numbers can interact with the bot:
# Include country code with + prefix
WHATSAPP_ALLOWED_USERS=+15551234567,+15559876543Note: Only DMs are restricted. Group messages may still be received (but not responded to unless the sender is allowed).
Since LettaBot uses a single agent across all channels:
- Messages from WhatsApp continue the same conversation as Telegram/Slack
- The agent remembers context from all channels
- Start a conversation on Telegram, continue it on WhatsApp
WhatsApp doesn't support editing messages. When the bot streams a long response, it will send the full message at once rather than updating incrementally.
WhatsApp has strict rate limits to prevent spam:
- Don't send too many messages too quickly
- Avoid automated bulk messaging
- Risk of account ban if abused
This uses your personal WhatsApp account:
- Messages appear as coming from your number
- Consider using a dedicated phone number for the bot
- Your contacts will see the bot as "you"
- WhatsApp allows up to 4 linked devices
- The bot counts as one linked device
- If you unlink the bot, you'll need to scan the QR code again
For production deployments:
- Use a dedicated phone number - Don't use your personal WhatsApp
- Persistent storage - Make sure
WHATSAPP_SESSION_PATHpoints to persistent storage - Monitor reconnections - The bot auto-reconnects, but check logs for issues
- Backup session - Back up the session folder to avoid re-scanning QR codes
If no QR code appears:
- Check that
WHATSAPP_ENABLED=trueis set - Look for error messages in the console
- Make sure you have a terminal that supports QR code display
This usually means:
- WhatsApp Web session was logged out from your phone
- Network connectivity issues
- WhatsApp servers are temporarily unavailable
The bot will automatically try to reconnect.
If you see "logged out" in the logs:
- Delete the session folder:
rm -rf ./data/whatsapp-session - Restart LettaBot
- Scan the new QR code
- Make sure the sender's number is in
WHATSAPP_ALLOWED_USERS(if configured) - Check that the message is a text message (media not fully supported yet)
- Look for errors in the console
On first connection, the bot might receive some historical messages. This is normal WhatsApp behavior. The bot will only respond to new messages going forward.
- Session files contain authentication data - keep them secure
- Don't share your session folder
- Use
WHATSAPP_ALLOWED_USERSto restrict who can interact with the bot - Consider the privacy implications of using a personal number
data/
└── whatsapp-session/
├── creds.json # Authentication credentials
├── app-state-sync-* # App state
└── ... # Other session data