Class: Adhearsion::CallController::Input::PromptBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/call_controller/input/prompt_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_document, grammars, options) ⇒ PromptBuilder

Returns a new instance of PromptBuilder



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/adhearsion/call_controller/input/prompt_builder.rb', line 9

def initialize(output_document, grammars, options)
  input_options = {
    mode: options[:mode] || :dtmf,
    initial_timeout: timeout(options[:timeout] || Adhearsion.config.core.media.timeout),
    inter_digit_timeout: timeout(options[:inter_digit_timeout] || Adhearsion.config.core.media.inter_digit_timeout),
    max_silence: timeout(options[:timeout] || Adhearsion.config.core.media.timeout),
    min_confidence: Adhearsion.config.core.media.min_confidence,
    grammars: grammars,
    recognizer: Adhearsion.config.core.media.recognizer,
    language: Adhearsion.config.core.media.input_language,
    terminator: options[:terminator]
  }.merge(options[:input_options] || {})

  @prompt = if output_document || options[:render_document]
    output_options = {
      render_document: options[:render_document] || {value: output_document},
      renderer: Adhearsion.config.core.media.default_renderer,
      voice: Adhearsion.config.core.media.default_voice
    }.merge(options[:output_options] || {})

    Adhearsion::Rayo::Component::Prompt.new output_options, input_options, barge_in: options.has_key?(:interruptible) ? options[:interruptible] : true
  else
    Adhearsion::Rayo::Component::Input.new input_options
  end
end

Instance Method Details

#execute(controller) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/adhearsion/call_controller/input/prompt_builder.rb', line 35

def execute(controller)
  controller.execute_component_and_await_completion @prompt

  result @prompt.complete_event.reason
rescue Adhearsion::Call::ExpiredError
  raise Adhearsion::Call::Hangup
end