Overview
To receive webhooks from Africa’s Talking, your local development server must be accessible from the internet. Tunneling tools create a secure connection between a public URL and your local server, allowing external services to reach your endpoints.Why Tunneling is Required
Africa’s Talking sends webhook notifications (SMS delivery reports, voice events, etc.) to your configured callback URLs. Since these services run on Africa’s Talking’s servers, they can’t reachlocalhost on your development machine. Tunneling solves this by:
- Creating a public HTTPS URL that forwards to your local server
- Providing secure encrypted connections
- Allowing real-time testing of webhooks during development
For production deployments, you’ll deploy your application to a server with a public IP address or domain, eliminating the need for tunneling.
Tunneling Options
This guide covers three popular tunneling solutions:- ngrok - Feature-rich, reliable, with a free tier
- Cloudflare Tunnel (cloudflared) - Free, no account required for basic use
- localhost.run - Simple SSH-based tunneling, no installation needed
Option 1: ngrok (Recommended)
ngrok is the most popular and feature-rich tunneling solution, offering a generous free tier with persistent URLs on paid plans.Installation
Download ngrok
Visit ngrok.com and download the version for your operating system.For macOS (using Homebrew):For Linux:For Windows:
Download the ZIP file from the ngrok website and extract it to a folder in your PATH.
Authenticate ngrok
Run the following command with your authentication token:This saves your token to
~/.ngrok2/ngrok.yml and authenticates all future sessions.Starting ngrok
Once installed and authenticated, start ngrok to tunnel to your Flask application:Replace
9000 with the port number your Flask app is running on (check your .env file’s PORT variable).Understanding ngrok Output
When ngrok starts, you’ll see output like this:- Forwarding URL:
https://abc123.ngrok.io- This is your public URL - Web Interface:
http://127.0.0.1:4040- ngrok’s local dashboard for monitoring requests
Using Your ngrok URL
Your public URL will be in the format:https://abc123.ngrok.io
To access your Flask endpoints through ngrok:
ngrok Advanced Features
Custom Subdomain (Paid Plans)
https://my-at-webhook.ngrok.io
Configuration File
Create~/.ngrok2/ngrok.yml for persistent configuration:
Regional Endpoints
For better performance in Africa:us, eu, ap, au, sa, jp, in
Option 2: Cloudflare Tunnel
Cloudflare Tunnel (cloudflared) is a free alternative that doesn’t require an account for basic use.Installation
Install cloudflared
For macOS (using Homebrew):For Linux (Debian/Ubuntu):For Windows:
Download from Cloudflare’s release page
Understanding cloudflared Output
https://abc-def-123.trycloudflare.com
Cloudflare quick tunnels generate random URLs each time. For persistent URLs, you need to create a Cloudflare account and configure a named tunnel.
Persistent Cloudflare Tunnel (With Account)
Option 3: localhost.run
localhost.run is the simplest option, using SSH tunneling with no installation required.Usage
Simply run this SSH command:-R 80:localhost:9000- Forward remote port 80 to local port 9000[email protected]- Connect without SSH keys
Output
- HTTP:
http://abc123.localhost.run - HTTPS:
https://abc123.localhost.run
Custom Subdomain
https://my-tunnel.localhost.run (availability not guaranteed)
Comparison of Tunneling Solutions
| Feature | ngrok | Cloudflare Tunnel | localhost.run |
|---|---|---|---|
| Installation | Required | Required | Not required |
| Account Required | Yes (free tier) | No (for quick tunnels) | No |
| Persistent URLs | Paid plans only | With account | No |
| HTTPS | Yes (automatic) | Yes (automatic) | Yes (automatic) |
| Web Dashboard | Yes | Via Cloudflare account | No |
| Request Inspection | Yes | Via logs | No |
| Custom Domains | Paid plans | With account | Limited |
| Stability | Excellent | Excellent | Good |
| Best For | Development & debugging | Production-like setups | Quick tests |
Configuring Your Application
Testing Your Tunnel
After starting your tunnel, test that it works:Using the Tunnel URL with Africa’s Talking
Once your tunnel is running, you’ll use the public URL to configure webhooks in Africa’s Talking dashboard. For example, if your ngrok URL ishttps://abc123.ngrok.io, your webhook URLs will be:
- SMS Delivery Reports:
https://abc123.ngrok.io/api/sms/delivery-reports - SMS Two-way:
https://abc123.ngrok.io/api/sms/twoway - Voice Instructions:
https://abc123.ngrok.io/api/voice/instruct - Voice Events:
https://abc123.ngrok.io/api/voice/events - Airtime Validation:
https://abc123.ngrok.io/api/airtime/validation - Airtime Status:
https://abc123.ngrok.io/api/airtime/status
Troubleshooting
Tunnel Not Starting
Problem: ngrok or cloudflared fails to start. Solutions:- Verify you’ve authenticated (ngrok only)
- Check that the port isn’t already in use
- Ensure your Flask app is running before starting the tunnel
- Check firewall settings
502 Bad Gateway Errors
Problem: Accessing the tunnel URL returns a 502 error. Solutions:- Verify your Flask application is running
- Check that you’re tunneling to the correct port
- Ensure the Flask app is binding to
0.0.0.0, not just127.0.0.1
Webhooks Not Received
Problem: Africa’s Talking webhooks aren’t reaching your application. Solutions:- Verify the webhook URLs in Africa’s Talking dashboard are correct
- Check ngrok’s web interface (
http://127.0.0.1:4040) to see if requests are arriving - Ensure your routes match the configured webhook paths exactly
- Check for HTTPS (Africa’s Talking requires HTTPS for webhooks)
Tunnel URL Changes
Problem: The tunnel URL changes every time you restart. Solutions:- ngrok: Upgrade to a paid plan for persistent URLs
- Cloudflare: Set up a named tunnel with an account
- Update webhook URLs in Africa’s Talking dashboard after each restart
Rate Limits or Throttling
Problem: Getting rate limit errors or slow responses. Solutions:- ngrok free tier: Limited to 40 requests/minute
- Upgrade to a paid plan for higher limits
- Use Cloudflare Tunnel as an alternative
Security Considerations
Request Authentication
Consider adding authentication to your webhook endpoints:IP Whitelisting
Africa’s Talking provides IP ranges for their webhook servers. You can restrict access to only these IPs in production.Next Steps
Now that your local server is accessible from the internet:- Configure webhook URLs in the Africa’s Talking dashboard
- Test your endpoints to ensure webhooks are received correctly
- Learn about environment setup for managing secrets
