Reputation: 3564
I want to print/get the incoming caller number in Twilio Flask app. I was referring to the twilio-ivr-phone-tree for this. I tried print(request.args)
in the welcome
function i.e the first method which is invoked when I receive an incoming call. But it prints an empty ImmutableMultiDict([])
.
Am I missing something? Any help is appreciated. Thanks in advance.
To -ve voters, post a comment for doing so. It helps to increase the quality of the question and make stack a better place.
Upvotes: 0
Views: 491
Reputation: 1898
The incoming call request information can be obtained in a Flask app using request.values
these are they keys of the diction returned: atts = ('AccountSid', 'ApiVersion', 'CallSid', 'CallStatus', 'Called', 'CalledCity', 'CalledCountry', 'CalledState', 'CalledZip', 'Caller', 'CallerCity', 'CallerCountry', 'CallerState', 'CallerZip', 'Direction', 'From', 'FromCity', 'FromCountry', 'FromState', 'FromZip', 'To', 'ToCity', 'ToCountry', 'ToState', 'ToZip')
Upvotes: 1
Reputation: 3564
The main problem is the Twilio request has a form content type and the raw data will be consumed leading it to appear empty as described in this answer.
However request.get_data()
can print the whole POST and you can easily find that the key From
holds the caller's phone number.
So, to access it you need request.form['From']
and it fetches the caller's number to the local environment.
Upvotes: 0