Method: Adhearsion::CallController::Input#ask

Defined in:
lib/adhearsion/call_controller/input.rb

#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.

Examples:

A basic DTMF digit collection:

ask "Welcome, ", "/opt/sounds/menu-prompt.mp3",
    timeout: 10, terminator: '#', limit: 3

See Also:

  • Output#play
  • Rayo::Component::Input.new
  • Rayo::Component::Output.new


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/adhearsion/call_controller/input.rb', line 40

def ask(*args)
  options = args.last.kind_of?(Hash) ? args.pop : {}
  prompts = args.flatten.compact

  options[:grammar] || options[:grammar_url] || options[:limit] || options[:terminator] || raise(ArgumentError, "You must specify at least one of limit, terminator or grammar")

  grammars = AskGrammarBuilder.new(options).grammars

  output_document = prompts.empty? ? nil : output_formatter.ssml_for_collection(prompts)

  PromptBuilder.new(output_document, grammars, options).execute self
end