我最近开始使用Twilio语音呼叫,使用Django向用户发送OTP。 我指的是定制Twilio响应的给定链接。 https://www.twilio.com/docs/tutorials/walkthrough/click-to-call/python/flask
views.py
def voice_call(otp, mobile_no):
client = TwilioRestClient(settings.ACCOUNT_SID, settings.AUTH_TOKEN)
client.calls.create(from_=settings.OTP_FROM_NUMBER,
to=mobile_no,
url='http://localhost:8000/outbound/',
method='POST')
def outbound(self):
response = twiml.Response()
response.say("Thank you for contacting our department",
voice='alice')
return HttpResponse(response, content_type="application/xml")
在urls.py中,我有/ outbound /指向我的django视图模块。
如果我在浏览器中点击'/ outbound /',它会呈现正确的xml响应 但在语音通话中,它会显示一条错误消息,指出'抱歉应用程序错误'
不确定在渲染xml时我出错了。 提前谢谢。
答案 0 :(得分:1)
Twilio开发者传道者在这里。
我认为问题是你试图将Twilio指向你的localhost
。当Twilio连接调用时,它将尝试向您在REST API调用中传递的URL发出HTTP请求。如果您通过localhost
,那么Twilio将无法访问它,因为只有您的计算机才能访问它。
虽然有解决方案!我们建议使用名为ngrok的工具。它允许外部服务通过您的localhost
隧道,以便您可以像这样测试webhook。查看how to set up ngrok for use with Twilio和all the reasons I like using ngrok for developing with Twilio上的这些博文。
如果有帮助,请告诉我!