Reputation: 13
I am new to twilio python and flask. I tried to follow the twilio example for tracking sms status, but as I mentionned I get none
as the return for this statement status=request.values.get('callstatus', None)
.
I want to track the call progress status and see its different status. I follow all the documentation but I am blocked. Thanks for your help.
from flask import Flask,request
from twilio.rest import Client
from twilio.twiml.voice_response import Dial, VoiceResponse
from pprint import pprint
import logging
logging.basicConfig(level=logging.INFO)
app = Flask(__name__)
twilioClient = Client('*******************', '*****************************')
@app.route("/voice")
def voice():
call=twilioClient.calls.create(
method='GET',
status_callback='http://*****.ngrok.io/response',
status_callback_event='initiated ringing answered completed',
status_callback_method='POST',
from_='+**********',
to='+*********',
url='http://demo.twilio.com/docs/voice.xml''
)
return call.sid
@app.route('/response', methods=['POST'])
def outbound():
status=request.values.get('callstatus', None)
logging.info('Status: {}'.format(status))
return ('', 204)
if __name__ == "__main__":
app.run(debug=true)
Upvotes: 1
Views: 733
Reputation: 287
I understand that this is a relatively old post and that you might have figured out the solution as of now, but still I am posting my answer so that it will benefit other users who may face the same issue in future.
There are 2 issues that I can see in the code posted above:
When you are making a request to the twilio server by using the API twilioClient.calls.create(), you are feeding the status_callback_event parameter with a single string.
Instead of passing a single string, you have to pass a list of strings like: ['initiated', 'answered', 'ringing', 'completed']
The parameter sent by twilio to the call back url is CallStatus and not callstatus. They are case sensitive.
status=request.values.get('CallStatus', None)
You can refer this link to check out all the call resources
Upvotes: 1