我正在尝试编写一个Twilio脚本来进行没有rails的语音广播 - 我希望能够直接从我的终端运行脚本。
我有一个非常简单的脚本,直接来自twilio-rb
gem docs:
# This should be in an initializer or similar
Twilio::Config.setup \
:account_sid => account,
:auth_token => token
Twilio::Call.create :to => '+1234567890', :from => '+0987654321',
:url => xml_file
xml_file
是我本地计算机上的xml文件,但它会抛出此错误:
Error #21205: Url is not a valid url
如何编写上述脚本来操作本地xml文件?最终目标是严格打电话,播放音频消息,按下按钮并根据收到的号码进行操作。 Twiml XML文件应该为我做,如果我可以让它工作。
编辑:
使用Dropbox共享链接时,我在Twilio界面中收到此错误:
'Twilio is unable to process the Content-Type of the provided URL. Please see the Twilio Markup XML Documentation for more information on valid Content-Types.
You must return a Content-Type for all requests. Requests without a Content-Type will appear in the Debugger as a 502 Bad Gateway error.
Having a phone number, outgoing call request or action attribute refer to a non XML or audio resource.
Having a Play verb attempt to play non-audio content, such as XML or text.
Verify that that your web server is returning a Content-Type and it is the expected value
Make sure the URL noted refers to a valid resource'
为了确保,我复制了一个我知道将用于我的XML文件的示例:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="man">Hey man! Listen to this!</Say>
<Play>http://foo.com/cowbell.mp3</Play>
<Say voice="man">What did you think of that?!</Say>
<Record action="http://foo.com/handleRecording.php" method="GET" maxLength="20" finishOnKey="*"/>
<Gather action="/process_gather.php" method="GET">
<Say>Now hit some buttons!</Say>
</Gather>
<Say voice="man">Awesome! Thanks!</Say>
<Hangup/>
</Response>
答案 0 :(得分:0)
尝试两种想法:
(1)如果文件是在本地读取并发送到Twilio服务器,请尝试:
:url => 'file:///path/file.xml'
<强>,其中强>
host
中的//host/
,连续产生了三个斜杠。path
是XML文件的完整文件系统路径。file.xml
是XML文件的名称。(2)如果文件必须由Twilio服务器公开读取,请尝试将其放置在某个地方的云端(例如Dropbox)并在那里使用公共URL。