繁体   English   中英

无法使用 TwiML Bin 和资产进行自定义 Twilio 调用

[英]Can't make custom Twilio Call with TwiML Bin and Assets

我正在尝试通过在 Twilio TwiMl Bins 上托管一个 xml 文件并在 Assets 中托管一个 mp3 文件来进行 twilio 调用:

警长镇

我只想说一个简单的句子然后播放一个5-10秒的剪辑。 目前,当我运行我的代码时:

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


# Your Account Sid and Auth Token from twilio.com/console
account_sid = "stuff"
auth_token = "stuff"
client = Client(account_sid, auth_token)

call = client.calls.create(
            url="https://handler.twilio.com/twiml/EHdff1ba57cc168191864794c6c44c1723",
            from_="+1mytwilionumber",
            to="+1mynumber"                  
        )

print(call.sid)

我刚接到一个电话 - 试用消息,然后静音,然后电话结束。 有小费吗?

没关系! 所以这有效:

https://support.twilio.com/hc/en-us/articles/223132187--Not-Authorized-error-when-trying-to-view-TwiML-Bin-URL

但是您的 twilio 调用只会在您使用 hmac 身份验证“签署”HTTP 请求后运行一次。 脚本是

const crypto = require('crypto')
    , request = require('request')

const url = process.argv[2] + '?AccountSid=' + process.env.TWILIO_ACCOUNT_SID

const twilioSig = crypto.createHmac('sha1', process.env.TWILIO_AUTH_TOKEN).update(new Buffer(url, 'utf-8')).digest('Base64')

request({url: url, headers: { 'X-TWILIO-SIGNATURE': twilioSig }}, function(err, res, body) {
  console.log(body)
})

确保安装了 node、npm 和 request 模块。

npm install request --save

你很高兴去! 在你的 python 调用脚本之前运行这个脚本。

仅供参考,您还可以通过在拨打电话之前将 TWIML 上传到垃圾箱来即时拨打 TWIML/robocalls。 它只需要一个公共 URL。 我发现的这个项目实际上通过动态上传 TWIML/XML、获取新 URL(用于新生成的 TWIML),然后进行 Twilio 调用来演示该技术。 为此,restwords.com 网站非常方便。

暂无
暂无

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

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