Overview
Webhooks are HTTP callbacks that Africa’s Talking uses to notify your application about events like SMS delivery, incoming messages, voice call events, and more. This guide walks you through configuring webhook URLs for each Africa’s Talking service.Prerequisites
Before configuring webhooks, ensure you have:- An Africa’s Talking account with an active app
- Your Flask application running locally (default port: 9000)
- A tunneling service running (ngrok, cloudflared, or localhost.run)
- Your public tunnel URL (e.g.,
https://abc123.ngrok.io)
Make sure your tunnel is running before configuring webhooks. Keep the tunnel running while testing to avoid connection failures.
Webhook URL Patterns
Based on your Flask application, here are all the webhook endpoints:SMS Endpoints
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| Delivery Reports | /api/sms/delivery-reports | Receive SMS delivery status updates |
| Two-way SMS | /api/sms/twoway | Receive incoming SMS messages |
| Opt-out | /api/sms/opt-out | Handle SMS unsubscribe requests |
| Subscription | /api/sms/subscription | Handle premium SMS subscriptions |
Voice Endpoints
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| Call Instructions | /api/voice/instruct | Provide call flow instructions (XML) |
| Voice Events | /api/voice/events | Receive call event notifications |
Airtime Endpoints
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| Validation | /api/airtime/validation | Validate airtime requests |
| Status Callback | /api/airtime/status | Receive airtime delivery status |
SIM Swap Endpoints
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| Status Callback | /api/sim-swap/status | Receive SIM swap check results |
USSD Endpoints
| Endpoint | URL Pattern | Purpose |
|---|---|---|
| Session Callback | /api/ussd/session | Handle USSD session interactions |
| Status Notification | /api/ussd/status | Receive session end notifications |
Configuring SMS Webhooks
Access Your App Settings
- Log in to Africa’s Talking Dashboard
- Select your team from the dropdown
- Click on your application (or create a new one)
- Navigate to SMS → Settings
Configure Delivery Reports URL
In the Delivery Report URL field, enter:Example:This endpoint receives notifications about SMS delivery status (Sent, Delivered, Failed, etc.)
Configure Two-way SMS URL
In the Incoming Messages URL field, enter:Example:This endpoint receives incoming SMS messages sent to your shortcode.
Configure Opt-out URL (Optional)
If using bulk SMS, set the Opt-out URL:This receives notifications when users unsubscribe from your messages.
Configure Subscription URL (Optional)
For premium SMS services, set the Subscription URL:This handles subscription additions and deletions.
Testing SMS Webhooks
After configuration, test your SMS webhooks:http://127.0.0.1:4040) to see the delivery report webhook.
Configuring Voice Webhooks
Access Voice Settings
- In your Africa’s Talking dashboard, navigate to Voice → Settings
- Ensure you have a voice-enabled phone number assigned
Configure Call Instructions URL
In the Call Instructions URL field, enter:Example:This endpoint provides XML instructions when a call is answered.
Configure Event Notification URL
In the Event Notification URL field, enter:Example:This endpoint receives call event notifications (answered, completed, failed, etc.).
Testing Voice Webhooks
Test your voice configuration:/api/voice/instruct endpoint.
Voice Instructions Response Format
Your/api/voice/instruct endpoint must return XML:
Configuring Airtime Webhooks
Configure Validation URL
In the Validation URL field, enter:This endpoint validates airtime requests before they’re processed.
Configure Status Callback URL
In the Status Callback URL field, enter:This receives airtime delivery status notifications.
Testing Airtime Webhooks
Validation Endpoint Request Format
Your validation endpoint receives:Status Callback Request Format
Your status endpoint receives:Configuring SIM Swap Webhooks
Access SIM Swap Settings
Navigate to your SIM Swap service settings in the Africa’s Talking dashboard.
Testing SIM Swap Webhooks
Status Callback Format
Configuring USSD Webhooks
Configure Session Callback URL
Set your USSD callback URL to:This endpoint handles USSD session interactions.
Configure Status Notification URL
Set the status notification URL to:This receives end-of-session notifications.
USSD Response Format
Your USSD session endpoint must return text responses:CON- Continue the session (show menu)END- End the session (final message)
Webhook Security Best Practices
Validating Webhook Sources
Add validation to ensure requests come from Africa’s Talking:Logging Webhook Payloads
The application already logs webhooks, but you can enhance logging:Monitoring Webhooks with ngrok
ngrok’s web interface (http://127.0.0.1:4040) is invaluable for debugging webhooks:
Accessing the Dashboard
- Ensure ngrok is running
- Open
http://127.0.0.1:4040in your browser - View all incoming requests in real-time
Features
- Request inspection: See headers, body, and query parameters
- Response inspection: View your application’s responses
- Replay requests: Resend previous requests for testing
- Filter and search: Find specific webhook calls
Troubleshooting Webhooks
Webhooks Not Received
Problem: Africa’s Talking sends webhooks but your application doesn’t receive them. Solutions:-
Verify tunnel is running:
-
Check webhook URL configuration:
- Ensure URLs in dashboard exactly match your endpoints
- Verify HTTPS is used
- Check for typos in paths
-
Test endpoint directly:
-
Check ngrok dashboard for incoming requests at
http://127.0.0.1:4040
404 Not Found Errors
Problem: Webhooks return 404 errors. Solutions:- Verify route paths in your Flask application match webhook URLs
- Check that blueprints are registered correctly
- Ensure Flask app is running
405 Method Not Allowed
Problem: Webhook returns 405 error. Solutions:-
Ensure your route accepts POST requests:
- Africa’s Talking sends most webhooks via POST, not GET
Timeouts
Problem: Africa’s Talking times out waiting for your response. Solutions:- Respond quickly (within 10 seconds)
- Process heavy tasks asynchronously
- Return “OK” immediately, then process in background
Invalid Responses
Problem: Webhooks fail due to invalid response format. Solutions:-
Voice endpoints must return XML with
text/plainmimetype: -
USSD endpoints must return plain text starting with
CONorEND: -
Other webhooks should return
"OK"with status 200:
Testing Webhook Configuration
After configuring all webhooks, run comprehensive tests:1. Test All Endpoints
2. Verify Webhook Receipts
Check your terminal for log output and ngrok dashboard for incoming webhooks.3. Test Error Handling
Send invalid requests to ensure error handling works:Production Considerations
Example Production URLs
Instead of:Next Steps
Now that your webhooks are configured:- Test your endpoints thoroughly with various scenarios
- Implement error handling and retry logic
- Set up logging and monitoring
- Review the API reference for detailed webhook payload formats
