简体   繁体   English

Twilio - 传入语音 Webhook 因同一个呼叫而被调用两次?

[英]Twilio - Incoming Voice Webhook is getting called twice for the same call?

Trying to understand why the incoming voice call webhook is getting called twice.试图了解为什么传入的语音呼叫 webhook 会被调用两次。

I'm using an Azure Function with a HTTP trigger.我正在使用 Azure Function 和 HTTP 触发器。 Python 3. Python 3.

It returns a valid TwiML once when I test it through the web browser and look at the logs.当我通过 web 浏览器测试它并查看日志时,它会返回一个有效的 TwiML。

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

However, when I call the Twilio number it begins saying "hello this is a test" followed by ringing and the same message played again.但是,当我拨打 Twilio 号码时,它会开始说“你好,这是一个测试”,然后响铃并再次播放相同的消息。 My phone then displays called failed.然后我的手机显示呼叫失败。

When I place the same XML code in a TwiML bin it works perfectly, only firing once.当我将相同的 XML 代码放在 TwiML 箱中时,它可以完美运行,只触发一次。

Having a similar problem to this person: Incoming Voice Webhook is getting called twice for the same call与此人有类似问题: Incoming Voice Webhook 因同一个呼叫而被呼叫两次


More information - code in the function更多信息 - function 中的代码

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)

Thanks Alan for helping me solve this.感谢艾伦帮我解决了这个问题。

I needed to add the header Content-Type with value 'text/xml'我需要添加值为'text/xml'的header Content-Type

added parameter mimetype='text/xml' to the func.HttpResponse()将参数 mimetype='text/xml' 添加到 func.HttpResponse()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM