问题描述
我正在尝试触发呼叫并获取该呼叫的实时状态更新。我可以通过访问网站来触发呼叫,但是在弄清楚如何通过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 (将#修改为@)