英文:
Forward unanswered calls in Twilio using python
问题
以下是代码部分的翻译:
有人能够捕获Twilio的DialCallStatus吗?它在许多Twilio在线文档中被提到,但我在调试Python脚本时从未看到过。我只看到CallStatus,例如在request.values的以下转储中。
REQUEST VALUES >>> CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([('AccountSid', 'ACxxxxxxx'), ('ApiVersion', '2010-04-01'), ('CallSid', 'CA0c9f4e7eb73dfcd72f273451c6aa249c'), ('**CallStatus', 'in-progress**'), ('Called', '+1785xxxxxxx'), ('CalledCity', 'TOPEKA'), ('CalledCountry', 'US'), ('CalledState', 'KS'), ('CalledZip', '66603'), ('Caller', '+1630xxxxxxx'), ('CallerCity', 'ROSELLE'), ('CallerCountry', 'US'), ('CallerState', 'IL'), ('CallerZip', '60193'), ('Digits', '1'), ('Direction', 'inbound'), ('FinishedOnKey', ''), ('From', '+1630xxxxxxx'), ('FromCity', 'ROSELLE'), ('FromCountry', 'US'), ('FromState', 'IL'), ('FromZip', '60193'), ('To', '+1785xxxxxxx'), ('ToCity', 'TOPEKA'), ('ToCountry', 'US'), ('ToState', 'KS'), ('ToZip', '66603'), ('msg', 'Gather End')])])
实际上,我需要将未接听的来电转发到另一个电话号码,而在回调事件中报告“无回答”似乎是一个很好的时机。但在这一点上,呼叫流已经结束,response.dial.number('next-number')不再起作用。
有人以前这样做过吗?
#这是初始来电被接听的路由
@app.route('/gather', methods=['GET', 'POST'])
def gather():
resp = VoiceResponse()
dial = Dial(timeout=30)
dial.number(
'+1-initial-called-number',
status_callback_event='initiated ringing answered completed busy failed no-answer canceled',
status_callback='https://my.ngrok.io/response',
status_callback_method='POST',
)
resp.append(dial)
return str(resp)
@app.route('/response', methods=['POST']) #这是回调路由
def outbound():
status = request.values.get('CallStatus', None)
resp = VoiceResponse()
if (status == 'no-answer'):
resp.dial(timeout=20).number('+1-next-number')
return str(resp)
希望这对您有所帮助。如果您有任何其他问题,请随时提出。
英文:
Has anybody been able to capture the Twilio DialCallStatus? It's referred in many Twilio online documents but I never see one while debugging python scripts. I only see CallStatus such as in the following dump of request.values.
REQUEST VALUES>>> CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([('AccountSid', 'ACxxxxxxx'), ('ApiVersion', '2010-04-01'), ('CallSid', 'CA0c9f4e7eb73dfcd72f273451c6aa249c'), ('CallStatus', 'in-progress'), ('Called', '+1785xxxxxxx'), ('CalledCity', 'TOPEKA'), ('CalledCountry', 'US'), ('CalledState', 'KS'), ('CalledZip', '66603'), ('Caller', '+1630xxxxxxx'), ('CallerCity', 'ROSELLE'), ('CallerCountry', 'US'), ('CallerState', 'IL'), ('CallerZip', '60193'), ('Digits', '1'), ('Direction', 'inbound'), ('FinishedOnKey', ''), ('From', '+1630xxxxxxx'), ('FromCity', 'ROSELLE'), ('FromCountry', 'US'), ('FromState', 'IL'), ('FromZip', '60193'), ('To', '+1785xxxxxxx'), ('ToCity', 'TOPEKA'), ('ToCountry', 'US'), ('ToState', 'KS'), ('ToZip', '66603'), ('msg', 'Gather End')])])
Actually, I need to forward an unanswered incoming call to another phone number and it seems to be a good time to do that when "no-answer" is reported in call back events. However, at that point, it seems that the call flow has been ended and response.dial.number('next-number') does not work any more.
Has anybody done that in the past?
#This is the route where the initial incoming call is answered
@app.route('/gather', methods=['GET', 'POST'])
def gather():
resp = VoiceResponse()
dial = Dial(timeout=30)
dial.number(
'+1-initial-called-number',
status_callback_event='initiated ringing answered completed busy failed no-answer canceled',
status_callback='https://my.ngrok.io/response',
status_callback_method='POST',
)
resp.append(dial)
return str(resp)
@app.route('/response', methods=['POST']) #This is the call back route
def outbound():
status=request.values.get('CallStatus', None)
resp = VoiceResponse()
if (status=='no-answer'):
resp.dial(timeout=20).number('+1-next-number')
return str(resp)
答案1
得分: 0
是的,我收到一个DialCallStatus参数。这是在Dial完成并执行Action URL之后。以下是一些Twiml示例:
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Dial action="https:XXXXXX/api/twilio/voice/noanswer" timeout="20">
<Sip>sip:XXXXXX.sip.us1.twilio.com</Sip>
</Dial>
</Response>
在Dial完成时,https:XXXXXX/api/twilio/voice/noanswer端点会接收到DialCallStatus。示例中的Sip部分并不重要 - 对于Number、Client和Conference操作也是如此。一旦Sip、Number、Client或Conference完成Dial操作,将调用Action URL并具有该参数。文档 表示这是Dial命令的终端状态。
我不太懂Python,但似乎您的示例代码缺少Action URL。Twilio提供的Python示例代码在"指定Action URL和方法"中。
from twilio.twiml.voice_response import Dial, VoiceResponse, Say
response = VoiceResponse()
response.dial('415-123-4567', action='/api/twilio/voice/noanswer', method='GET')
response.say('I am unreachable')
print(response)
英文:
Yes, I receive a DialCallStatus parameter. This is after a Dial completes and executes the Action url. Here is some Twiml:
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Dial action="https:XXXXXX/api/twilio/voice/noanswer" timeout="20">
<Sip>sip:XXXXXX.sip.us1.twilio.com</Sip>
</Dial>
</Response>
The https:XXXXXX/api/twilio/voice/noanswer endpoint receives the DialCallCstatus at the completion of the Dial. The Sip part in the example doesn't really matter - the same is true for Number, Client, and Conference actions. Once the Sip, Number, Client, or Conference completes the Dial action URL is called and will have that parameter. The documentation says it is the terminal status for the Dial command.
I do not know Python well but it seems your example code is missing the Action url. Example code from Twilio for Python is in the "Specify an action URL and method"
from twilio.twiml.voice_response import Dial, VoiceResponse, Say
response = VoiceResponse()
response.dial('415-123-4567', action='/api/twilio/voice/noanswer', method='GET')
response.say('I am unreachable')
print(response)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论