Twilio外拨电话 - Twiml网址

时间:2015-10-03 20:48:54

标签: twilio

在基本的Twilio传出调用中,有一个参数需要设置,即url,如下例所示:

call = client.calls.create(to="+14085551234",  # Any phone number
                       from_="+12125551234", # Must be a valid Twilio number
                       url="TwiML-app-url")

以下是我的网址中传递的TwiML文件:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="**my-ruby-script**" method="get">
        <Say>Please choose a number then press the pound sign</Say>
    </Gather>
</Response>

如何使用ruby脚本处理操作? ruby脚本需要获取用户输入的数字,然后根据该输入生成新的TwiML响应。

1 个答案:

答案 0 :(得分:0)

来自Twilio的Ricky。

为了做到这一点,您需要确保通过可公开访问的URL提供ruby脚本。由于您指定了GET作为操作方法,因此Twilio将在名为Digits的参数中发送用户在查询字符串中按下的数字。然后你可以use the Ruby helper library to generate the TwiML想要回复。

你没有提到你是否使用框架,所以我将使用Sinatra显示一个片段,但一般的想法也适用于其他框架。

require 'twilio-ruby'
require 'sinatra'

get '/process_gather' do
  # params['Digits'] <- here is where the button the user pressed will be stored. 
  # You can do a conditional check here as you see fit.
  response = Twilio::TwiML::Response.new do |r|
    r.Say 'hello there', voice: 'alice'
  end

  response.text
end

希望有所帮助!

相关问题