Overview
The Chatwoot integration allows you to:- Receive WhatsApp messages in your Chatwoot inbox
- Reply to WhatsApp messages directly from Chatwoot
- Support text messages, images, audio, video, and file attachments
- Handle both individual chats and group conversations
- Sync message history to Chatwoot
Prerequisites
Before setting up the integration, ensure you have:- Go WhatsApp Web Multidevice running and accessible via a public URL
- Chatwoot instance (self-hosted or cloud) with admin access
- API Channel inbox created in Chatwoot
- At least one WhatsApp device connected and logged in
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
CHATWOOT_ENABLED | Yes | false | Enable Chatwoot integration |
CHATWOOT_URL | Yes | - | Your Chatwoot instance URL (e.g., https://app.chatwoot.com) |
CHATWOOT_API_TOKEN | Yes | - | API access token from Chatwoot |
CHATWOOT_ACCOUNT_ID | Yes | - | Your Chatwoot account ID |
CHATWOOT_INBOX_ID | Yes | - | The inbox ID for WhatsApp messages |
CHATWOOT_DEVICE_ID | No | - | Specific device ID for outbound messages (required for multi-device setups) |
CHATWOOT_IMPORT_MESSAGES | No | false | Enable message history sync to Chatwoot |
CHATWOOT_DAYS_LIMIT_IMPORT_MESSAGES | No | 3 | Number of days of history to import |
Configuration Examples
Chatwoot Setup
Step 1: Create an API Channel Inbox
- Log in to your Chatwoot dashboard
- Navigate to Settings > Inboxes
- Click Add Inbox
- Select API as the channel type
- Configure the inbox:
- Name: WhatsApp (or any descriptive name)
- Webhook URL: Leave empty for now (we’ll configure this in Step 4)
- Click Create Inbox
- Note down the Inbox ID (visible in the URL or inbox settings)
Step 2: Get Your API Token
- Navigate to Settings > Profile Settings
- Scroll to Access Token section
- Copy your API access token
Step 3: Find Your Account ID
Your account ID is visible in the URL when logged into Chatwoot:Step 4: Configure the Webhook
- Navigate to Settings > Integrations > Webhooks
- Click Add new webhook
- Configure:
- URL:
https://your-whatsapp-api.com/chatwoot/webhook - Events: Select
message_created
- URL:
- Click Create
Multi-Device Setup
When running with multiple WhatsApp devices, you must specify which device should handle Chatwoot outbound messages usingCHATWOOT_DEVICE_ID.
Finding Your Device ID
- Access your WhatsApp API at
http://your-api:3000 - Navigate to the device management section
- Note the Device ID of the device you want to use for Chatwoot
Configuration
- If
CHATWOOT_DEVICE_IDis not set and only one device is registered, that device will be used automatically - If
CHATWOOT_DEVICE_IDis not set and multiple devices exist, outbound messages will fail - If the specified device is not found or not connected, outbound messages will fail with a
DEVICE_NOT_AVAILABLEerror
Message History Sync
The history sync feature allows you to import existing WhatsApp message history into Chatwoot. This is useful when you want to have context from past conversations when starting to use Chatwoot.Enabling Auto-Sync
To automatically sync history when a device connects:Manual Sync via API
You can trigger a sync manually using the REST API:Sync Options
| Option | Default | Description |
|---|---|---|
days_limit | 3 | Number of days of history to import |
include_media | true | Download and sync media attachments |
include_groups | true | Include group chat messages |
How It Works
- Reads stored messages from the local chat storage database
- Creates contacts in Chatwoot for each chat participant
- Creates conversations for each chat
- Imports messages with timestamps, preserving chronological order
- Downloads and attaches media (if enabled and media is still available)
- Messages are prefixed with their original timestamp for context:
[2024-01-15 14:30] Hello! - Group messages include the sender name:
[2024-01-15 14:30] John: Hello! - Media older than ~2 weeks may be unavailable on WhatsApp servers
- The sync runs in the background and can be monitored via the status endpoint
- Only one sync can run per device at a time
Supported Features
Incoming Messages (WhatsApp → Chatwoot)
| Message Type | Supported | Notes |
|---|---|---|
| Text | ✅ | Full text content preserved |
| Images | ✅ | Displayed as attachments |
| Audio | ✅ | Displayed as attachments |
| Video | ✅ | Displayed as attachments |
| Documents | ✅ | Displayed as attachments |
| Stickers | ✅ | Displayed as image attachments |
| Location | ✅ | Shown as text with coordinates |
| Contacts | ✅ | vCard information preserved |
outgoing messages.
Outgoing Messages (Chatwoot → WhatsApp)
| Message Type | Supported | Notes |
|---|---|---|
| Text | ✅ | - |
| Images | ✅ | Sent with optional caption |
| Audio | ✅ | Sent as voice note (PTT) |
| Video | ✅ | - |
| Files | ✅ | Any file type supported |
Group Support
- Groups are automatically detected by JID format (
@g.us) - Group name is used as contact name in Chatwoot
- Replies go to the correct group chat
- Group messages include sender name prefix
Architecture
Message Flow
-
Incoming (WhatsApp → Chatwoot):
- WhatsApp message received by connected device
- Event handler processes the message
- Message forwarded to Chatwoot API
- Contact/conversation created if needed
- Message appears in Chatwoot inbox
-
Outgoing (Chatwoot → WhatsApp):
- Agent replies in Chatwoot
- Chatwoot sends webhook to
/chatwoot/webhook - Handler resolves device from
CHATWOOT_DEVICE_IDor default - Message sent via WhatsApp
- Delivery confirmed
Troubleshooting
Outbound Messages Not Sending
Symptoms: Messages typed in Chatwoot are not delivered to WhatsApp Possible Causes & Solutions:Device not specified or not found
Device not specified or not found
- Check logs for “Failed to resolve device” errors
- Ensure
CHATWOOT_DEVICE_IDis set correctly - Verify the device is registered:
curl http://your-api:3000/devices
Webhook not configured
Webhook not configured
- Verify the webhook URL in Chatwoot settings
- Ensure the URL is publicly accessible
- Check that
message_createdevent is selected
Device not logged in
Device not logged in
- Check device status:
curl http://your-api:3000/devices/{device_id}/status - Reconnect the device if disconnected
CHATWOOT_ENABLED not set
CHATWOOT_ENABLED not set
- Verify
CHATWOOT_ENABLED=truein your configuration
Incoming Messages Not Appearing in Chatwoot
Symptoms: WhatsApp messages are not showing in Chatwoot inbox Possible Causes & Solutions:Chatwoot not enabled
Chatwoot not enabled
- Verify
CHATWOOT_ENABLED=truein configuration
Invalid API credentials
Invalid API credentials
- Double-check
CHATWOOT_API_TOKEN - Verify
CHATWOOT_ACCOUNT_IDandCHATWOOT_INBOX_ID
Network connectivity
Network connectivity
- Ensure the API server can reach Chatwoot URL
- Check for firewall rules blocking outbound connections
Common Error Messages
| Error | Meaning | Solution |
|---|---|---|
DEVICE_NOT_AVAILABLE | No device found for sending | Set CHATWOOT_DEVICE_ID or ensure one device is registered |
device not found | Specified device ID doesn’t exist | Check device ID spelling and registration |
device id is required | No device ID and multiple devices exist | Set CHATWOOT_DEVICE_ID |
failed to create contact | Chatwoot API error | Verify API token and account permissions |
Invalid payload | Malformed webhook request | Check Chatwoot webhook configuration |
Debug Logging
Enable debug mode to see detailed Chatwoot integration logs:Chatwoot Webhook:- Webhook processingChatwoot:- API operations (contact/conversation/message creation)
Best Practices
Use a dedicated device
Use a separate WhatsApp device for Chatwoot integration in production
Set up monitoring
Monitor device connection status to maintain service availability
Test webhook connectivity
Verify webhook endpoint is accessible before going live
Use HTTPS
Always use HTTPS for webhook URLs in production
Set CHATWOOT_DEVICE_ID
Explicitly configure device ID in multi-device environments
Monitor logs
Keep track of failed message deliveries through log monitoring
Security Considerations
- Keep
CHATWOOT_API_TOKENsecure and rotate periodically - Use HTTPS for all webhook communications
- Consider network-level restrictions on the webhook endpoint
- Monitor for unusual activity in Chatwoot logs
- Use strong authentication for the WhatsApp API (
APP_BASIC_AUTH)
