簡體   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