Twilio-传入语音Webhook为同一呼叫两次被呼叫?

时间:2020-04-29 15:43:11

标签: python-3.x twilio azure-functions

试图了解为什么传入语音呼叫Webhook两次被呼叫。

我正在将Azure函数与HTTP触发器一起使用。 Python3。

当我通过Web浏览器对其进行测试并查看日志时,它将返回一个有效的TwiML。

<?xml version="1.0" encoding="UTF-8"?><Response><Say>hello this is a test </Say><Play digits="wwww#" /></Response>

但是,当我拨打Twilio号码时,它开始说“你好,这是一次测试”,然后响起并再次播放相同的消息。然后我的电话显示呼叫失败。

当我将相同的XML代码放入TwiML容器中时,它可以正常工作,仅触发一次。

与此人有类似的问题: Incoming Voice Webhook is getting called twice for the same call


更多信息-函数中的代码

import logging
from twilio.twiml.voice_response import Say, Play, VoiceResponse
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    response = VoiceResponse()
    response.say('hello this is test bots')
    response.play('', digits='wwww#')

    return func.HttpResponse(str(response), status_code=200)

1 个答案:

答案 0 :(得分:1)

感谢艾伦(Alan)帮助我解决了这个问题。

我需要添加值为'text / xml'的标题Content-Type

在func.HttpResponse()中添加了参数mimetype ='text / xml'

import logging
from twilio.twiml.voice_response import Say, Play, VoiceResponse
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    response = VoiceResponse()
    response.say('hello this is test bots')
    response.play('', digits='wwww#')

    return func.HttpResponse(str(response), status_code=200, mimetype='text/xml')