Module: Adhearsion::CallController::Input
- Included in:
- Adhearsion::CallController
- Defined in:
- lib/adhearsion/call_controller/input.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#ask(*args, options, &block) ⇒ Result
Prompts for input via DTMF, handling playback of prompts, timeouts, digit limits and terminator digits.
-
#menu(*args, options, &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, options, &block) ⇒ Result
Prompts for input via DTMF, handling playback of prompts, timeouts, digit limits and terminator digits.
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 then be specified. A block may be passed which is invoked on each digit being collected. If it returns true, the collection is terminated.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/adhearsion/call_controller/input.rb', line 43 def ask(*args, , &block) logger.warn "This implementation of #ask is deprecated due to issues with dropped DTMF. For a solution, see http://adhearsion.com/docs/common_problems#toc_3" unless .is_a?(Hash) args << = {} end sound_files = args.flatten = MenuDSL::Menu.new do validator(&block) if block end .validate :basic = nil catch :finish do until MenuDSL::Menu::MenuResultDone === raise unless .should_continue? = .continue if .is_a?(MenuDSL::Menu::MenuGetAnotherDigit) next_digit = , sound_files if next_digit << next_digit else .timeout! throw :finish end end end end Result.new.tap do |result| result.response = .result result.status = .status result. = end end |
#menu(*args, options, &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.
#invalid has its associated block executed when the input does not possibly match any pattern. #timeout’s block is run when time expires before or between input digits. #failure runs its block when the maximum number of tries is reached without an input match.
#validator runs its block on each digit being collected. If it returns true, the collection is terminated.
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.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/adhearsion/call_controller/input.rb', line 136 def (*args, , &block) logger.warn "This implementation of #menu is deprecated due to issues with dropped DTMF. For a solution, see http://adhearsion.com/docs/common_problems#toc_3" unless .is_a?(Hash) args << = {} end sound_files = args.flatten = MenuDSL::Menu.new , &block .validate = nil catch :finish do until MenuDSL::Menu::MenuResultDone === if .should_continue? = .continue else logger.debug "Menu failed to get valid input. Calling \"failure\" hook." .execute_failure_hook throw :finish end case when MenuDSL::Menu::MenuResultInvalid logger.debug "Menu received invalid input. Calling \"invalid\" hook and restarting." .execute_invalid_hook .restart! = nil when MenuDSL::Menu::MenuGetAnotherDigit next_digit = , sound_files if next_digit << next_digit else case when MenuDSL::Menu::MenuGetAnotherDigitOrFinish jump_to .match_object, :extension => .new_extension throw :finish when MenuDSL::Menu::MenuGetAnotherDigitOrTimeout logger.debug "Menu timed out. Calling \"timeout\" hook and restarting." .execute_timeout_hook .restart! = nil end end when MenuDSL::Menu::MenuResultFound logger.debug "Menu received valid input (#{.new_extension}). Calling the matching hook." jump_to .match_object, :extension => .new_extension throw :finish end end end Result.new.tap do |result| result.response = .result result.status = .status result. = end end |