Overview
VoicePact receives real-time notifications from Africa’s Talking through webhooks for voice calls, SMS delivery, payment status, and other events. This guide covers webhook configuration, security, and implementation.Webhook Architecture
Event Flow
Webhook Types
VoicePact handles four types of webhooks:| Type | Endpoint | Purpose | Source File |
|---|---|---|---|
| Voice | /api/v1/voice/webhook | Call recordings, status | app/api/v1/endpoints/voice.py:223 |
| SMS | /api/v1/sms/webhook | Delivery reports, replies | app/api/v1/endpoints/sms.py:293 |
| Payment | /api/v1/payments/webhook | Payment confirmations | app/api/v1/endpoints/payments.py:96 |
| USSD | /api/v1/ussd/ | Interactive sessions | app/api/v1/endpoints/ussd.py:19 |
Configuration
Environment Variables
Configuration Class
Fromapp/core/config.py:172-182:
Africa’s Talking Dashboard Setup
- Login to Africa’s Talking dashboard
- Navigate to your application settings
- Configure webhook URLs:
- Voice callback:
https://your-domain.com/api/v1/voice/webhook - SMS delivery reports:
https://your-domain.com/api/v1/sms/webhook - Payment notifications:
https://your-domain.com/api/v1/payments/webhook - USSD callback:
https://your-domain.com/api/v1/ussd/
- Voice callback:
Webhook Security
Signature Verification
All webhooks should be verified using HMAC signatures:Implementation
Fromapp/services/africastalking_client.py:119-129:
Usage in Endpoints
Best Practices
- Always verify signatures in production
- Use HTTPS for webhook endpoints
- Rotate secrets regularly
- Log suspicious requests
- Implement rate limiting
- Return 200 OK quickly to avoid retries
Voice Webhooks
Endpoint Configuration
Endpoint:POST /api/v1/voice/webhook
Location: app/api/v1/endpoints/voice.py:223-258
Payload Format
Africa’s Talking sends voice webhooks with the following data:Implementation
Voice Status Codes
| Status | Description |
|---|---|
Completed | Call completed successfully |
Answered | Call was answered |
NotAnswered | Call not answered |
Busy | Line was busy |
InvalidPhoneNumber | Invalid number format |
Processing Recording
After receiving a voice webhook, process the recording:SMS Webhooks
Endpoint Configuration
Endpoint:POST /api/v1/sms/webhook
Location: app/api/v1/endpoints/sms.py:293-328
Payload Formats
Incoming SMS
Delivery Report
Implementation
Handling Incoming SMS
SMS Status Codes
| Status | Description |
|---|---|
Success | Message delivered successfully |
Sent | Message sent to carrier |
Queued | Message queued for sending |
Failed | Delivery failed |
Rejected | Message rejected by carrier |
Payment Webhooks
Endpoint Configuration
Endpoint:POST /api/v1/payments/webhook
Location: app/api/v1/endpoints/payments.py:96-136
Payload Format
Successful Payment
Failed Payment
Implementation
Payment Status Codes
| Status | Description |
|---|---|
Success | Payment completed successfully |
PendingConfirmation | Awaiting user PIN entry |
PendingValidation | Being validated by provider |
Failed | Payment failed |
Cancelled | User cancelled payment |
USSD Webhooks
Endpoint Configuration
Endpoint:POST /api/v1/ussd/
Location: app/api/v1/endpoints/ussd.py:19-61
Payload Format
Implementation
USSD Response Format
USSD responses must be plain text with special prefixes:CON: Continue session (show menu, wait for input)END: End session (final message)
Webhook Processing
Data Processing
Process and normalize webhook data:Error Handling
Webhook Failures
Retry Logic
Africa’s Talking will retry webhooks if they receive:- Non-2xx status codes
- Timeouts (>30 seconds)
- Connection errors
Testing Webhooks
Local Testing with ngrok
- Install ngrok:
- Start your server:
- Create tunnel:
- Configure webhook URL:
Manual Testing
Test webhooks manually using curl:Webhook Testing Tools
- Webhook.site: https://webhook.site (inspect payloads)
- RequestBin: https://requestbin.com (capture requests)
- Postman: Test webhook endpoints locally
Monitoring
Logging
Metrics
Track webhook metrics:Troubleshooting
Webhooks Not Received
- Check URL accessibility:
- Verify webhook configuration in AT dashboard
- Check firewall rules - allow AT IP ranges
- Review application logs for errors
- Test with ngrok for local development
Invalid Signatures
- Verify webhook secret matches AT dashboard
- Check signature header name and format
- Ensure raw body is used for verification
- Test signature locally:
Webhook Timeouts
- Return 200 quickly - process asynchronously
- Use background tasks for heavy processing
- Optimize database queries
- Add request timeout monitoring
Best Practices
- Return 200 OK quickly: Process webhooks asynchronously
- Verify all signatures: Never skip signature verification in production
- Use idempotency: Handle duplicate webhooks gracefully
- Log everything: Comprehensive logging helps debugging
- Monitor failures: Track failed webhooks for manual review
- Test thoroughly: Test with actual AT sandbox before production
- Handle retries: AT will retry failed webhooks
- Validate data: Don’t trust webhook data blindly
- Use HTTPS: Never use HTTP in production
- Set timeouts: Don’t let webhook processing block
Next Steps
Africa's Talking
Core integration documentation
Mobile Money
Payment webhook details
Voice Processing
Voice webhook handling
API Reference
Webhook API documentation