VOICE
Making a call
We will be making an outgoing call from a script running in the projectName folder. We create this folder in the Setup and Dependencies section.
You should have a virtual number that you create on the sandbox.
In the projectName folder, create a script Voice.py and copy-paste the code below. In the code, we are implementing a call in the following way:
- Import the AfricasTalking gateway class installed cia pip.
- Define the number(caller ID) that is dialing to the user.
- Define the recipient of the call as a comma-separated list.
- Create an instance of the Gateway class and pass in your API credentials
- Call the call() method and pass in the caller number and the recipient number to initiate the call
#-> projectName/Voice.py
#import our API wrapper
from africastalking.AfricasTalkingGateway import AfricasTalkingGateway,AfricasTalkingGatewayException
#specify the caller ID
callFrom = "+254711082XYZ"
# Specify the numbers that you want to call
callTo = "+254711XXXYYY,+254733YYYZZZ"
# Create a new instance of gateway class
gateway = AfricasTalkingGateway(username, apikey, "sandbox")
try:
# Make the call
results = gateway.call(callFrom, callTo)
#see the results
for result in results:
# Only status "Queued" means the call was successfully placed
print "Status : %s; phoneNumber : %s " % (result['status'],result['phoneNumber'])
Fire up the simulator, register the same number as the number in your script ('+254733YYYZZZ') and you should see the call appear in the simulator.
Run your code to interact with the simulator:
python Voice.py