Module: AdhearsionASR::ControllerMethods
- Defined in:
- lib/adhearsion-asr/controller_methods.rb
Instance Method Summary collapse
-
#ask(*args) ⇒ Result
Prompts for input, handling playback of prompts, DTMF grammar construction, and execution.
-
#menu(*args, &block) ⇒ Result
Creates and manages a multiple choice menu driven by DTMF, handling playback of prompts, invalid input, retries and timeouts, and final failures.
Instance Method Details
#ask(*args) ⇒ Result
Prompts for input, handling playback of prompts, DTMF grammar construction, and execution
The first arguments will be a list of sounds to play, as accepted by #play, including strings for TTS, Date and Time objects, and file paths. :timeout, :terminator and :limit options may be specified to automatically construct a grammar, or grammars may be manually specified.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/adhearsion-asr/controller_methods.rb', line 35 def ask(*args) = args.last.kind_of?(Hash) ? args.pop : {} prompts = args.flatten.compact if block_given? logger.warn "You passed a block to #ask, but this functionality is not available in adhearsion-asr. If you're looking for the block validator functionality, you should avoid using it in favour of grammars, and it is deprecated in Adhearsion Core." end [:grammar] || [:grammar_url] || [:limit] || [:terminator] || raise(ArgumentError, "You must specify at least one of limit, terminator or grammar") grammars = AskGrammarBuilder.new().grammars output_document = prompts.empty? ? nil : output_formatter.ssml_for_collection(prompts) PromptBuilder.new(output_document, grammars, ).execute self end |
#menu(*args, &block) ⇒ Result
Creates and manages a multiple choice menu driven by DTMF, handling playback of prompts, invalid input, retries and timeouts, and final failures.
The first arguments will be a list of sounds to play, as accepted by #play, including strings for TTS, Date and Time objects, and file paths. :tries and :timeout options respectively specify the number of tries before going into failure, and the timeout in seconds allowed on each digit input. The most important part is the following block, which specifies how the menu will be constructed and handled.
#match handles connecting an input pattern to a payload. The pattern can be one or more of: an integer, a Range, a string, an Array of the possible single types. Input is matched against patterns, and the first exact match has it’s payload executed. Matched input is passed in to the associated block, or to the controller through #options.
Allowed payloads are the name of a controller class, in which case it is executed through its #run method, or a block, which is executed in the context of the current controller.
#invalid has its associated block executed when the input does not possibly match any pattern. #timeout’s block is run when timeout expires before receiving any input #failure runs its block when the maximum number of tries is reached without an input match.
Execution of the current context resumes after #menu finishes. If you wish to jump to an entirely different controller, use #pass. Menu will return :failed if failure was reached, or :done if a match was executed.
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/adhearsion-asr/controller_methods.rb', line 106 def (*args, &block) raise ArgumentError, "You must specify a block to build the menu" unless block = args.last.kind_of?(Hash) ? args.pop : {} prompts = args.flatten.compact = MenuBuilder.new(, &block) output_document = prompts.empty? ? nil : output_formatter.ssml_for_collection(prompts) .execute output_document, self end |