【问题标题】:Twilio Skip Options (ruby)Twilio 跳过选项(红宝石)
【发布时间】:2014-09-04 18:55:40
【问题描述】:

我正在使用 ruby​​ 和 twilio api 构建一个网络应用程序,它允许您拨打 twilio 号码并录制语音记录。

这是被调用来录制你的声音的方法:

 def getRecord()
    Twilio::TwiML::Response.new do |response|
      // userResponse = response.Gather --> does this Gather anything someone types at anytime?
      response.Say "Hello"
      response.Say "Record your message.", :voice => 'woman'
      response.Record :maxLength => '5', :trim => "trim-silence", :playBeep => "false", :action => '/feed', :method => 'get'
    end.text
  end

如何添加“复活节彩蛋”功能,例如“跳过说消息”,甚至根据用户点击的数字运行完全不同的方法。我尝试在我的response.Record 呼叫之后立即添加以下if 语句,它确实有效,尽管它仅在用户在录制开始后点击* 时才有效,我希望它从呼叫开始的那一刻开始工作.

  if userResponse['Digits'] == "*"
    getFeed()
  end 

我还尝试了以下方法:

 def getRecord()
    Twilio::TwiML::Response.new do |response|
      // userResponse = response.Gather --> does this Gather anything someone types at anytime?
     until userResponse == '*' do
      response.Say "Hello"
      response.Say "Record your message.", :voice => 'woman'
      response.Record :maxLength => '5', :trim => "trim-silence", :playBeep => "false", :action => '/feed', :method => 'get'
     end
     if userResponse == '*'
       getFeed()
     end

    end.text
  end

但这样until 循环中的任何内容都不会运行。

如何添加一个response.Gather 来监听用户在通话期间随时输入的任何内容?

【问题讨论】:

    标签: ruby twilio twilio-twiml


    【解决方案1】:

    我是 Twilio 的开发人员宣传员,我想我可以在这里提供帮助。

    以你原来的方法为例,你可以这样做:

    def getRecord()
      Twilio::TwiML::Response.new do |response|
        response.Gather :finishOnKey => '*' do
          response.Say "Hello"
          response.Say "Record your message.", :voice => 'woman'
          response.Record :maxLength => '5', :trim => "trim-silence", :playBeep => "false", :action => '/feed', :method => 'get'
        end
        # Whatever you want to happen when the user presses *
        getFeed()
      end.text
    end
    

    如您所见,您可以将 TwiML 嵌套在 Gather 块中。在这种情况下,Gather 将监听按键。如果用户在消息或录制过程中按下 *,它将跳转到 Gather 动词的末尾并在 Gather 之后继续 TwiML,在这种情况下调用方法 getFeed。您可能只想让它重定向到您的提要端点,您可以为此使用response.Redirect '/feed', :method => 'get'

    如果这有帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 2013-01-09
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多