Testing Twilio Integration Locally
This guide covers setting up Twilio WhatsApp integration for local development.
Prerequisites
- Twilio account with a phone number (or Twilio Sandbox for WhatsApp)
- ngrok installed (https://ngrok.com/download)
1. Expose Local Server with ngrok
Start your Django server with a public URL:
invoke runserver --public
This generates a public HTTPS URL like https://abc123.ngrok.io.
2. Create Messaging Provider
- Go to Team Settings → Messaging Providers
- Click Add and select Twilio as the provider type
- Enter your Twilio Account SID and Auth Token
3. Create Channel on Bot
- Navigate to your bot/experiment
- Go to Channels and add a new WhatsApp channel
- Select your Twilio messaging provider
- Note the webhook URL displayed
4. Configure Twilio Webhook
- Go to Twilio Console
- Navigate to your phone number settings (Messaging -> Senders -> WhatsApp senders)
- Under Messaging Endpoint Configuration, set the webhook URL:
- URL format:
https://<your-ngrok-subdomain>.ngrok.io/channels/twilio/<channel-id>/incoming/ - Set the HTTP method to POST
Important: The callback URL must use your ngrok domain, not localhost.
Troubleshooting
- Webhook not receiving messages: Verify ngrok is running and the URL matches exactly
- Signature validation errors: Ensure the Auth Token in OCS matches your Twilio account and that Django is using HTTPS for generating abosulte URLs.
- Voice transcription failing: Check voice provider credentials and that the provider supports transcription