Method: AdhearsionASR::ControllerMethods#ask

Defined in:
lib/adhearsion-asr/controller_methods.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

Parameters:

  • args (Object, Array<Object>)

    A list of outputs to play, as accepted by #play

  • options (Hash)

    Options to modify the grammar

Returns:

  • (Result)

    a result object from which the details of the utterance may be established

See Also:



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)
  options = 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

  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