Class: Signalwire::Relay::Calling::Prompt

Inherits:
ControlComponent show all
Defined in:
lib/signalwire/relay/calling/component/prompt.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#blocker, #call, #completed, #event, #execute_result, #state, #successful

Instance Method Summary collapse

Methods inherited from ControlComponent

#control_id, #setup_handlers, #stop

Methods inherited from Component

#check_for_waiting_events, #create_blocker, #execute, #execute_params, #handle_execute_result, #payload, #setup_handlers, #setup_waiting_events, #terminate, #unblock, #wait_for, #wait_on_blocker

Constructor Details

#initialize(call:, collect:, play:) ⇒ Prompt

Returns a new instance of Prompt.



6
7
8
9
10
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 6

def initialize(call:, collect:, play:)
  super(call: call)
  @play = play
  @collect = collect
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 5

def input
  @input
end

#terminatorObject (readonly)

Returns the value of attribute terminator.



5
6
7
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 5

def terminator
  @terminator
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 5

def type
  @type
end

Instance Method Details

#event_typeObject



16
17
18
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 16

def event_type
  Relay::CallNotification::COLLECT
end

#inner_paramsObject



20
21
22
23
24
25
26
27
28
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 20

def inner_params
  {
    node_id: @call.node_id,
    call_id: @call.id,
    control_id: control_id,
    play: @play,
    collect: @collect
  }
end

#methodObject



12
13
14
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 12

def method
  Relay::ComponentMethod::PROMPT
end

#notification_handler(event) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 30

def notification_handler(event)
  @completed = true
  result = event.call_params[:result]
  @type = result[:type]
  @state = @type

  if @type == Relay::CallPromptState::DIGIT
    digit_event(result)
  elsif type == Relay::CallPromptState::SPEECH
    speech_event(result)
  else
    @state = @type
    @successful = false
  end

  check_for_waiting_events
end