【问题标题】:Twilio - Incoming Voice Webhook is getting called twice for the same call?Twilio - 传入语音 Webhook 会因同一个呼叫而被呼叫两次?
【发布时间】:2020-04-29 15:43:11
【问题描述】:

试图了解为什么传入的语音呼叫 webhook 会被调用两次。

我正在使用带有 HTTP 触发器的 Azure 函数。 Python 3。

当我通过网络浏览器测试它并查看日志时,它会返回一个有效的 TwiML。

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

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

当我将相同的 XML 代码放入 TwiML bin 时,它可以完美运行,只触发一次。

与此人有类似问题: 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)

【问题讨论】:

  • 我可以解释的另一个链接,有时基于会话发起协议 (SIP) 响应,运营商可能会重试呼叫,认为原始运营商无法终止它。在这种情况下,新的 CallSID 是线索。忙碌(486 响应代码)并不常见,但情况似乎如此。但是,我无法解释为什么您的 webhook 被调用了两次。如果您在呼叫日志中查找 CallSID,您认为 Azure 函数中的 TwiML 是什么?您是否可能配置了故障转移 URL 并且正在触发?
  • 嗨 @Alan,查看通话记录,有两个不同的 CallSID 都返回 Last SIP Response 603 Decline 我从上面的帖子中看到相同的 TwiML,但我没有配置故障转移 URL。跨度>
  • @Alan 知道为什么 TwiML bin 中的代码成功并且 azure 函数会导致错误吗?在原始帖子中添加了请求的图片
  • 我建议使用 Postman (postman.com) 之类的工具并比较 Content-Type 和 HTTP 响应代码(最有可能在这里),那里必须有所不同。您将无法使用 TwiML Bin 执行此操作(因为它会检查特定的签名标头 - X-Twilio-Signature),而是使用此 URL,然后将其与您的 Azure 函数端点响应进行比较,demo.twilio.com/docs/voice.xml .
  • @Alan 谢谢你的建议!!我没有将 Content-Type 设置为 text/xml。现在可以正常使用了

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


【解决方案1】:

感谢艾伦帮我解决了这个问题。

我需要添加带有值“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')

【讨论】:

  • 太棒了!感谢您的更新和发布您解决问题的方式!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多