Class: AGI
- Inherits:
-
Object
- Object
- AGI
- Defined in:
- lib/ruby-agi/agi.rb,
lib/ruby-agi/command.rb,
lib/ruby-agi/asterisk_variable.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#accountcode ⇒ Object
<method description>.
-
#answer ⇒ Object
Answers channel if not already in answer state.
-
#callerid ⇒ Object
method to read callerid, Ex.
-
#calleridname ⇒ Object
method to read calleridname, Ex.
-
#calleridnumber ⇒ Object
method to read calleridnumber, Ex.
-
#callingani2 ⇒ Object
<method description>.
-
#callingpres ⇒ Object
<method description>.
-
#callingtns ⇒ Object
<method description>.
-
#callington ⇒ Object
<method description>.
-
#channel ⇒ Object
<method description>.
-
#channel_status(channel = nil) ⇒ Object
Returns the status of the specified channel.
-
#context ⇒ Object
<method description>.
-
#debug=(val) ⇒ Object
<method description>.
-
#debug? ⇒ Boolean
<method description>.
-
#dial(telephone_number = nil, protocol = nil, username = nil, context = nil, timeout = nil, options = nil) ⇒ Object
method to dial out.
-
#dnid ⇒ Object
<method description>.
-
#enhanced ⇒ Object
<method description>.
-
#exec(asterisk_application, options = nil) ⇒ Object
Executes <application> with given <options>.
-
#extension ⇒ Object
<method description>.
-
#get_variable(name) ⇒ Object
method to read a variable.
-
#hangup(channel = nil) ⇒ Object
method to hang up the specified channel.
-
#initialize ⇒ AGI
constructor
constructor method of class AGI.
-
#jump_to(context = nil, extension = nil, priority = nil) ⇒ Object
method to jump in a specified context, extension and priority.
-
#language ⇒ Object
<method description>.
-
#noop(msg) ⇒ Object
method that Does nothing !!.
-
#priority ⇒ Object
<method description>.
-
#raw_command(str) ⇒ Object
<method description>.
-
#rdnid ⇒ Object
<method description>.
-
#receive_char(timeout) ⇒ Object
Receives a character of text on a channel, and discards any further characters after the first one waiting.
-
#receive_text(timeout) ⇒ Object
Receives a string text on a channel.
-
#record_file(filename, format = 'gsm', escape_digits = nil, timeout = nil, beep = true) ⇒ Object
Record to a file until <escape digits> are received as dtmf.
-
#request ⇒ Object
<method description>.
-
#say_digits(digit_string, escape_digits = nil) ⇒ Object
Say a given digit string, returning early if any of the given DTMF digits are received on the channel.
-
#say_number(number, escape_digits = nil) ⇒ Object
Say a given number, returning early if any of the given DTMF digits are received on the channel.
-
#say_phonetic(string, escape_digits = nil) ⇒ Object
Say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel.
-
#say_time(time = Time.now.to_i, escape_digits = '#') ⇒ Object
Say a given time, returning early if any of the given DTMF digits are received on the channel.
- #semaphore ⇒ Object
-
#send_image(image) ⇒ Object
Sends the given image on a channel.
-
#send_text(text) ⇒ Object
Sends the given text on a channel.
-
#set_auto_hangup(val) ⇒ Object
<method description>.
-
#set_caller_id(number) ⇒ Object
Changes the callerid of the current channel.
-
#set_context(context) ⇒ Object
Sets the context for continuation upon exiting the application.
-
#set_extension(extension) ⇒ Object
Changes the extension for continuation upon exiting the application.
-
#set_music(mode = true, moh_class = 'default') ⇒ Object
Enables/Disables the music on hold generator.
-
#set_priority(priority) ⇒ Object
Changes the priority for continuation upon exiting the application.
-
#set_variable(name, value) ⇒ Object
These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary.
-
#stream_file(filename, escape_digits = '#') ⇒ Object
Send the given file, allowing playback to be interrupted by the given digits, if any.
-
#tdd_mode(settings = true) ⇒ Object
Enable/Disable TDD transmission/reception on a channel.
-
#type ⇒ Object
<method description>.
-
#uniqueid ⇒ Object
<method description>.
-
#verbose(message, level = 3) ⇒ Object
Sends <message> to the console via verbose message system.
-
#wait_for_digit(timeout = nil) ⇒ Object
Waits up to <timeout> milliseconds for channel to receive a DTMF digit.
-
#wait_for_digits(filename, timeout = nil, max_digit = nil) ⇒ Object
method to get digit(s) pressing ‘#’ will always terminate the input process.
Constructor Details
#initialize ⇒ AGI
constructor method of class AGI
Parameters
-
none
Returns
-
self
43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby-agi/agi.rb', line 43 def initialize @@env = nil @@command = nil @@debug = nil @@stdin_semaphore = nil @@stdout_semaphore = nil @@stderr_semaphore = nil end |
Instance Method Details
#accountcode ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
413 414 415 |
# File 'lib/ruby-agi/agi.rb', line 413 def accountcode return env.accountcode end |
#answer ⇒ Object
Answers channel if not already in answer state.
Parameters
-
none
Returns
-
ReturnStatus object
438 439 440 |
# File 'lib/ruby-agi/agi.rb', line 438 def answer return command.answer end |
#callerid ⇒ Object
method to read callerid, Ex. “John Smith” <1234567890> regardless of asterisk version, method callerid would return “Caller Name” <Number>
Parameters
-
none
Returns
-
String : empty string for Unidentified
255 256 257 |
# File 'lib/ruby-agi/agi.rb', line 255 def callerid return env.callerid end |
#calleridname ⇒ Object
method to read calleridname, Ex. John Smith
Parameters
-
none
Returns
-
String : empty string for Unidentified
268 269 270 |
# File 'lib/ruby-agi/agi.rb', line 268 def calleridname return env.calleridname end |
#calleridnumber ⇒ Object
method to read calleridnumber, Ex. 1234567890
Parameters
-
none
Returns
-
String : empty string for Unidentified
281 282 283 |
# File 'lib/ruby-agi/agi.rb', line 281 def calleridnumber return env.calleridnumber end |
#callingani2 ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
305 306 307 |
# File 'lib/ruby-agi/agi.rb', line 305 def callingani2 return env.callingani2 end |
#callingpres ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
293 294 295 |
# File 'lib/ruby-agi/agi.rb', line 293 def callingpres return env.callingpres end |
#callingtns ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
329 330 331 |
# File 'lib/ruby-agi/agi.rb', line 329 def callingtns return env.callingtns end |
#callington ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
317 318 319 |
# File 'lib/ruby-agi/agi.rb', line 317 def callington return env.callington end |
#channel ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
205 206 207 |
# File 'lib/ruby-agi/agi.rb', line 205 def channel return env.channel end |
#channel_status(channel = nil) ⇒ Object
Returns the status of the specified channel. If no channel name is given the returns the status of the current channel.
Parameters
-
channel : name of the channel.
Returns
-
ReturnStatus object
464 465 466 |
# File 'lib/ruby-agi/agi.rb', line 464 def channel_status(channel=nil) return command.channel_status(channel) end |
#context ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
365 366 367 |
# File 'lib/ruby-agi/agi.rb', line 365 def context return env.context end |
#debug=(val) ⇒ Object
<method description>
Parameters
-
val(Boolean)
Returns
-
none
169 170 171 |
# File 'lib/ruby-agi/agi.rb', line 169 def debug=(val) @@debug = val end |
#debug? ⇒ Boolean
<method description>
Parameters
-
none
Returns
-
Boolean
181 182 183 |
# File 'lib/ruby-agi/agi.rb', line 181 def debug? return @@debug == true end |
#dial(telephone_number = nil, protocol = nil, username = nil, context = nil, 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
859 860 861 |
# File 'lib/ruby-agi/agi.rb', line 859 def dial(telephone_number=nil, protocol=nil, username=nil, context=nil, timeout=nil, =nil) return command.dial(telephone_number, protocol, username, context, timeout, ) end |
#dnid ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
341 342 343 |
# File 'lib/ruby-agi/agi.rb', line 341 def dnid return env.dnid end |
#enhanced ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
401 402 403 |
# File 'lib/ruby-agi/agi.rb', line 401 def enhanced return env.enhanced end |
#exec(asterisk_application, options = nil) ⇒ Object
Executes <application> with given <options>. Applications are the functions you use to create a dial plan in extensions.conf.
Parameters
-
application : Asterisk command of the application
-
options : options to be passed with the asterisk application
Returns
-
ReturnStatus object
479 480 481 |
# File 'lib/ruby-agi/agi.rb', line 479 def exec(asterisk_application, =nil) return command.exec(asterisk_application, ) end |
#extension ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
377 378 379 |
# File 'lib/ruby-agi/agi.rb', line 377 def extension return env.extension end |
#get_variable(name) ⇒ Object
method to read a variable
Parameters
-
name : name of the variable to read
Returns
-
ReturnStatus object
509 510 511 |
# File 'lib/ruby-agi/agi.rb', line 509 def get_variable(name) return command.get_variable(name) end |
#hangup(channel = nil) ⇒ Object
method to hang up the specified channel. If no channel name is given, hangs up the current channel.
Parameters
-
channel : name of the channel to hang up
Returns
-
ReturnStatus object
522 523 524 |
# File 'lib/ruby-agi/agi.rb', line 522 def hangup(channel=nil) return command.hangup(channel) end |
#jump_to(context = nil, extension = nil, priority = nil) ⇒ Object
method to jump in a specified context, extension and priority
Parameters
-
context : name of the context
-
extension : name of the extension
-
priority : name of the priority
Returns
-
none
874 875 876 |
# File 'lib/ruby-agi/agi.rb', line 874 def jump_to(context=nil, extension=nil, priority=nil) command.jump_to(context, extension, priority) end |
#language ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
217 218 219 |
# File 'lib/ruby-agi/agi.rb', line 217 def language return env.language end |
#noop(msg) ⇒ Object
method that Does nothing !!
Parameters
-
msg : message to pass this method
Returns
-
ReturnStatus object
success: 200 result=0
536 537 538 |
# File 'lib/ruby-agi/agi.rb', line 536 def noop(msg) return command.noop(msg) end |
#priority ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
389 390 391 |
# File 'lib/ruby-agi/agi.rb', line 389 def priority return env.priority end |
#raw_command(str) ⇒ Object
<method description>
Parameters
-
str(String) : asterisk command in raw format to be executed
Returns
-
ReturnStatus object
425 426 427 |
# File 'lib/ruby-agi/agi.rb', line 425 def raw_command(str) return command.raw_command(str) end |
#rdnid ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
353 354 355 |
# File 'lib/ruby-agi/agi.rb', line 353 def rdnid return env.rdnid end |
#receive_char(timeout) ⇒ Object
Receives a character of text on a channel, and discards any further characters after the first one waiting. Most channels do not support the reception of text. See Asterisk Text for details.
Parameters
-
timeout : maximum time to wait for input in seconds
negative or zero is not acceptable
Returns
-
ReturnStatus object
551 552 553 |
# File 'lib/ruby-agi/agi.rb', line 551 def receive_char(timeout) return command.receive_char(timeout) end |
#receive_text(timeout) ⇒ Object
Receives a string text on a channel. Most channels do not support the reception of text.
Parameters
-
timeout : time to wait for input in seconds
negative or zero is not acceptable
Returns
-
ReturnStatus object
566 567 568 |
# File 'lib/ruby-agi/agi.rb', line 566 def receive_text(timeout) return command.receive_text(timeout) end |
#record_file(filename, format = 'gsm', escape_digits = nil, timeout = nil, beep = true) ⇒ Object
Record to a file until <escape digits> are received as dtmf.
Parameters
-
filename : location of the file where the audio file will be saved
-
format : specify what kind of file will be recorded.
-
timeout : maximum record time in seconds
nil, negative or 0 for no timeout.
-
offset : [offset samples] is optional,
and if provided will seek to the offset without exceeding the end of the file.
-
silence : number of seconds of silence allowed before the function returns
despite the lack of dtmf digits or reaching timeout. Silence value must be preceeded by "s=" and is optional.
Returns
-
ReturnStatus object
587 588 589 |
# File 'lib/ruby-agi/agi.rb', line 587 def record_file(filename, format='gsm', escape_digits=nil, timeout=nil, beep=true) return command.record_file(filename, format, escape_digits, timeout, beep) end |
#request ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
193 194 195 |
# File 'lib/ruby-agi/agi.rb', line 193 def request return env.request end |
#say_digits(digit_string, escape_digits = nil) ⇒ Object
Say a given digit string, returning early if any of the given DTMF digits are received on the channel.
Parameters
-
number : number to announce
-
escape_digit : if digit pressed during playback, will return from announce
Returns
-
ReturnStatus (object)
failure: 200 result=-1 success: 200 result=0 digit pressed: 200 result=<digit> <digit> is the ascii code for the digit pressed.
606 607 608 |
# File 'lib/ruby-agi/agi.rb', line 606 def say_digits(digit_string, escape_digits=nil) return command.say_digits(digit_string, escape_digits) end |
#say_number(number, escape_digits = nil) ⇒ Object
Say a given number, returning early if any of the given DTMF digits are received on the channel.
Parameters
-
number : number to announce
-
escape_digit : if pressed, return from program
Returns
-
ReturnStatus object
620 621 622 |
# File 'lib/ruby-agi/agi.rb', line 620 def say_number(number, escape_digits=nil) return command.say_number(number, escape_digits) end |
#say_phonetic(string, escape_digits = nil) ⇒ Object
Say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel.
Parameters
-
string : character string to announce
-
escape_digit : digit to be pressed to escape from program
Returns
-
ReturnStatus (object)
634 635 636 |
# File 'lib/ruby-agi/agi.rb', line 634 def say_phonetic(string, escape_digits=nil) return command.say_phonetic(string, escape_digits) end |
#say_time(time = Time.now.to_i, escape_digits = '#') ⇒ Object
Say a given time, returning early if any of the given DTMF digits are received on the channel.
Parameters
-
time : number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
-
escape_digits : digit to be pressed to escape from the program
Returns
-
ReturnStatus (object)
648 649 650 |
# File 'lib/ruby-agi/agi.rb', line 648 def say_time(time=Time.now.to_i, escape_digits='#') return command.say_time(time, escape_digits) end |
#semaphore ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ruby-agi/agi.rb', line 149 def semaphore if block_given? stderr_semaphore.synchronize do stdout_semaphore.synchronize do stdin_semaphore.synchronize do yield end end end end end |
#send_image(image) ⇒ Object
Sends the given image on a channel. Most channels do not support the transmission of images. Image names should not include extensions.
Parameters
-
image : location of image
Returns
-
ReturnStatus (object)
663 664 665 |
# File 'lib/ruby-agi/agi.rb', line 663 def send_image(image) return command.send_image(image) end |
#send_text(text) ⇒ Object
Sends the given text on a channel. Most channels do not support the transmission of text. Text consisting of greater than one word should be placed in quotes since the command only accepts a single argument.
Parameters
-
text : text to be send
Returns
-
ReturnStatus (object)
678 679 680 |
# File 'lib/ruby-agi/agi.rb', line 678 def send_text(text) return command.send_text(text) end |
#set_auto_hangup(val) ⇒ Object
<method description>
Parameters
-
val(Integer) : time in secconds
Returns
-
ReturnStatus object
450 451 452 |
# File 'lib/ruby-agi/agi.rb', line 450 def set_auto_hangup(val) return command.set_auto_hangup(val) end |
#set_caller_id(number) ⇒ Object
Changes the callerid of the current channel.
Parameters
-
number : number to be set a callerid
Returns
-
ReturnStatus (object)
691 692 693 |
# File 'lib/ruby-agi/agi.rb', line 691 def set_caller_id(number) return command.set_caller_id(number) end |
#set_context(context) ⇒ Object
Sets the context for continuation upon exiting the application.
Parameters
-
context : name of the context
Returns
-
ReturnStatus object
704 705 706 |
# File 'lib/ruby-agi/agi.rb', line 704 def set_context(context) return command.set_context(context) end |
#set_extension(extension) ⇒ Object
Changes the extension for continuation upon exiting the application.
Parameters
-
extension: name or number of extension to be set
Returns
-
ReturnStatus object
717 718 719 |
# File 'lib/ruby-agi/agi.rb', line 717 def set_extension(extension) return command.set_extension(extension) end |
#set_music(mode = true, moh_class = 'default') ⇒ Object
Enables/Disables the music on hold generator.
Parameters
-
mode : on or off
-
moh_class : name of the music on hold class
'default' for not provided or nil
Returns
-
ReturnStatus object
744 745 746 |
# File 'lib/ruby-agi/agi.rb', line 744 def set_music(mode=true, moh_class='default') return command.set_music(mode, moh_class) end |
#set_priority(priority) ⇒ Object
Changes the priority for continuation upon exiting the application.
Parameters
-
priority : number of priority
Returns
-
ReturnStatus object
729 730 731 |
# File 'lib/ruby-agi/agi.rb', line 729 def set_priority(priority) return command.set_priority(priority) end |
#set_variable(name, value) ⇒ Object
These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary. Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted and any variables in that channel are deleted as well.
Parameters
-
variablename : name of the variable
-
value : value to be set for the variable
Returns
-
ReturnStatus object
763 764 765 |
# File 'lib/ruby-agi/agi.rb', line 763 def set_variable(name, value) return command.set_variable(name, value) end |
#stream_file(filename, escape_digits = '#') ⇒ Object
Send the given file, allowing playback to be interrupted by the given digits, if any. Use double quotes for the digits if you wish none to be permitted. If sample offset is provided then the audio will seek to sample offset before play starts. Remember, the file extension must not be included in the filename.
Parameters
-
filename : location of the file to be played
-
escape_digit: digit to be pressed to escape from playback
Returns
-
ReturnStatus object
781 782 783 |
# File 'lib/ruby-agi/agi.rb', line 781 def stream_file(filename, escape_digits='#') return command.stream_file(filename, escape_digits) end |
#tdd_mode(settings = true) ⇒ Object
Enable/Disable TDD transmission/reception on a channel. This function is currently (01July2005) only supported on Zap channels. As of 02July2005, this function never returns 0 (Not Capable). If it fails for any reason, -1 (Failure) will be returned, otherwise 1 (Success) will be returned. The capability for returning 0 if the channel is not capable of TDD MODE is a future plan.
Parameters
-
mode : mode of the tdd to be set
set tdd on if non-zero or 'true' specified
Returns
-
ReturnStatus object
800 801 802 |
# File 'lib/ruby-agi/agi.rb', line 800 def tdd_mode(settings=true) return command.tdd_mode(settings) end |
#type ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
229 230 231 |
# File 'lib/ruby-agi/agi.rb', line 229 def type return env.type end |
#uniqueid ⇒ Object
<method description>
Parameters
-
none
Returns
-
String
241 242 243 |
# File 'lib/ruby-agi/agi.rb', line 241 def uniqueid return env.uniqueid end |
#verbose(message, level = 3) ⇒ Object
Sends <message> to the console via verbose message system. The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later using the console ‘set verbose’ command. Messages are displayed on the console if their verbose level is less than or equal to desired verbosity set by the user. More important messages should have a low verbose level; less important messages should have a high verbose level.
Parameters
-
message : message to be send as log
-
level : verbose level to be set
[level] is the the verbose level (1-4) If you specify a verbose level less than 1 or greater than 4, the verbosity is 1. The default verbosity seems to be 0 (in 1.0.8), and supplying a 0 (zero) verbosity does work: the message will be displayed regardless of the console verbosity setting.
Returns
-
ReturnStatus object
826 827 828 |
# File 'lib/ruby-agi/agi.rb', line 826 def verbose(, level=3) return command.verbose(, level) end |
#wait_for_digit(timeout = nil) ⇒ Object
Waits up to <timeout> milliseconds for channel to receive a DTMF digit.
Parameters
-
timeout : maximum allow waiting time in seconds to get input
nil, zero or negative would be considered as infinite wait time
Returns
-
ReturnStatus object
841 842 843 |
# File 'lib/ruby-agi/agi.rb', line 841 def wait_for_digit(timeout=nil) return command.wait_for_digit(timeout) end |
#wait_for_digits(filename, timeout = nil, max_digit = nil) ⇒ Object
method to get digit(s) pressing ‘#’ will always terminate the input process
Parameters
-
filename : audio to be played before get as input
-
timeout : maximum allowed time in second(s) to receive each digit
wait for ever if timeout is nil or negative or zero
-
max_digit: maximum number of digits to get as input
wait for unlimited number of digits if max_digit is nil or negative or zero
Returns
-
ReturnStatus object
496 497 498 |
# File 'lib/ruby-agi/agi.rb', line 496 def wait_for_digits(filename, timeout=nil, max_digit=nil) return command.wait_for_digits(filename, timeout, max_digit) end |