如何显示通过 Twilio Gather 方法输入的数字?
How do I display inputted digits from the Twilio Gather method?
我是 Twilio 和一般编码的新手,我在从 Gather 方法访问参数时遇到问题。我正在使用 Sinatra 编写此应用程序的代码。基本上,我的应用正在尝试执行以下操作:
- 用户在表格中输入他们的号码和延迟。
- 我的 twilio 号码将在指定的延迟后拨打该号码。
- 语音会要求用户使用 Gather 方法输入数字。
- 呼叫将被重定向到一个新的 url,语音将从 1 计数到输入的数字。
我想在下方显示一个历史日志,其中显示 phone 号码和表格延迟,以及通话期间收集的号码参数。我可以看到在 Twilio 日志中输入的数字,但不知道如何访问它。在我的 index.erb 文件中显示此信息的最佳方式是什么?
<% unless @calls.nil? %>
<% @calls[1..10].each do |call| %>
<tr>
<td><%= call.start_time %> </td>
<td><%= call.to_formatted %> </td>
<td><%= delay input %></td>
<td><%= number inputted %></td>
</tr>
<% end %>
<% end %>
提前致谢。
此处为 Twilio 开发人员布道师。
您只能在调用中访问来自 <Gather>
的输入数字,因此如果您想稍后读出此内容,您需要将值保存在您自己的数据库中并自行核对数据。
您的应用程序将看起来像这样:
<Gather>
数字的动作:
post "/calls" do
twiml = Twilio::TwiML::Response.new do |r|
r.Gather action: "/process_gather" do |g|
g.Say "Please enter a digit and I will count up to it."
end
end
twiml.to_xml
end
然后您可以收到 Digits
,将它们与呼叫 SID 一起保存,并读出号码。 (我正在想象一个 CallRecord
模型,其行为类似于 ActiveRecord。)
post "/process_gather" do
number = params["Digits"].to_i
call_record = CallRecord.new(call_sid: params["CallSid"], number: number)
call_record.save!
twiml = Twilio::TwiML::Response.new do |r|
twiml.Say "Here are your numbers."
twiml.Say (1..number).to_a.join(', ')
end
twiml.to_xml
end
然后,对于您的日志页面,您可以从 API 检索调用,正如我假设的那样。然后,您想要使用 API 中的 CallSid
s 从数据库中 return CallRecord
s 并且您可以将两个记录压缩在一起并将结果读出到你的看法。
这有什么帮助吗?
我是 Twilio 和一般编码的新手,我在从 Gather 方法访问参数时遇到问题。我正在使用 Sinatra 编写此应用程序的代码。基本上,我的应用正在尝试执行以下操作:
- 用户在表格中输入他们的号码和延迟。
- 我的 twilio 号码将在指定的延迟后拨打该号码。
- 语音会要求用户使用 Gather 方法输入数字。
- 呼叫将被重定向到一个新的 url,语音将从 1 计数到输入的数字。
我想在下方显示一个历史日志,其中显示 phone 号码和表格延迟,以及通话期间收集的号码参数。我可以看到在 Twilio 日志中输入的数字,但不知道如何访问它。在我的 index.erb 文件中显示此信息的最佳方式是什么?
<% unless @calls.nil? %>
<% @calls[1..10].each do |call| %>
<tr>
<td><%= call.start_time %> </td>
<td><%= call.to_formatted %> </td>
<td><%= delay input %></td>
<td><%= number inputted %></td>
</tr>
<% end %>
<% end %>
提前致谢。
此处为 Twilio 开发人员布道师。
您只能在调用中访问来自 <Gather>
的输入数字,因此如果您想稍后读出此内容,您需要将值保存在您自己的数据库中并自行核对数据。
您的应用程序将看起来像这样:
<Gather>
数字的动作:
post "/calls" do
twiml = Twilio::TwiML::Response.new do |r|
r.Gather action: "/process_gather" do |g|
g.Say "Please enter a digit and I will count up to it."
end
end
twiml.to_xml
end
然后您可以收到 Digits
,将它们与呼叫 SID 一起保存,并读出号码。 (我正在想象一个 CallRecord
模型,其行为类似于 ActiveRecord。)
post "/process_gather" do
number = params["Digits"].to_i
call_record = CallRecord.new(call_sid: params["CallSid"], number: number)
call_record.save!
twiml = Twilio::TwiML::Response.new do |r|
twiml.Say "Here are your numbers."
twiml.Say (1..number).to_a.join(', ')
end
twiml.to_xml
end
然后,对于您的日志页面,您可以从 API 检索调用,正如我假设的那样。然后,您想要使用 API 中的 CallSid
s 从数据库中 return CallRecord
s 并且您可以将两个记录压缩在一起并将结果读出到你的看法。
这有什么帮助吗?