我是否必须在Python中使用Twilio API进行出站调用时始终使用“ url”字段?

我一直在尝试找出如何在检测到答录机时拨打外线电话以留下语音邮件。我仍处于探索的开始,并一直在尝试遵循this之类的Twilio示例。我想使用Python,所以我从下面的Twilio复制粘贴示例:

# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client


# Your account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'your account sid'
auth_token = 'your_auth_token'
client = Client(account_sid,auth_token)

call = client.calls.create(
                        url='http://demo.twilio.com/docs/voice.xml',to='+1555123456',from_='+1501123456'
                    )

print(call.sid)

在上面的代码中,似乎Twilio的Python SDK始终期望url(公开可用的XML文件/响应)作为ping的资源。我想知道是否可以构建有效的XML(TwiML)文件并在上述client.calls.create(...)调用中引用它。换句话说,如何使Twilio“说”我在本地计算机上的XML文件中设计的内容(如果可能的话)?我只打算根据需要从我的个人计算机上运行Python脚本,而且我无法访问任何地方的服务器。

预先感谢您的回答/建议!

redrex5 回答:我是否必须在Python中使用Twilio API进行出站调用时始终使用“ url”字段?

需要公开访问URL。如果您想让Twilio托管逻辑,则可以使用Twilio StudioTwilio Serverless Functions,而无需公开公共URL。

对于开发,您可以使用名为Ngrok的工具,该工具会将Twilio TwiML请求传送到您的私有应用程序。

您可以在此处找到更多详细信息。

How to test webhooks locally with ngrok - Twilio Tip #6

,

那么您可以使用pythons简单的http服务器对此进行测试。并让它托管该文件。

curl http://demo.twilio.com/docs/voice.xml -o voice.xml
python -m SimpleHTTPServer 
#run to above commands then
#try using bellow?
call = client.calls.create(
                    url='http://localhost:8000/voice.xml',to='+1555123456',from_='+1501123456'
                )
#the file at that location is dead simple
<Response>
<Say voice="alice">Thanks for trying our documentation. Enjoy!</Say>
<Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>
本文链接:https://www.f2er.com/3126848.html

大家都在问