我想做以下事情:
用我的手机拨打我的 twilio 号码
我的 twilio 号码识别来电号码然后立即挂断
我的twilio号码回拨识别的号码(我的手机号码)
当我接电话时,twilio 要求我输入我想拨打的号码
Twilio 收集我要呼叫的号码的输入并连接我。
所以我可以用我的手机拨打便宜的国际电话(或漫游电话)。
到目前为止,取自 twilio website api docs,我有:
require 'rubygems'
require 'sinatra'
require 'twilio-ruby'
get '/' do
account_sid = 'xxxxxxx'
auth_token = 'zzzzzzz'
to = params['From']
#to = '+447928344246'
#to = '441903773807'
from = '442033222327'
Twilio::TwiML::Response.new do |r|
r.Hangup
end.text
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
@call = @client.account.calls.create(
:from => from, # From your Twilio number
:to => to, # To any number
:timeout => "20",
# Fetch instructions from this URL when the call connects
:url => 'https://dl.dropboxusercontent.com/u/85088004/twilio/twilio.xml'
)
end
post '/makecall' do
warn params.inspect
account_sid = ' ACaf2b951ae6f7424da036ea9dcd5b0d91'
auth_token = 'my token'
@client = Twilio::REST::Client.new account_sid, auth_token
call = @client.account.calls.create(:url => "https://dl.dropboxusercontent.com/u/85088004/twilio/callback.xml",
:to => params[:Digits],
:from => "+442033222327")
puts call.to
end
'/' 部分 url 文件中的 twilio.xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/makecall" method="POST">
<Say timeout="10">Enter the number you wish to call</Say>
</Gather>
</Response>
我收到“抱歉,出现应用程序错误”。然后它就挂断了。
warn params.inspect
当我检查heroku日志时不会产生任何东西。所以我认为(其中一个)问题是我拨打的号码的参数没有通过。
逻辑或脚本是否还有其他显而易见的问题?
问题是否出在“/makecall”片段中的 url 上?它是:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
</Hangup>
</Response>
非常感谢!