class Punchblock::Translator::Asterisk::Component::ComposedPrompt

Public Instance Methods

execute() click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 11
def execute
  validate
  output_command.request!
  setup_dtmf_recognizer

  @output_incomplete = true

  @output_component = Output.new(output_command, @call)
  call.register_component @output_component
  fut = Celluloid::Future.new { @output_component.execute }

  case @output_command.response
  when Ref
    send_ref
  else
    set_node_response @output_command.response
  end

  if @component_node.barge_in
    @barged = false
    register_dtmf_event_handler
    fut.value # Block until output is complete before starting timers
    @output_incomplete = false
    start_timers unless @barged
  else
    fut.value # Block until output is complete before allowing input
    register_dtmf_event_handler
    start_timers
  end
end
output_command() click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 50
def output_command
  @output_command ||= @component_node.output
end
process_dtmf(digit) click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 42
def process_dtmf(digit)
  if @component_node.barge_in && @output_incomplete
    @output_component.stop_by_redirect Punchblock::Event::Complete::Stop.new
    @barged = true
  end
  super
end

Private Instance Methods

input_node() click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 56
def input_node
  @input_node ||= @component_node.input
end
register_dtmf_event_handler() click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 60
def register_dtmf_event_handler
  @dtmf_handler_id = call.register_handler :ami, [{:name => 'DTMF', [:[], 'End'] => 'Yes'}, {:name => 'DTMFEnd'}] do |event|
    process_dtmf event['Digit']
  end
end
unregister_dtmf_event_handler() click to toggle source
# File lib/punchblock/translator/asterisk/component/composed_prompt.rb, line 66
def unregister_dtmf_event_handler
  call.unregister_handler :ami, @dtmf_handler_id if instance_variable_defined?(:@dtmf_handler_id)
end