如何解决Twilio CallBackStatus和烧瓶
我正在尝试触发呼叫并获取该呼叫的实时状态更新。我可以通过访问网站来触发呼叫,但是在弄清楚如何通过CallBackStatus发出的呼叫上实时接收更新时遇到了问题。设置CallBackStatus URL时-twilio应该提供有关呼叫状态的实时更新,包括启动,响铃,应答和完成。我在ngrok转发网址中输入“ / events”,以为信息将发送到该网址,但我看不到。如何在我的flask&ngrok应用程序中从Twilio获取实时呼叫状态更新?
from flask import Flask,request
from twilio.twiml.voice_response import VoiceResponse
from twilio.rest import Client
import time
app = Flask(__name__)
client = Client("ENTER ACCOUNT SID","ENTER ACCOUNT TOKEN")
NGROK_BASE_URL = 'ENTER NGROJK FORWARDING URL HERE'
from_="ENTER TWILIO NUMBER HERE" # twilio number
to = 'ENTER NUMBER TO CALL HERE' # number to call
@app.route('/')
def index():
"""Returns standard text response to show app is working."""
return "Twilio Flask app up and running!"
@app.route('/twiml',methods=['GET','POST'])
def twiml_response():
"""Provides TwiML instructions in response to a Twilio POST webhook
event so that Twilio knows how to handle the outbound phone call
when someone picks up the phone.
"""
response = VoiceResponse()
response.say('hello Daman!!!!')
return str(response)
@app.route('/dial-phone',methods=['GET'])
def outbound_call():
"""Uses the Twilio Python helper library to send a POST request to
Twilio telling it to dial an outbound phone call from our
specific Twilio phone number (that phone number must be owned by our
Twilio account).
"""
# the url must match the Ngrok Forwarding URL plus the route defined in
# the previous function that responds with TwiML instructions
client.calls.create(method='Post',to=to,from_=from_,url=NGROK_BASE_URL + '/events',status_callback_event='initiated ringing answered completed',status_callback=NGROK_BASE_URL + '/events',status_callback_method='POST',)
return 'phone call placed to ' + to + '!'
# TODO find out how to get callback events - NOT WORKING
@app.route('/events','POST'])
def twiml_response():
all_call_info = request.values
print(all_call_info)
call_status = request.values.get('CallStatus','')
print(call_status)
time.sleep(5)
print(call_status)
time.sleep(5)
print(call_status)
time.sleep(5)
return call_status
if __name__ == '__main__':
app.run()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。