Module: Larynx::Commands
- Included in:
- CallHandler
- Defined in:
- lib/larynx/commands.rb
Instance Method Summary collapse
- #answer(&block) ⇒ Object
- #break! ⇒ Object
- #connect(&block) ⇒ Object
- #filter(type, &block) ⇒ Object
- #hangup(&block) ⇒ Object
- #linger(&block) ⇒ Object
- #myevents(&block) ⇒ Object
- #phrase(data, options = {}, &block) ⇒ Object
- #playback(data, options = {}, &block) ⇒ Object (also: #play)
- #prompt(options = {}, &block) ⇒ Object
-
#read(options = {}, &block) ⇒ Object
Executes read command with some default values.
- #speak(data, options = {}, &block) ⇒ Object
Instance Method Details
#answer(&block) ⇒ Object
20 21 22 |
# File 'lib/larynx/commands.rb', line 20 def answer(&block) execute AppCommand.new('answer', &block) end |
#break! ⇒ Object
83 84 85 |
# File 'lib/larynx/commands.rb', line 83 def break! execute AppCommand.new('break'), true end |
#connect(&block) ⇒ Object
4 5 6 |
# File 'lib/larynx/commands.rb', line 4 def connect(&block) execute CallCommand.new('connect', &block) end |
#filter(type, &block) ⇒ Object
12 13 14 |
# File 'lib/larynx/commands.rb', line 12 def filter(type, &block) execute CallCommand.new('filter', type, &block) end |
#hangup(&block) ⇒ Object
24 25 26 |
# File 'lib/larynx/commands.rb', line 24 def hangup(&block) execute AppCommand.new('hangup', &block) end |
#linger(&block) ⇒ Object
16 17 18 |
# File 'lib/larynx/commands.rb', line 16 def linger(&block) execute CallCommand.new('linger', &block) end |
#myevents(&block) ⇒ Object
8 9 10 |
# File 'lib/larynx/commands.rb', line 8 def myevents(&block) execute CallCommand.new('myevents', &block) end |
#phrase(data, options = {}, &block) ⇒ Object
37 38 39 |
# File 'lib/larynx/commands.rb', line 37 def phrase(data, ={}, &block) execute AppCommand.new('phrase', data, , &block) end |
#playback(data, options = {}, &block) ⇒ Object Also known as: play
28 29 30 |
# File 'lib/larynx/commands.rb', line 28 def playback(data, ={}, &block) execute AppCommand.new('playback', data, , &block) end |
#prompt(options = {}, &block) ⇒ Object
79 80 81 |
# File 'lib/larynx/commands.rb', line 79 def prompt(={}, &block) execute Prompt.new(self, , &block).command end |
#read(options = {}, &block) ⇒ Object
Executes read command with some default values. Allows length option which expands into minimum and maximum length values. Length can be a range. Passes user input into callback block.
Defaults:
timeout: 5000 or 5 seconds
termchar: #
Example:
read(:minimum => 1, :maximum => 2, :sound_file => 'en/us/callie/conference/8000/conf-pin.wav') {|input|
speak "You entered #{input}"
}
Or
read(:length => 1..2, :sound_file => 'en/us/callie/conference/8000/conf-pin.wav') {|input|
speak "You entered #{input}"
}
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/larynx/commands.rb', line 62 def read(={}, &block) .reverse_merge!(:timeout => 5000, :var_name => 'read_result', :termchar => '#') [:bargein] = false if length = .delete(:length) values = length.is_a?(Range) ? [length.first, length.last] : [length, length] .merge!(:minimum => values[0], :maximum => values[1]) end order = [:minimum, :maximum, :sound_file, :var_name, :timeout, :termchar] data = order.inject('') {|data, key| data += " #{[key]}"; data }.strip execute AppCommand.new('read', data, ).after { block.call(response.body[:variable_read_result]) } end |
#speak(data, options = {}, &block) ⇒ Object
33 34 35 |
# File 'lib/larynx/commands.rb', line 33 def speak(data, ={}, &block) execute AppCommand.new('speak', data, , &block) end |