Class: SignalWire::Relay::CollectAction

Inherits:
Action
  • Object
show all
Defined in:
lib/signalwire/relay/action.rb

Overview

Handle for play_and_collect or standalone collect.

Instance Attribute Summary

Attributes inherited from Action

#call, #completed, #control_id, #result

Instance Method Summary collapse

Methods inherited from Action

#_resolve, #_set_on_completed, #done?, #on_completed, #wait

Constructor Details

#initialize(call, control_id) ⇒ CollectAction

Returns a new instance of CollectAction.



165
166
167
168
# File 'lib/signalwire/relay/action.rb', line 165

def initialize(call, control_id)
  super(call, control_id, EVENT_CALL_COLLECT,
        %w[finished error no_input no_match])
end

Instance Method Details

#_check_event(event) ⇒ Object

play_and_collect shares a control_id across play and collect phases. Only resolve on collect events, not play events.



172
173
174
175
176
177
178
179
180
181
# File 'lib/signalwire/relay/action.rb', line 172

def _check_event(event)
  return unless event.event_type == EVENT_CALL_COLLECT

  result_data = event.params['result'] || {}
  if !result_data.empty? && !@completed
    _resolve(event)
  else
    super(event)
  end
end

#start_input_timersObject



193
194
195
# File 'lib/signalwire/relay/action.rb', line 193

def start_input_timers
  @call._execute('collect.start_input_timers', { 'control_id' => @control_id })
end

#stopObject



183
184
185
# File 'lib/signalwire/relay/action.rb', line 183

def stop
  @call._execute('play_and_collect.stop', { 'control_id' => @control_id })
end

#volume(vol) ⇒ Object



187
188
189
190
191
# File 'lib/signalwire/relay/action.rb', line 187

def volume(vol)
  @call._execute('play_and_collect.volume', {
    'control_id' => @control_id, 'volume' => vol
  })
end