I am trying to create a small app with Twilio and Flask to make outbound calls, and execute certain code based on the statusCallBackEvent.
When I print the statusCallBackEvent in terminal, it returns None even though the call’s rining , answered, or hung up. On the localhost website that I tunnel with ngrok, it shows “call made” on the main page, and “catching the response” on /response page.
Should the page reload each time a new event is fired?
Could someone teach me what I am doing wrong, and what code/language I need to include in order to catch and print the event real time (preferably in python)?
from twilio.rest import Client from threading import Timer from flask import Flask, Response, request, render_template # Your Account Sid and Auth Token from twilio.com/console # DANGER! This is insecure. See http://twil.io/secure account_sid = 'XXXXXXXXXX' auth_token = 'XXXXXXXXXX' status_callback_url = ' http://website.ngrok.io' client = Client(account_sid, auth_token) app = Flask(__name__) @app.route('/', methods=('GET','POST')) def voice(): call = client.calls.create(twiml='<Response><Say>Ahoy, World!</Say></Response>', to='+XXXXXXXXXX', from_='XXXXXXXXX', status_callback= status_callback_url, status_callback_method='POST', status_callback_event =('answered','completed','ringing')) print("Inside voice") return "call made" @app.route('/response', methods=('GET','POST')) def outbound(): print("PHONE STATUS1") status = request.values.get('CallStatus',None) print(status) print("PHONE STATUS2") return "catching the response" if __name__ == '__main__': app.debug = True app.run()