使用VoiceResponce - 带POST的response.gather()不会发送数字

时间:2018-02-28 14:58:44

标签: twilio

我使用GET将Twilio编号配置为http://66.175.221.103:6543/ivr/860d247f4bc7

以下代码在GET中捕获它并使用欢迎消息创建语音响应。该操作是相同的URL但使用POST。

    itemID = request.matchdict['itemid']
    itemData = getItemData(request,itemID)
    if itemData is not None:
        itemResponses = getItemResponses(request,itemID)
        if request.method == 'GET':
            #Gather the response and POST to the same ID
            response = VoiceResponse()
            with response.gather(numDigits=1, action=request.route_url('ivr',itemid=itemID), method="POST") as g:
                 g.say(itemData["item_desc"],voice="alice", language="en-GB", loop=3)
            return twiml(response)                
        else:
            log.debug("*************888")
            log.debug(request.POST)
            log.debug("*************888")
            soption = request.POST.get('Digits', '0')
            noption = int(soption)
            for resp in itemResponses:
                if resp["resp_num"] == noption:
                    response = VoiceResponse()
                    response.redirect(request.route_url('ivr',itemid=resp["target_item"]))
                    return twiml(response)
            resp = VoiceResponse()
            resp.say("Error, was not able to find a response")
            resp.hangup()
            return twiml(resp)

产生以下XML

<Response><Gather action="http://66.175.221.103:6543/ivr/860d247f4bc7" method="POST" numDigits="1"><Say language="en-GB" loop="3" voice="alice">Welcome to the Agricultural Podcast service. To listen to a podcast press 1. To request for new content press 2</Say></Gather></Response>

我按1例如,我在帖子上得到了这个:

[('Called', '+17656133098'), ('ToState', 'IN'), ('CallerCountry', 'LS'), ('Direction', 'inbound'), ('CallerState', ''), ('ToZip', '46952'), ('CallSid', 'CAa127058ffcc4b148e8757ffb9025440c'), ('To', '+17656133098'), ('CallerZip', ''), ('ToCountry', 'US'), ('ApiVersion', '2010-04-01'), ('CalledZip', '46952'), ('CalledCity', 'MARION'), ('CallStatus', 'in-progress'), ('From', '+266696687'), ('AccountSid', 'ACaa8c3038f45a521b83c74789d51af27d'), ('CalledCountry', 'US'), ('CallerCity', ''), ('Caller', '+266696687'), ('FromCountry', 'LS'), ('ToCity', 'MARION'), ('FromCity', ''), ('CalledState', 'IN'), ('FromZip', ''), ('FromState', '')]

The Gather发布了一个帖子&#34; http://66.175.221.103:6543/ivr/860d247f4bc7&#34;但不发送&#34;数字&#34;作为帖子的一部分。

知道为什么吗?

1 个答案:

答案 0 :(得分:0)

由于Twilio中未记录的某些原因,对UR​​L的get请求无法对同一URL执行发布(使用Gather)。我将帖子分开并获得了分开的URL,现在一切正常。