StatusCallBackEvent in Twilio returns none

亡梦爱人 提交于 2021-01-29 18:11:54

问题


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()

    

来源:https://stackoverflow.com/questions/63776883/statuscallbackevent-in-twilio-returns-none

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!