简体   繁体   English

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

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

I am trying to make a twilio call with hosting an xml file on Twilio TwiMl Bins and hosting an mp3 file in Assets:我正在尝试通过在 Twilio TwiMl Bins 上托管一个 xml 文件并在 Assets 中托管一个 mp3 文件来进行 twilio 调用:

警长镇

I just want to say a simple sentence and then play a 5-10 second clip.我只想说一个简单的句子然后播放一个5-10秒的剪辑。 Currently when I run my code:目前,当我运行我的代码时:

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

I just get a call - the trial message and then silence and then the call is concluded.我刚接到一个电话 - 试用消息,然后静音,然后电话结束。 Any tips?有小费吗?

Never Mind!没关系! So this worked:所以这有效:

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

But your twilio call will only run once after you "sign" the HTTP request with hmac authentication.但是您的 twilio 调用只会在您使用 hmac 身份验证“签署”HTTP 请求后运行一次。 The script is脚本是

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

Make sure to have node, npm, and request module installed.确保安装了 node、npm 和 request 模块。

npm install request --save

and you are good to go!你很高兴去! Run this script right before your python calling script.在你的 python 调用脚本之前运行这个脚本。

Just an fyi you can also make TWIML/robocalls on the fly by uploading your TWIML to a bin, just before you make the call.仅供参考,您还可以通过在拨打电话之前将 TWIML 上传到垃圾箱来即时拨打 TWIML/robocalls。 It just needs a public URL.它只需要一个公共 URL。 This project that I found actually demonstrates the technique by uploading the TWIML/XML on the fly, getting the new URL (for the newly generated TWIML), and then makes the Twilio call.我发现的这个项目实际上通过动态上传 TWIML/XML、获取新 URL(用于新生成的 TWIML),然后进行 Twilio 调用来演示该技术。 That restwords.com site is pretty handy for this purpose.为此,restwords.com 网站非常方便。

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

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