Prerequisites
Before you begin, make sure you have:- Completed the environment setup
- Flask server running on
http://localhost:9000 - Valid Africa’s Talking credentials in your
.envfile - A phone number to test with (in international format:
+254XXXXXXXXX)
Send Your First SMS
The SMS API allows you to send bulk SMS messages to one or more recipients using a simple GET request.Start your Flask server
Make sure your Flask application is running:You should see output confirming the server is running:
Send an SMS via the API
Use curl or your browser to send an SMS. Replace
YOUR_PHONE_NUMBER with your actual phone number:The
phone parameter should be in international format without the + symbol (e.g., 254712345678 for Kenya).How it Works
The SMS endpoint is defined inroutes/sms.py:13-31:
send_bulk_sms() function from utils/sms_utils.py:55-75 handles the actual API call:
Make Your First Voice Call
The Voice API allows you to initiate outbound calls programmatically.Initiate a voice call
Use curl or your browser to make a call. Replace
YOUR_PHONE_NUMBER with the recipient’s number:Check the response
You should receive a confirmation that the call was initiated:The recipient should receive a call shortly. When they answer, they’ll hear the message configured in your
/api/voice/instruct webhook.How it Works
The voice call endpoint is defined inroutes/voice.py:12-29:
make_call() function from utils/voice_utils.py:20-45 handles the API call:
Understanding Webhooks
Both SMS and Voice APIs use webhooks to send you real-time notifications about events:SMS Webhooks
- Delivery Reports (
POST /api/sms/delivery-reports) - Notifies you when an SMS is delivered or fails - Two-Way SMS (
POST /api/sms/twoway) - Receives incoming SMS messages sent to your shortcode
Voice Webhooks
- Call Instructions (
POST /api/voice/instruct) - Provides XML instructions when a call is answered - Call Events (
POST /api/voice/events) - Receives events like call started, ended, failed, etc.
To receive webhooks locally, you need to expose your Flask server to the internet using a tunneling tool like ngrok. See the Setup Guide for details.
Next Steps
Now that you’ve sent your first SMS and made your first call, you can:Explore SMS Features
Learn about two-way SMS, delivery reports, and premium SMS subscriptions
Build Voice Apps
Create interactive voice menus, record calls, and handle DTMF input
Integrate AI
Use Google Gemini to add AI-powered responses to SMS and voice interactions
Troubleshooting
Resolve common issues and errors
Common Issues
Error: Missing 'phone' query parameter
Error: Missing 'phone' query parameter
Make sure you’re passing the
phone parameter in the URL:Error: Missing Africa's Talking credentials
Error: Missing Africa's Talking credentials
Ensure your Restart your Flask server after updating the
.env file contains valid credentials:.env file.SMS not received
SMS not received
- Check that the phone number is in the correct format (254XXXXXXXXX without the +)
- Verify you have sufficient credits in your Africa’s Talking account
- Check the API response for error messages
- Ensure you’re using a valid destination number (some countries/networks may be restricted)
Voice call not working
Voice call not working
- Voice calls require a production account (sandbox doesn’t support voice)
- Verify
AT_VOICE_NUMBERis set and is a valid voice-enabled number - Check that you have sufficient credits for voice calls
- Ensure your webhook URLs are configured in the Africa’s Talking dashboard
