Class: Punchblock::Translator::Asterisk::Component::Output

Inherits:
Component show all
Includes:
StopByRedirect
Defined in:
lib/punchblock/translator/asterisk/component/output.rb

Constant Summary collapse

UnrenderableDocError =
Class.new OptionError

Instance Attribute Summary

Attributes inherited from Component

#call, #call_id, #id

Instance Method Summary collapse

Methods included from StopByRedirect

#execute_command, #stop_by_redirect

Methods inherited from Component

#call_ended, #execute_command, #initialize, #logger_id, #send_complete_event, #send_event

Methods included from DeadActorSafety

#safe_from_dead_actors

Constructor Details

This class inherits a constructor from Punchblock::Translator::Asterisk::Component::Component

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 18

def execute
  raise OptionError, 'An SSML document is required.' unless @component_node.ssml
  raise OptionError, 'An interrupt-on value of speech is unsupported.' if @component_node.interrupt_on == :speech

  [:start_offset, :start_paused, :repeat_interval, :repeat_times, :max_time].each do |opt|
    raise OptionError, "A #{opt} value is unsupported on Asterisk." if @component_node.send opt
  end

  early = !@call.answered?

  rendering_engine = @component_node.renderer || @media_engine || :asterisk

  case rendering_engine.to_sym
  when :asterisk
    raise OptionError, "A voice value is unsupported on Asterisk." if @component_node.voice
    raise OptionError, 'Interrupt digits are not allowed with early media.' if early && @component_node.interrupt_on

    case @component_node.interrupt_on
    when :any, :dtmf
      interrupt = true
    end

    path = filenames.join '&'

    @call.send_progress if early

    if interrupt
      output_component = current_actor
      call.register_handler :ami, :name => 'DTMF', [:[], 'End'] => 'Yes' do |event|
        output_component.stop_by_redirect Punchblock::Component::Output::Complete::Success.new
      end
    end

    send_ref

    opts = early ? "#{path},noanswer" : path
    @call.execute_agi_command 'EXEC Playback', opts
  when :unimrcp
    @call.send_progress if early
    send_ref
    @call.execute_agi_command 'EXEC MRCPSynth', escape_commas(escaped_doc), mrcpsynth_options
  when :swift
    @call.send_progress if early
    send_ref
    @call.execute_agi_command 'EXEC Swift', swift_doc
  else
    raise OptionError, "The renderer #{rendering_engine} is unsupported."
  end
  send_success
rescue RubyAMI::Error => e
  complete_with_error "Terminated due to AMI error '#{e.message}'"
rescue UnrenderableDocError => e
  with_error 'unrenderable document error', e.message
rescue OptionError => e
  with_error 'option error', e.message
end

#setupObject



14
15
16
# File 'lib/punchblock/translator/asterisk/component/output.rb', line 14

def setup
  @media_engine = @call.translator.media_engine
end