Module: AdhearsionCpa::ControllerMethods

Defined in:
lib/adhearsion_cpa/controller_methods.rb

Instance Method Summary collapse

Instance Method Details

#detect_tone(*arguments) ⇒ PunchBlock::Signal?

Detects a tone

Examples:

Wait 5 seconds to detect a fax tone

detect_tone "fax-cng", timeout: 5

Check for multiple tone types

detect_tone "fax-ced", :modem, timeout: 5

Check for a type, with options

detect_tone :speech, maxTime: 4000, minSpeechDuration: 4000, timeout: 5

Check for a type, with options, and another type without

detect_tone({:dtmf => {}, speech: {maxTime: 4000, minSpeechDuration: 4000}}, timeout: 5)

Returns:

  • (PunchBlock::Signal)

    if one of the requested tones was detected

  • (nil)

    if none of the requested tones were detected in time



18
19
20
21
# File 'lib/adhearsion_cpa/controller_methods.rb', line 18

def detect_tone(*arguments)
  options = arguments.last.is_a?(Hash) && arguments.count > 1 ? arguments.pop : {}
  ToneDetector.new(self).detect_tones arguments, options
end

#detect_tone!(*arguments) ⇒ Object

Begin asynchronous tone detection, and run the block when the tone is detected

Examples:

Asynchronous wait for a dtmf

detect_tone :dtmf, timeout: -1 { |detected| logger.info "Beep! Customer pushed #{detected.inspect}"}

Asynchronous wait for dtmf presses, running the block multiple times if multiple signals are detected



28
29
30
31
# File 'lib/adhearsion_cpa/controller_methods.rb', line 28

def detect_tone!(*arguments)
  options = arguments.last.is_a?(Hash) && arguments.count > 1 ? arguments.pop : {}
  ToneDetector.new(self).detect_tones arguments, options.merge(async: true), &Proc.new
end