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, #execute_subcommand, #setup_handlers, #stop

Methods inherited from Component

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

Methods included from Logger

#level=, #logger, logger

Constructor Details

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

Returns a new instance of Prompt.



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

def initialize(call:, collect:, play:, volume: nil)
  super(call: call)
  @play = play
  @collect = collect
  @volume = volume
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



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

def event_type
  Relay::CallNotification::COLLECT
end

#inner_paramsObject



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

def inner_params
  prm = {
    node_id: @call.node_id,
    call_id: @call.id,
    control_id: control_id,
    play: @play,
    collect: @collect
  }
  prm[:volume] = @volume unless @volume.nil?
  prm
end

#methodObject



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

def method
  Relay::ComponentMethod::PROMPT
end

#notification_handler(event) ⇒ Object



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

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

#volume(setting) ⇒ Object



51
52
53
# File 'lib/signalwire/relay/calling/component/prompt.rb', line 51

def volume(setting)
  execute_subcommand '.volume', Signalwire::Relay::Calling::PromptVolumeResult, { volume: setting }
end