Overview
The Twilio integration enables:- SMS messaging via Twilio
- WhatsApp messaging via Twilio
- AI-powered responses to customer messages
- Bidirectional communication (send and receive)
- Multi-channel support alongside other channels
Setup
Step 1: Create Twilio Account
- Go to twilio.com and sign up
- Complete account verification
- Get your Account SID and Auth Token from the dashboard
Step 2: Get Phone Numbers
For SMS
- In Twilio Console, go to Phone Numbers → Buy a number
- Select a number with SMS capability
- Purchase the number
For WhatsApp
- Go to Messaging → Try it out → Send a WhatsApp message
- Use the Sandbox number for testing (starts with
whatsapp:+) - For production, request WhatsApp approval from Twilio
Step 3: Configure Webhooks
SMS Webhook
- In Twilio Console, go to your phone number
- Under Messaging, set Webhook URL:
- Set HTTP method to POST
WhatsApp Webhook
- Go to Messaging → Try it out → Send a WhatsApp message
- Set When a message comes in webhook:
- Set HTTP method to POST
Step 4: Configure in Support Unicorn
- Navigate to your Support Unicorn instance
- Go to Settings → Integrations → Twilio
- Enter:
- Account SID
- Auth Token
- From phone number (SMS)
- WhatsApp number (if using WhatsApp)
- Click “Save”
How It Works
Sending Messages
Messages are sent automatically by your AI agent when:- Responding to customer inquiries on SMS or WhatsApp channels
- Following up on escalated conversations
- Executing procedures that trigger message actions
Receiving Messages
When a customer sends a message:- Twilio sends a webhook to Support Unicorn
- The message is processed by
LiveChatService - If AI is enabled, the agent responds automatically
- Response is sent back via Twilio
AI Agent Integration
- Create or select an Agent
- Configure knowledge base
- Link agent to Configuration
- AI will respond to incoming messages
Routes
| Route | Method | Description |
|---|---|---|
/twilio/sms/send/:organization_id/:from | POST | Send SMS message |
/twilio/sms/webhook/:channel_id | POST | Receive SMS webhook |
/twilio/whatsapp/send/:organization_id/:from | POST | Send WhatsApp message |
/twilio/whatsapp/webhook/:channel_id | POST | Receive WhatsApp webhook |
Configuration
Environment Variables
Channel Configuration
Each channel can be configured with:- Phone number (SMS or WhatsApp)
- Organization mapping
- Configuration (for AI agent)
Troubleshooting
Messages not sending
- Verify Account SID and Auth Token
- Check phone number is correct format (E.164)
- Verify webhook URL is accessible
- Check Twilio logs for errors
Not receiving messages
- Verify webhook is configured in Twilio
- Check webhook URL is correct
- Ensure SSL certificate is valid (HTTPS required)
- Review Rails logs for webhook errors
WhatsApp Sandbox
For testing WhatsApp, you need to:- Join the Twilio Sandbox (send code to Twilio number)
- Use sandbox number format:
whatsapp:+14155238886 - For production, request WhatsApp approval
Best Practices
- Rate limiting: Be mindful of Twilio rate limits
- Message length: SMS has 160 character limit (use concatenation for longer)
- Error handling: Implement retry logic for failed sends
- Webhook security: Validate webhook signatures (future enhancement)
Next Steps
Google Integration
Connect with Google services