【问题标题】:Forward unanswered calls in Twilio using python使用 python 在 Twilio 中转发未应答的呼叫
【发布时间】:2023-02-09 06:45:05
【问题描述】:

有人能够捕获 Twilio DialCallStatus 吗?许多 Twilio 在线文档中都提到了它,但我在调试 python 脚本时从未见过它。我只看到 CallStatus,例如在 request.values 的以下转储中。

请求值>>> CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([('AccountSid', 'ACxxxxxxx'), ('ApiVersion', '2010-04-01'), ('CallSid', 'CA0c9f4e7eb73dfcd72f273451c6aa249c') , ('CallStatus', '进行中'), ('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') 不再起作用。

过去有人这样做过吗?

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

【问题讨论】:

    标签: python-3.x twilio call forward


    【解决方案1】:

    是的,我收到一个 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>
    

    https:XXXXXX/api/twilio/voice/noanswer 端点在拨号完成时接收 DialCallCstatus。示例中的 Sip 部分并不重要 - Number、Client 和 Conference 操作也是如此。一旦 Sip、号码、客户端或会议完成,将调用拨号操作 URL 并将具有该参数。 documentation 表示它是 Dial 命令的终端状态。

    我不太了解 Python,但您的示例代码似乎缺少 Action url。来自 Twilio for Python 的示例代码位于 "Specify an action URL and method"

    from twilio.twiml.voice_response import Dial, VoiceResponse, Say
    
    response = VoiceResponse()
    response.dial('415-123-4567', action='/handleDialCallStatus', method='GET')
    response.say('I am unreachable')
    
    print(response)
    

    【讨论】:

    • 我的代码实际上是用 Python 编写的。我看到您有 Twiml 文件和 PHP 文件。他们如何协同工作?另外,https:XXXXXX/api/twilio/voice/noanswer 在哪里?
    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多