Class: Command
- Inherits:
-
AGI
show all
- Defined in:
- lib/ruby-agi/command.rb
Instance Method Summary
collapse
-
#answer ⇒ Object
-
#channel_status(channel = nil) ⇒ Object
-
#dial(telephone_number = nil, protocol = nil, username = nil, context = 'default', timeout = nil, options = nil) ⇒ Object
-
#exec(application, options = nil) ⇒ Object
-
#get_variable(name) ⇒ Object
-
#hangup(channel = nil) ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#jump_to(context, extension, priority) ⇒ Object
-
#noop(msg) ⇒ Object
-
#raw_command(cmd) ⇒ Object
-
#receive_char(timeout) ⇒ Object
-
#receive_text(timeout) ⇒ Object
-
#record_file(filename, format = 'gsm', escape_digits = '#', timeout = nil, beep = true) ⇒ Object
-
#say_digits(digit_string, escape_digits = nil) ⇒ Object
-
#say_number(number, escape_digits = nil) ⇒ Object
-
#say_phonetic(string, escape_digits = nil) ⇒ Object
-
#say_time(time = Time.now.to_i, escape_digits = '#') ⇒ Object
-
#send_image(image) ⇒ Object
-
#send_text(text) ⇒ Object
-
#set_auto_hangup(secs = 0) ⇒ Object
-
#set_caller_id(number) ⇒ Object
-
#set_context(context) ⇒ Object
-
#set_extension(extension) ⇒ Object
-
#set_music(mode = true, moh_class = 'default') ⇒ Object
-
#set_priority(priority) ⇒ Object
-
#set_variable(name, value) ⇒ Object
-
#stream_file(filename, escape_digits = '#') ⇒ Object
-
#tdd_mode(mode = true) ⇒ Object
-
#verbose(message, level = 3) ⇒ Object
-
#wait_for_digit(timeout = nil) ⇒ Object
-
#wait_for_digits(filename, timeout = nil, max_digit = nil) ⇒ Object
Methods inherited from AGI
#accountcode, #callerid, #calleridname, #calleridnumber, #callingani2, #callingpres, #callingtns, #callington, #channel, #context, #debug=, #debug?, #dnid, #enhanced, #extension, #language, #priority, #rdnid, #request, #semaphore, #type, #uniqueid
Constructor Details
Returns a new instance of Command.
47
48
|
# File 'lib/ruby-agi/command.rb', line 47
def initialize
end
|
Instance Method Details
#answer ⇒ Object
64
65
66
67
68
69
|
# File 'lib/ruby-agi/command.rb', line 64
def answer
cmd = "ANSWER"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#channel_status(channel = nil) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/ruby-agi/command.rb', line 117
def channel_status(channel=nil)
if channel.nil?
channel = ""
end
cmd = "CHANNEL STATUS #{channel.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#dial(telephone_number = nil, protocol = nil, username = nil, context = 'default', timeout = nil, options = nil) ⇒ Object
method to dial out
Parameters
-
telephone_number : telephone_number or extension to dial
-
protocol : protocol to be used to make this call
-
username : username to be used to make this call using the specified protocol
-
context : name of the context to be used for authentication
-
timeout : maximum allowed time in seconds to make this call
-
options : options to be passed in ‘Dial’ command
Returns
Command Reference: Dial(type/identifier,timeout,options,URL)
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
|
# File 'lib/ruby-agi/command.rb', line 796
def dial(telephone_number=nil, protocol=nil, username=nil, context='default', timeout=nil, options=nil)
dial_string = nil
if protocol == 'LOCAL'
return nil if (telephone_number.nil? or context.nil?)
dial_string = "LOCAL/#{telephone_number}@#{context}"
elsif protocol == 'IAX2'
return nil if (telephone_number.nil? or username.nil? or context.nil?)
telephone_number.strip!
dial_string = "IAX2/#{username}@#{context}/#{telephone_number}"
elsif protocol == 'SIP'
else
return nil
end
timeout.nil? ? dial_string += "|" : dial_string += "|#{timeout}"
options.nil? ? dial_string += "|" : dial_string += "|#{options}"
rs = exec('DIAL', dial_string)
return rs
end
|
#exec(application, options = nil) ⇒ Object
144
145
146
147
148
149
150
151
152
|
# File 'lib/ruby-agi/command.rb', line 144
def exec(application, options=nil)
if options.nil?
options = ""
end
cmd = "EXEC #{application.to_s} #{options.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#get_variable(name) ⇒ Object
202
203
204
205
206
207
|
# File 'lib/ruby-agi/command.rb', line 202
def get_variable(name)
cmd = "GET VARIABLE #{name.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#hangup(channel = nil) ⇒ Object
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/ruby-agi/command.rb', line 223
def hangup(channel=nil)
if channel.nil?
channel = ""
end
cmd = "HANGUP #{channel.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#jump_to(context, extension, priority) ⇒ Object
903
904
905
906
907
|
# File 'lib/ruby-agi/command.rb', line 903
def jump_to(context, extension, priority)
set_context(context) if not context.nil?
set_extension(extension) if not extension.nil?
set_priority(priority) if not priority.nil?
end
|
#noop(msg) ⇒ Object
246
247
248
249
250
251
|
# File 'lib/ruby-agi/command.rb', line 246
def noop(msg)
cmd = "NOOP #{msg.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#raw_command(cmd) ⇒ Object
820
821
822
823
824
|
# File 'lib/ruby-agi/command.rb', line 820
def raw_command(cmd)
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#receive_char(timeout) ⇒ Object
271
272
273
274
275
276
277
278
279
|
# File 'lib/ruby-agi/command.rb', line 271
def receive_char(timeout)
timeout = sanitize_timeout(timeout)
raise(ArgumentError, "timeout need to be positive") if (timeout < 1)
cmd = "RECEIVE CHAR #{timeout.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#receive_text(timeout) ⇒ Object
298
299
300
301
302
303
304
305
306
|
# File 'lib/ruby-agi/command.rb', line 298
def receive_text(timeout)
timeout = sanitize_timeout(timeout)
raise(ArgumentError, "timeout need to be positive") if (timeout < 1)
cmd = "RECEIVE TEXT #{timeout.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#record_file(filename, format = 'gsm', escape_digits = '#', timeout = nil, beep = true) ⇒ Object
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
# File 'lib/ruby-agi/command.rb', line 339
def record_file(filename, format='gsm', escape_digits='#', timeout=nil, beep=true)
format = sanitize_file_format(format)
escape_digits = sanitize_escape_digits(escape_digits)
timeout = sanitize_timeout(timeout)
if ((escape_digits == "X") and (timeout == -1))
raise(ArgumentError, "need at least one valid escape digit or timeout need te positive")
end
cmd = "RECORD FILE #{filename} #{format} #{escape_digits} #{timeout}"
cmd = "#{cmd} beep" if beep == true
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#say_digits(digit_string, escape_digits = nil) ⇒ Object
376
377
378
379
380
381
382
383
|
# File 'lib/ruby-agi/command.rb', line 376
def say_digits(digit_string, escape_digits=nil)
escape_digits = sanitize_escape_digits(escape_digits)
cmd = "SAY DIGITS #{digit_string.to_s} #{escape_digits}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#say_number(number, escape_digits = nil) ⇒ Object
403
404
405
406
407
408
409
|
# File 'lib/ruby-agi/command.rb', line 403
def say_number(number, escape_digits=nil)
escape_digits = sanitize_escape_digits(escape_digits)
cmd = "SAY NUMBER #{number.to_s} #{escape_digits.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#say_phonetic(string, escape_digits = nil) ⇒ Object
429
430
431
432
433
434
435
|
# File 'lib/ruby-agi/command.rb', line 429
def say_phonetic(string, escape_digits=nil)
escape_digits = sanitize_escape_digits(escape_digits)
cmd = "SAY PHONETIC #{string.to_s} #{escape_digits}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#say_time(time = Time.now.to_i, escape_digits = '#') ⇒ Object
455
456
457
458
459
460
461
|
# File 'lib/ruby-agi/command.rb', line 455
def say_time(time=Time.now.to_i, escape_digits='#')
escape_digits = sanitize_escape_digits(escape_digits)
cmd = "SAY TIME #{time.to_s} #{escape_digits.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#send_image(image) ⇒ Object
480
481
482
483
484
485
|
# File 'lib/ruby-agi/command.rb', line 480
def send_image(image)
cmd = "SEND IMAGE #{image.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#send_text(text) ⇒ Object
504
505
506
507
508
509
|
# File 'lib/ruby-agi/command.rb', line 504
def send_text(text)
cmd = "SEND TEXT #{text.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_auto_hangup(secs = 0) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/ruby-agi/command.rb', line 86
def set_auto_hangup(secs=0)
cmd = "SET AUTOHANGUP #{secs.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_caller_id(number) ⇒ Object
525
526
527
528
529
530
|
# File 'lib/ruby-agi/command.rb', line 525
def set_caller_id(number)
cmd = "SET CALLERID #{number.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_context(context) ⇒ Object
548
549
550
551
552
553
|
# File 'lib/ruby-agi/command.rb', line 548
def set_context(context)
cmd = "SET CONTEXT #{context.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_extension(extension) ⇒ Object
572
573
574
575
576
577
|
# File 'lib/ruby-agi/command.rb', line 572
def set_extension(extension)
cmd = "SET EXTENSION #{extension.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_music(mode = true, moh_class = 'default') ⇒ Object
594
595
596
597
598
599
600
601
602
603
604
|
# File 'lib/ruby-agi/command.rb', line 594
def set_music(mode=true, moh_class='default')
if ((mode == true) or (not (mode == 0)))
mode = 'ON'
else
mode = 'OFF'
end
cmd = "SET MUSIC #{mode.to_s} #{moh_class.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_priority(priority) ⇒ Object
619
620
621
622
623
624
|
# File 'lib/ruby-agi/command.rb', line 619
def set_priority(priority)
cmd = "SET PRIORITY #{priority.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#set_variable(name, value) ⇒ Object
645
646
647
648
649
650
|
# File 'lib/ruby-agi/command.rb', line 645
def set_variable(name, value)
cmd = "SET VARIABLE #{name.to_s} \"#{value.to_s}\""
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#stream_file(filename, escape_digits = '#') ⇒ Object
676
677
678
679
680
681
682
683
684
685
|
# File 'lib/ruby-agi/command.rb', line 676
def stream_file(filename, escape_digits='#')
escape_digits = sanitize_escape_digits(escape_digits)
cmd = "STREAM FILE #{filename.to_s} #{escape_digits}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#tdd_mode(mode = true) ⇒ Object
708
709
710
711
712
713
714
715
716
717
718
|
# File 'lib/ruby-agi/command.rb', line 708
def tdd_mode(mode=true)
if ((mode == true) or ( not (mode == 1)))
mode = 'ON'
else
mode = 'OFF'
end
cmd = "TDD MODE #{mode.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#verbose(message, level = 3) ⇒ Object
746
747
748
749
750
751
|
# File 'lib/ruby-agi/command.rb', line 746
def verbose(message, level=3)
cmd = "VERBOSE \"#{message.to_s}\" #{level.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#wait_for_digit(timeout = nil) ⇒ Object
771
772
773
774
775
776
777
778
|
# File 'lib/ruby-agi/command.rb', line 771
def wait_for_digit(timeout=nil)
timeout = sanitize_timeout(timeout)
cmd = "WAIT FOR DIGIT #{timeout.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|
#wait_for_digits(filename, timeout = nil, max_digit = nil) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/ruby-agi/command.rb', line 175
def wait_for_digits(filename, timeout=nil, max_digit=nil)
timeout = sanitize_timeout(timeout)
max_digit = sanitize_max_digit(max_digit)
cmd = "GET DATA #{filename.to_s} #{timeout.to_s} #{max_digit.to_s}"
rs = exec_command(cmd)
raise CommandError, rs.to_s if rs.command_error?
return rs
end
|