Connect CodeSpar to WhatsApp using Evolution API for team communication via QR code pairing and webhook-based messaging.
WhatsApp Channel
CodeSpar connects to WhatsApp through Evolution API, an open-source WhatsApp gateway. This approach uses a real WhatsApp session (via QR code) rather than the official Business API, making it accessible for teams of any size without Meta Business verification.
Prerequisites
- Docker and Docker Compose installed
- A phone number dedicated to the bot (a secondary number or old phone works)
- CodeSpar instance running
Architecture
Evolution API runs as a separate Docker container. It manages the WhatsApp Web session and forwards messages to CodeSpar via webhooks. CodeSpar sends responses back through Evolution API's REST endpoint.
Docker Compose Setup
Create a docker-compose.whatsapp.yml or add the Evolution API service to your existing compose file:
Environment Variables
Add these to your .env file:
Variable Reference
| Variable | Required | Description |
|---|---|---|
ENABLE_WHATSAPP | Yes | Set to true to activate the WhatsApp channel |
EVOLUTION_API_URL | Yes | URL where Evolution API is running |
EVOLUTION_API_KEY | Yes | API key for authenticating with Evolution API |
EVOLUTION_INSTANCE | Yes | Instance name for the WhatsApp session |
WHATSAPP_BOT_MENTION | No | Trigger keyword in group chats (default: @codespar) |
QR Code Pairing
After starting Evolution API, you need to scan a QR code to link a WhatsApp account:
Step 1: Create an Instance
Step 2: Get the QR Code
This returns a QR code (as base64 image or text). You can also access it in a browser at http://localhost:8080/manager if the Evolution API manager UI is enabled.
Step 3: Scan with WhatsApp
- Open WhatsApp on the phone you want to use as the bot
- Go to Settings → Linked Devices → Link a Device
- Scan the QR code
- The session is now active
The session persists across restarts thanks to the Docker volume. You only need to scan the QR code once unless the session is revoked from the phone.
Webhook Configuration
Evolution API sends incoming messages to CodeSpar via webhook. The key configuration in the Docker Compose file:
CodeSpar listens on port 3001 for these webhook events. The MESSAGES_UPSERT event fires for every incoming message. The adapter filters for messages containing the bot mention keyword.
How Mentions Work
WhatsApp doesn't have native bot mentions like Slack or Discord. Instead, CodeSpar uses a keyword trigger:
In Group Chats
The bot only responds to messages containing the WHATSAPP_BOT_MENTION keyword. All other messages are ignored.
In Direct Messages
When messaging the bot directly (1:1 chat), no mention keyword is needed. Every message is processed as a command:
Limitations
WhatsApp has some constraints compared to other channels:
| Feature | Support |
|---|---|
| Threads | Not supported — all replies go to the main chat |
| Reactions | Not supported via Evolution API |
| Rich formatting | Partial — bold, italic, monospace, but no full Markdown |
| File uploads | Supported (images, documents) |
| Message editing | Not supported |
| Message length | ~65,000 characters per message |
Troubleshooting
QR code expired
QR codes expire after about 60 seconds. Request a new one:
Bot not responding in groups
- Verify
ENABLE_WHATSAPP=trueis set - Check that the
WHATSAPP_BOT_MENTIONkeyword matches what users are typing - Ensure the webhook URL is reachable from the Evolution API container (
http://codespar:3001/webhook/whatsapp) - Check CodeSpar logs for incoming webhook events
Session disconnected
If WhatsApp disconnects the linked device (happens after ~14 days of inactivity on the phone), you need to re-scan the QR code. Keep the phone connected to the internet and WhatsApp open periodically.
Evolution API container won't start
Ensure the evolution_data volume has proper permissions. On Linux, you may need: