Complete installation and configuration guide for the Africa’s Talking AI Integration Course
This guide will walk you through setting up your development environment, installing dependencies, configuring API credentials, and exposing your local server for webhooks.
Install ngrok, Cloudflare Tunnel, or localhost.run
Production vs Sandbox: Voice calls and some advanced features require a production Africa’s Talking account. You can start with the sandbox for SMS testing.
Create an isolated Python environment for the project:
python3 -m venv venvsource venv/bin/activate
When the virtual environment is active, you’ll see (venv) at the beginning of your terminal prompt.
3
Install dependencies
Install all required Python packages using the Makefile:
make install
This installs the following packages from requirements.txt:
Flask==3.0.2 # Web frameworkrequests==2.32.3 # HTTP libraryafricastalking==1.2.6 # Africa's Talking SDKgoogle-api-core # Google Cloud base librarygoogle-cloud-aiplatform # Vertex AI SDKruff==0.4.0 # Linter and formatter
If you don’t have make installed, you can install dependencies directly:
Create a .env file in the project root directory with your API credentials:
1
Copy the example file
cp .env.example .env
2
Edit the .env file
Open .env in your text editor and configure the following variables:
.env
# Flask ConfigurationFLASK_ENV=developmentPORT=9000# Africa's Talking CredentialsAT_USERNAME=sandbox # Use 'sandbox' for testing, or your production usernameAT_API_KEY=your_africastalking_api_key_hereAT_VOICE_NUMBER=+254XXXXXXXXX # Your voice-enabled number (production only)AT_SHORTCODE=8995 # Your shortcode for two-way SMS (if applicable)# Google Cloud CredentialsPROJECT_ID=your_gcp_project_idGEMINI_API_KEY=your_gemini_api_key_hereVERTEX_API_KEY=your_vertex_api_key_here# Ngrok Configuration (optional)NGROK_AUTHTOKEN=your_ngrok_auth_token_here
You should see output confirming the server is running:
✅ Registered airtime at /api/airtime✅ Registered sim-swap at /api/sim-swap✅ Registered sms at /api/sms✅ Registered ussd at /api/ussd✅ Registered voice at /api/voice * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:9000
The server runs on port 9000 by default. You can change this by updating the PORT variable in your .env file.
Sign up at ngrok.com to get an auth token, then run:
ngrok authtoken YOUR_NGROK_AUTH_TOKEN
3
Start the tunnel
Expose your Flask server (running on port 9000):
ngrok http 9000
Or use the Makefile:
make tunnel
You’ll see output like this:
Session Status onlineAccount [email protected]Version 3.x.xRegion United States (us)Forwarding https://abc123def456.ngrok-free.app -> http://localhost:9000
Keep ngrok running in a separate terminal window. If you close it, your webhooks will stop working.
4
Note your public URL
Copy the https:// forwarding URL (e.g., https://abc123def456.ngrok-free.app). You’ll need this for webhook configuration.
Your Google Cloud project has Vertex AI API enabled
Billing is enabled on your project
You have proper authentication set up
CORS errors (when building a frontend)
Solution:
Install Flask-CORS and enable it in app.py:
pip install flask-cors
from flask import Flaskfrom flask_cors import CORSfrom routes import register_routesapp = Flask(__name__)CORS(app) # Enable CORS for all routesregister_routes(app)