lib/tropo-webapi-ruby/tropo-webapi-ruby.rb
##
# Prompts the user (audio file or text to speech) and optionally waits for a response from the user. 
# If collected, responses may be in the form of DTMF, speech recognition or text using a grammar or 
# free-form text.
#
# @overload ask(params)
#   @param [Hash] params the options to create an ask action request with.
#   @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator
#   @option params [required, Object] :say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout
#   @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function 
#   @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
#   @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
#   @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
#   @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input
#   @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again
#   @option params [optional, Boolean] :required (true) determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed
#   @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question
#   @option params [optional, Float]: speechCompleteTimeout (0.5)  determines how long the application should wait - in seconds - after input before determining a match
#   @option params [optional, Float]: speechIncompleteTimeout (0.5)  determines how long the application should wait - in seconds - after partial input before determining a "no match"
#   @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
#   @option params [optional, String] :recognizer this tells Tropo what language to listen for
#   @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
#   @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
#   @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method.
#   @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
# @overload ask(params, &block)
#   @param [Hash] params the options to create an ask action request with.
#   @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
#   @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator
#   @option params [required, Object] :say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout
#   @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function
#   @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results
#   @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input
#   @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further
#   @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input
#   @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again
#   @option params [optional, Boolean] :required (true) determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed
#   @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question
#   @option params [optional, Float]: speechCompleteTimeout (0.5)  determines how long the application should wait - in seconds - after input before determining a match
#   @option params [optional, Float]: speechIncompleteTimeout (0.5)  determines how long the application should wait - in seconds - after partial input before determining a "no match"
#   @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on
#   @option params [optional, String] :recognizer this tells Tropo what language to listen for
#   @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user
#   @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method.
#   @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method.
#   @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
# @return [String, nil] the JSON string to be passed back to Tropo or nil
#   if the method has been called from inside a block
Prompts the user (audio file or text to speech) and optionally waits for a response from the user.
If collected, responses may be in the form of DTMF, speech recognition or text using a grammar or
free-form text.
Prompts the user ( audio file or text to speech ) and optionally waits for a response from the user . If collected responses may be in the form of DTMF speech recognition or text using a grammar or free - form text .
def ask(params={}, &block)
      params = set_language(params)
      if block_given?
        @ask_hash = {:ask => build_elements(params)}
        instance_exec(&block)
        has_params?(@ask_hash[:ask], 'ask', ['choices', 'say'])
        if @nested_on_hash
          if @nested_on_hash[:on][0][:ask].nil?
            @nested_on_hash[:on][0][:ask] = @ask_hash[:ask]
          elsif @nested_on_hash[:on][0][:ask].is_a? Array
            @nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
          else
            ask = @nested_on_hash[:on][0][:ask]
            @nested_on_hash[:on][0][:ask] = Array.new
            @nested_on_hash[:on][0][:ask] << ask
            @nested_on_hash[:on][0][:ask] << @ask_hash[:ask]
          end
        else
          @response[:tropo] << @ask_hash
          @ask_hash = nil
        end
      else
        hash = build_action('ask', params)
        if @nested_on_hash
          if @nested_on_hash[:on][0][:ask].nil?
            @nested_on_hash[:on][0][:ask] = hash[:ask]
          elsif @nested_on_hash[:on][0][:ask].is_a? Array
            @nested_on_hash[:on][0][:ask] << hash[:ask]
          else
            ask = @nested_on_hash[:on][0][:ask]
            @nested_on_hash[:on][0][:ask] = Array.new
            @nested_on_hash[:on][0][:ask] << ask
            @nested_on_hash[:on][0][:ask] << hash[:ask]
          end
        else
          @response[:tropo] << hash
        end
      end
      render_response if @building.nil?
    end
def ask ( params = { } , & block ) params = set_language ( params ) if block_given? @ask_hash = { :ask => build_elements ( params ) } instance_exec ( & block ) has_params? ( @ask_hash [ :ask ] , 'ask' , [ 'choices' , 'say' ] ) if @nested_on_hash if @nested_on_hash [ :on ] [ 0 ] [ :ask ] . nil? @nested_on_hash [ :on ] [ 0 ] [ :ask ] = @ask_hash [ :ask ] elsif @nested_on_hash [ :on ] [ 0 ] [ :ask ] . is_a? Array @nested_on_hash [ :on ] [ 0 ] [ :ask ] << @ask_hash [ :ask ] else ask = @nested_on_hash [ :on ] [ 0 ] [ :ask ] @nested_on_hash [ :on ] [ 0 ] [ :ask ] = Array . new @nested_on_hash [ :on ] [ 0 ] [ :ask ] << ask @nested_on_hash [ :on ] [ 0 ] [ :ask ] << @ask_hash [ :ask ] end else @response [ :tropo ] << @ask_hash @ask_hash = nil end else hash = build_action ( 'ask' , params ) if @nested_on_hash if @nested_on_hash [ :on ] [ 0 ] [ :ask ] . nil? @nested_on_hash [ :on ] [ 0 ] [ :ask ] = hash [ :ask ] elsif @nested_on_hash [ :on ] [ 0 ] [ :ask ] . is_a? Array @nested_on_hash [ :on ] [ 0 ] [ :ask ] << hash [ :ask ] else ask = @nested_on_hash [ :on ] [ 0 ] [ :ask ] @nested_on_hash [ :on ] [ 0 ] [ :ask ] = Array . new @nested_on_hash [ :on ] [ 0 ] [ :ask ] << ask @nested_on_hash [ :on ] [ 0 ] [ :ask ] << hash [ :ask ] end else @response [ :tropo ] << hash end end render_response if @building . nil? end
Prompts the user (audio file or text to speech) and optionally waits for a response from the user.
Prompts the user ( audio file or text to speech ) and optionally waits for a response from the user .
#create_nested_hash('ask', params)
the JSON string to be passed back to Tropo or nil if the method has been called from inside a block
the JSON string to be passed back to Tropo or nil if the method has been called from inside a block
String, nil
params
block
overload
ask(params) @param [Hash] params the options to create an ask action request with. @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator @option params [required, Object] :say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again @option params [optional, Boolean] :required (true) determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question @option params [optional, Float]: speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match @option params [optional, Float]: speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a "no match" @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on @option params [optional, String] :recognizer this tells Tropo what language to listen for @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method. @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method. @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
ask ( params ) @param [ Hash ] params the options to create an ask action request with . @option params [ required Object ] : choices indicates the structure of the expected data and acceptable modes of input - value mode terminator @option params [ required Object ] : say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout @option params [ optional String or Array ] : allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function @option params [ optional String ] : name this is the key used to identify the result of an operation so you can differentiate between multiple results @option params [ optional Integer ] : attempts ( 1 ) the number of times to prompt the user for input @option params [ optional Boolean ] : bargein ( true ) allows a user to say or enter a key to stop the prompt from playing further @option params [ optional Integer ] : interdigitTimeout ( Default : 5 . 0 ) defines how long to wait between key presses to determine the user has stopped entering input @option params [ optional Integer ] : minConfidence ( 30 ) the minimum confidence by which to accept the response as opposed to asking again @option params [ optional Boolean ] : required ( true ) determines whether Tropo should move on to the next verb - if true Tropo will only move on if the current operation completed @option params [ optional Float ] : sensitivity ( 0 . 5 ) determines how loud or soft audio needs to be before detecting as an attempt to answer the question @option params [ optional Float ] : speechCompleteTimeout ( 0 . 5 ) determines how long the application should wait - in seconds - after input before determining a match @option params [ optional Float ] : speechIncompleteTimeout ( 0 . 5 ) determines how long the application should wait - in seconds - after partial input before determining a " no match " @option params [ optional Integer ] : timeout ( 30 ) the amount of time in seconds to wait for a response before moving on @option params [ optional String ] : recognizer this tells Tropo what language to listen for @option params [ optional String ] : voice ( allison ) specifies the voice to be used when speaking text to a user @option params [ optional String ] : promptLogSecurity Controls whether Tropo logs the text to speech string used by the method . @option params [ optional String ] : asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method . @option params [ optional String ] : maskTemplate When asrLogSecurity is set to " mask " this parameter defines the pattern that should be masked .
overload
ask(params, █) @param [Hash] params the options to create an ask action request with. @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event @option params [required, Object] :choices indicates the structure of the expected data and acceptable modes of input - value, mode, terminator @option params [required, Object] :say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout @option params [optional, String or Array] :allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function @option params [optional, String] :name this is the key used to identify the result of an operation, so you can differentiate between multiple results @option params [optional, Integer] :attempts (1) the number of times to prompt the user for input @option params [optional, Boolean] :bargein (true) allows a user to say or enter a key to stop the prompt from playing further @option params [optional, Integer] :interdigitTimeout (Default: 5.0) defines how long to wait between key presses to determine the user has stopped entering input @option params [optional, Integer] :minConfidence (30) the minimum confidence by which to accept the response, as opposed to asking again @option params [optional, Boolean] :required (true) determines whether Tropo should move on to the next verb - if true, Tropo will only move on if the current operation completed @option params [optional, Float] :sensitivity (0.5) determines how loud or soft audio needs to be before detecting as an attempt to answer the question @option params [optional, Float]: speechCompleteTimeout (0.5) determines how long the application should wait - in seconds - after input before determining a match @option params [optional, Float]: speechIncompleteTimeout (0.5) determines how long the application should wait - in seconds - after partial input before determining a "no match" @option params [optional, Integer] :timeout (30) the amount of time, in seconds, to wait for a response before moving on @option params [optional, String] :recognizer this tells Tropo what language to listen for @option params [optional, String] :voice (allison) specifies the voice to be used when speaking text to a user @option params [optional, String] :promptLogSecurity Controls whether Tropo logs the text to speech string used by the method. @option params [optional, String] :asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method. @option params [optional, String] :maskTemplate When asrLogSecurity is set to "mask", this parameter defines the pattern that should be masked.
ask ( params █ ) @param [ Hash ] params the options to create an ask action request with . @param [ Block ] takes a block so that you may trigger actions such as a say on a specific event @option params [ required Object ] : choices indicates the structure of the expected data and acceptable modes of input - value mode terminator @option params [ required Object ] : say determines what is played or sent to the caller - also takes an event key to determine if prompt will be played based on a nomatch or timeout @option params [ optional String or Array ] : allowSignals allows you to assign a signal to ask which can be used with REST to interrupt the function @option params [ optional String ] : name this is the key used to identify the result of an operation so you can differentiate between multiple results @option params [ optional Integer ] : attempts ( 1 ) the number of times to prompt the user for input @option params [ optional Boolean ] : bargein ( true ) allows a user to say or enter a key to stop the prompt from playing further @option params [ optional Integer ] : interdigitTimeout ( Default : 5 . 0 ) defines how long to wait between key presses to determine the user has stopped entering input @option params [ optional Integer ] : minConfidence ( 30 ) the minimum confidence by which to accept the response as opposed to asking again @option params [ optional Boolean ] : required ( true ) determines whether Tropo should move on to the next verb - if true Tropo will only move on if the current operation completed @option params [ optional Float ] : sensitivity ( 0 . 5 ) determines how loud or soft audio needs to be before detecting as an attempt to answer the question @option params [ optional Float ] : speechCompleteTimeout ( 0 . 5 ) determines how long the application should wait - in seconds - after input before determining a match @option params [ optional Float ] : speechIncompleteTimeout ( 0 . 5 ) determines how long the application should wait - in seconds - after partial input before determining a " no match " @option params [ optional Integer ] : timeout ( 30 ) the amount of time in seconds to wait for a response before moving on @option params [ optional String ] : recognizer this tells Tropo what language to listen for @option params [ optional String ] : voice ( allison ) specifies the voice to be used when speaking text to a user @option params [ optional String ] : promptLogSecurity Controls whether Tropo logs the text to speech string used by the method . @option params [ optional String ] : asrLogSecurity Control whether Tropo should log the input from the user in response to the ask method . @option params [ optional String ] : maskTemplate When asrLogSecurity is set to " mask " this parameter defines the pattern that should be masked .