Class: Command

Inherits:
AGI
  • Object
show all
Defined in:
lib/ruby-agi/command.rb

Instance Method Summary collapse

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

#initializeCommand

Returns a new instance of Command.



53
54
# File 'lib/ruby-agi/command.rb', line 53

def initialize
end

Instance Method Details

#answerObject

Raises:



70
71
72
73
74
75
# File 'lib/ruby-agi/command.rb', line 70

def answer
	cmd = "ANSWER"
	rs = exec_command(cmd, Answer)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#channel_status(channel = nil) ⇒ Object

Raises:



123
124
125
126
127
128
129
130
131
132
# File 'lib/ruby-agi/command.rb', line 123

def channel_status(channel=nil)
	if channel.nil?
		channel = ""
	end

	cmd = "CHANNEL STATUS #{channel.to_s}"
	rs = exec_command(cmd, ChannelStatus)
	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

  • ReturnStatus object

Command Reference: Dial(type/identifier,timeout,options,URL)



802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/ruby-agi/command.rb', line 802

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

Raises:



150
151
152
153
154
155
156
157
158
# File 'lib/ruby-agi/command.rb', line 150

def exec(application, options=nil)
	if options.nil?
		options = ""
	end
	cmd = "EXEC #{application.to_s} #{options.to_s}"
	rs = exec_command(cmd, Exec)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#get_variable(name) ⇒ Object

Raises:



208
209
210
211
212
213
# File 'lib/ruby-agi/command.rb', line 208

def get_variable(name)
	cmd = "GET VARIABLE #{name.to_s}"
	rs = exec_command(cmd, GetVariable)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#hangup(channel = nil) ⇒ Object

Raises:



229
230
231
232
233
234
235
236
237
238
# File 'lib/ruby-agi/command.rb', line 229

def hangup(channel=nil)
	if channel.nil?
		channel = ""
	end

	cmd = "HANGUP #{channel.to_s}"
	rs = exec_command(cmd, Hangup)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#jump_to(context, extension, priority) ⇒ Object



906
907
908
909
910
# File 'lib/ruby-agi/command.rb', line 906

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

Raises:



252
253
254
255
256
257
# File 'lib/ruby-agi/command.rb', line 252

def noop(msg)
	cmd = "NOOP #{msg.to_s}"
	rs = exec_command(cmd, Noop)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#raw_command(cmd) ⇒ Object

Raises:



826
827
828
829
830
# File 'lib/ruby-agi/command.rb', line 826

def raw_command(cmd)
	rs = exec_command(cmd)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#receive_char(timeout) ⇒ Object

Raises:

  • (ArgumentError)


277
278
279
280
281
282
283
284
285
# File 'lib/ruby-agi/command.rb', line 277

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, ReceiveChar)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#receive_text(timeout) ⇒ Object

Raises:

  • (ArgumentError)


304
305
306
307
308
309
310
311
312
# File 'lib/ruby-agi/command.rb', line 304

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, ReceiveText)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#record_file(filename, format = 'gsm', escape_digits = '#', timeout = nil, beep = true) ⇒ Object

Raises:



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/ruby-agi/command.rb', line 345

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, RecordFile)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#say_digits(digit_string, escape_digits = nil) ⇒ Object

Raises:



382
383
384
385
386
387
388
389
# File 'lib/ruby-agi/command.rb', line 382

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, SayDigits)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#say_number(number, escape_digits = nil) ⇒ Object

Raises:



409
410
411
412
413
414
415
# File 'lib/ruby-agi/command.rb', line 409

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, SayNumber)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#say_phonetic(string, escape_digits = nil) ⇒ Object

Raises:



435
436
437
438
439
440
441
# File 'lib/ruby-agi/command.rb', line 435

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, SayPhonetic)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#say_time(time = Time.now.to_i, escape_digits = '#') ⇒ Object

Raises:



461
462
463
464
465
466
467
# File 'lib/ruby-agi/command.rb', line 461

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, SayTime)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#send_image(image) ⇒ Object

Raises:



486
487
488
489
490
491
# File 'lib/ruby-agi/command.rb', line 486

def send_image(image)
	cmd = "SEND IMAGE #{image.to_s}"
	rs = exec_command(cmd, SendImage)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#send_text(text) ⇒ Object

Raises:



510
511
512
513
514
515
# File 'lib/ruby-agi/command.rb', line 510

def send_text(text)
	cmd = "SEND TEXT #{text.to_s}"
	rs = exec_command(cmd, SendText)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_auto_hangup(secs = 0) ⇒ Object

Raises:



92
93
94
95
96
97
# File 'lib/ruby-agi/command.rb', line 92

def set_auto_hangup(secs=0)
	cmd = "SET AUTOHANGUP #{secs.to_s}"
	rs = exec_command(cmd, SetAutoHangup)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_caller_id(number) ⇒ Object

Raises:



531
532
533
534
535
536
# File 'lib/ruby-agi/command.rb', line 531

def set_caller_id(number)
	cmd = "SET CALLERID #{number.to_s}"
	rs = exec_command(cmd, SetCallerID)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_context(context) ⇒ Object

Raises:



554
555
556
557
558
559
# File 'lib/ruby-agi/command.rb', line 554

def set_context(context)
	cmd = "SET CONTEXT #{context.to_s}"
	rs = exec_command(cmd, SetContext)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_extension(extension) ⇒ Object

Raises:



578
579
580
581
582
583
# File 'lib/ruby-agi/command.rb', line 578

def set_extension(extension)
	cmd = "SET EXTENSION #{extension.to_s}"
	rs = exec_command(cmd, SetExtension)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_music(mode = true, moh_class = 'default') ⇒ Object

Raises:



600
601
602
603
604
605
606
607
608
609
610
# File 'lib/ruby-agi/command.rb', line 600

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, SetMusic)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_priority(priority) ⇒ Object

Raises:



625
626
627
628
629
630
# File 'lib/ruby-agi/command.rb', line 625

def set_priority(priority)
	cmd = "SET PRIORITY #{priority.to_s}"
	rs = exec_command(cmd, SetPriority)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#set_variable(name, value) ⇒ Object

Raises:



651
652
653
654
655
656
# File 'lib/ruby-agi/command.rb', line 651

def set_variable(name, value)
	cmd = "SET VARIABLE #{name.to_s} \"#{value.to_s}\""
	rs = exec_command(cmd, SetVariable)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#stream_file(filename, escape_digits = '#') ⇒ Object

Raises:



682
683
684
685
686
687
688
689
690
691
# File 'lib/ruby-agi/command.rb', line 682

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, StreamFile)
	raise CommandError, rs.to_s if rs.command_error?

	return rs
end

#tdd_mode(mode = true) ⇒ Object

Raises:



714
715
716
717
718
719
720
721
722
723
724
# File 'lib/ruby-agi/command.rb', line 714

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, TDDMode)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#verbose(message, level = 3) ⇒ Object

Raises:



752
753
754
755
756
757
# File 'lib/ruby-agi/command.rb', line 752

def verbose(message, level=3)
	cmd = "VERBOSE \"#{message.to_s}\" #{level.to_s}"
	rs = exec_command(cmd, Verbose)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#wait_for_digit(timeout = nil) ⇒ Object

Raises:



777
778
779
780
781
782
783
784
# File 'lib/ruby-agi/command.rb', line 777

def wait_for_digit(timeout=nil)
	timeout = sanitize_timeout(timeout)
	
	cmd = "WAIT FOR DIGIT #{timeout.to_s}"
	rs = exec_command(cmd, WaitForDigit)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end

#wait_for_digits(filename, timeout = nil, max_digit = nil) ⇒ Object

Raises:



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/ruby-agi/command.rb', line 181

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, WaitForDigits)
	raise CommandError, rs.to_s if rs.command_error?
	return rs
end