Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twilio传出呼叫-Twiml url_Twilio - Fatal编程技术网

Twilio传出呼叫-Twiml url

Twilio传出呼叫-Twiml url,twilio,Twilio,在基本的Twilio传出呼叫中,需要设置一个参数,即url,如下例所示: call = client.calls.create(to="+14085551234", # Any phone number from_="+12125551234", # Must be a valid Twilio number url="TwiML-app-url") 以下是在我的url中传递的TwiML文件: <

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

call = client.calls.create(to="+14085551234",  # Any phone number
                       from_="+12125551234", # Must be a valid Twilio number
                       url="TwiML-app-url")
以下是在我的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响应。

Ricky来自Twilio

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

你没有提到你是否在使用一个框架,所以我将展示一个使用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
需要“twilio ruby”
需要“sinatra”
获取“/process\u gather”do

#params['Digits']谢谢!还有一个问题,gather谓词中的“action=”标记是否应该等于我的ruby脚本的url?我似乎无法将TwiML文件链接到我的ruby脚本,即使它是可公开访问的,它应该是ruby脚本的URL。如果Twilio在访问时遇到问题,您可以通过查看应用程序监视器中发生的错误来了解更多信息: