📄 agi.pm
字号:
Example: $AGI->hangup();Returns: Always returns 1=cutsub hangup { my ($self, $channel) = @_; if ($channel) { return $self->execute("HANGUP $channel"); } else { return $self->execute("HANGUP"); }}=item $AGI->noop()Executes AGI Command "NOOP"Does absolutely nothing except pop up a log message. Useful for outputting debugging information to the Asterisk console.Example: $AGI->noop("Test Message");Returns: -1 on hangup or error, 0 otherwise=cutsub noop { my ($self, $string) = @_; return $self->execute("NOOP $string");}=item $AGI->receive_char($timeout)Executes AGI Command "RECEIVE CHAR $timeout"Receives a character of text on a channel. Specify timeout to be the maximumtime to wait for input in milliseconds, or 0 for infinite. Most channels do notsupport the reception of text. Example: $AGI->receive_char(3000);Returns: Returns the decimal value of the character if oneis received, or 0 if the channel does not support text reception. Returns -1only on error/hangup.=cutsub receive_char { my ($self, $timeout) = @_;#wait forever if timeout is not set. is this the prefered default? $timeout = 0 if (!defined($timeout)); return $self->execute("RECEIVE CHAR $timeout");}=item $AGI->receive_text($timeout)Executes AGI Command "RECEIVE TEXT $timeout"Receives a string of text on a channel. Specify timeout to be the maximum timeto wait for input in milliseconds, or 0 for infinite. Most channels do notsupport the reception of text. Example: $AGI->receive_text(3000);Returns: Returns the string of text if received, or -1 for failure, error or hangup.=cutsub receive_text { my ($self, $timeout) = @_;#wait forever if timeout is not set. is this the prefered default? $timeout = 0 if (!defined($timeout)); return $self->execute("RECEIVE TEXT $timeout");}=item $AGI->record_file($filename, $format, $digits, $timeout, $beep, $offset, $beep, $silence)Executes AGI Command "RECORD FILE $filename $format $digits $timeout [$offset [$beep [s=$silence]]]"Record to a file until $digits are received as dtmf.The $format will specify what kind of file will be recorded.The $timeout is the maximum record time in milliseconds, or -1 for no timeout.$offset samples is optional, and if provided will seek to the offset withoutexceeding the end of the file.$silence is the number of seconds of silence allowed before the functionreturns despite the lack of dtmf digits or reaching timeout.Example: $AGI->record_file('foo', 'wav', '#', '5000', '0', 1, '2');Returns: 1 on success, -1 on hangup or error.=cutsub record_file { my ($self, $filename, $format, $digits, $timeout, $offset, $beep, $silence) = @_; my $extra = ''; return -1 if (!defined($filename)); $digits = '""' if (!defined($digits)); $extra .= $offset if (defined($offset)); $extra .= ' ' . $beep if (defined($beep)); $extra .= ' s=' . $silence if (defined($silence)); return $self->execute("RECORD FILE $filename $format $digits $timeout $extra");}=item $AGI->say_alpha($string, $digits)Executes AGI Command "SAY ALPHA $string $digits"Say a given character string, returning early if any of the given DTMF $digitsare received on the channel. Returns Example: $AGI->say_alpha('Joe Smith', '#');Returns: 0 if playback completes without a digit being pressed; the ASCII numerical value of the digit if one was pressed; -1 on error/hangup.=cutsub say_alpha { my ($self, $string, $digits) = @_; $digits = '""' if (!defined($digits)); return -1 if (!defined($string)); return $self->execute("SAY ALPHA $string $digits");}=item $AGI->say_date($time [, $digits])=cut=item $AGI->say_time($time [, $digits])=cut=item $AGI->say_datetime($time [, $digits [, $format [, $timezone]]])Executes AGI Command "SAY DATE $number $digits"Executes AGI Command "SAY TIME $number $digits"Executes AGI Command "SAY DATETIME $number $digits $format $timezone"Say a given date or time, returning early if any of the optional DTMF $digits arereceived on the channel. $time is number of seconds elapsed since 00:00:00 onJanuary 1, 1970, Coordinated Universal Time (UTC), commonly known as"unixtime." For say_datetime, $format is the format the time should be said in; seevoicemail.conf (defaults to "ABdY 'digits/at' IMp"). Acceptable values for$timezone can be found in /usr/share/zoneinfo. Defaults to machine default.Example: $AGI->say_date('100000000'); $AGI->say_time('100000000', '#'); $AGI->say_datetime('100000000', '#', 'ABdY IMp', 'EDT');Returns: -1 on error or hangup; 0 if playback completes without a digit being pressed; the ASCII numerical value of the digit of one was pressed.=cutsub say_datetime_all { my ($self, $type, $time, $digits, $format, $timezone) = @_; my $ret = 0; $digits = '""' if (!defined($digits)); return -1 if (!defined($time)); if ($type == 'date') { $ret = $self->execute("SAY DATE $time $digits"); } elsif ($type == 'time') { $ret = $self->execute("SAY TIME $time $digits"); } elsif ($type == 'datetime') { $ret = $self->execute("SAY DATETIME $time $digits $format $timezone"); } else { $ret = -1; } return $ret;}sub say_date { my ($self, $time, $digits) = @_; return $self->say_datetime_all('date', $time, $digits);}sub say_time { my ($self, $time, $digits) = @_; return $self->say_datetime_all('time', $time, $digits);}sub say_datetime { my ($self, $time, $digits, $format, $timezone) = @_; return $self->say_datetime_all('datetime', $time, $digits, $format, $timezone);}=item $AGI->say_digits($number, $digits)Executes AGI Command "SAY DIGITS $number $digits"Says the given digit string $number, returning early if any of the $digits are received.Example: $AGI->say_digits('8675309');Returns: -1 on error or hangup,0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit of one was pressed.=cutsub say_digits { my ($self, $number, $digits) = @_; $digits = '""' if (!defined($digits)); return -1 if (!defined($number)); $number =~ s/\D//g; return $self->execute("SAY DIGITS $number $digits");}=item $AGI->say_number($number, $digits, $gender)Executes AGI Command "SAY NUMBER $number $digits [$gender]"Says the given $number, returning early if any of the $digits are received.Example: $AGI->say_number('98765');Returns: -1 on error or hangup,0 if playback completes without a digit being pressed, or the ASCII numerical value of the digit of one was pressed.=cutsub say_number { my ($self, $number, $digits, $gender) = @_; $digits = '""' if (!defined($digits)); return -1 if (!defined($number)); $number =~ s/\D//g; return $self->execute("SAY NUMBER $number $digits $gender");}=item $AGI->say_phonetic($string, $digits)Executes AGI Command "SAY PHONETIC $string $digits"Say a given character string with phonetics, returning early if any of thegiven DTMF digits are received on the channel.Example: $AGI->say_phonetic('Joe Smith', '#');Returns: 0 if playback completes without a digit being pressed; the ASCII numerical value of the digit if one was pressed; -1 on error/hangup.=cutsub say_phonetic { my ($self, $string, $digits) = @_; $digits = '""' if (!defined($digits)); return -1 if (!defined($string)); return $self->execute("SAY PHONETIC $string $digits");}=item $AGI->send_image($image)Executes AGI Command "SEND IMAGE $imageSends the given image on a channel. Most channels do not support the transmission of images.Example: $AGI->send_image('image.png');Returns: -1 on error or hangup,0 if the image was sent or if the channel does not support image transmission.=cutsub send_image { my ($self, $image) = @_; return -1 if (!defined($image)); return $self->execute("SEND IMAGE $image");}=item $AGI->send_text($text)Executes AGI Command "SEND TEXT "$text"Sends the given text on a channel. Most channels do not support the transmission of text.Example: $AGI->send_text('You've got mail!');Returns: -1 on error or hangup,0 if the text was sent or if the channel does not support text transmission.=cutsub send_text { my ($self, $text) = @_; return 0 if (!defined($text)); return $self->execute("SEND TEXT \"$text\"");}=item $AGI->set_autohangup($time)Executes AGI Command "SET AUTOHANGUP $time"Cause the channel to automatically hangup at <time> seconds in the future.Of course it can be hungup before then as well.Setting to 0 will cause the autohangup feature to be disabled on this channel.Example: $AGI->set_autohangup(60);Returns: Always returns 1=cutsub set_autohangup { my ($self, $time) = @_; $time = 0 if (!defined($time)); return $self->execute("SET AUTOHANGUP $time");}=item $AGI->set_callerid($number)Executes AGI Command "SET CALLERID $number"Changes the callerid of the current channel to <number>Example: $AGI->set_callerid('9995551212');Returns: Always returns 1=cutsub set_callerid { my ($self, $number) = @_; return if (!defined($number)); return $self->execute("SET CALLERID $number");}=item $AGI->set_context($context)Executes AGI Command "SET CONTEXT $context"Changes the context for continuation upon exiting the agi applicationExample: $AGI->set_context('dialout');Returns: Always returns 0=cutsub set_context { my ($self, $context) = @_; return -1 if (!defined($context)); return $self->execute("SET CONTEXT $context");}=item $AGI->set_extension($extension)Executes AGI Command "SET EXTENSION $extension"Changes the extension for continuation upon exiting the agi applicationExample: $AGI->set_extension('7');Returns: Always returns 0=cutsub set_extension { my ($self, $extension) = @_; return -1 if (!defined($extension)); return $self->execute("SET EXTENSION $extension");}=item $AGI->set_music($mode [, $class])Executes AGI Command "SET MUSIC $mode $class"Enables/Disables the music on hold generator. If $class is not specified, thenthe default music on hold class will be used. $mode must be "on" or "off".Example: $AGI->set_music("on", "happy"); $AGI->set_music("off");Returns: -1 on hangup or error, 0 otherwise.=cutsub set_music { my ($self, $mode, $class) = @_; return $self->execute("SET MUSIC $mode $class");}=item $AGI->set_priority($priority)Executes AGI Command "SET PRIORITY $priority"Changes the priority for continuation upon exiting the agi applicationExample: $AGI->set_priority(1);Returns: Always returns 0=cutsub set_priority { my ($self, $priority) = @_; return -1 if (!defined($priority)); return $self->execute("SET PRIORITY $priority");}=item $AGI->set_variable($variable, $value)Executes AGI Command "SET VARIABLE $variable $value"Sets the channel variable <variablename> to <value>Example: $AGI->set_variable('status', 'authorized');Returns: Always returns 1=cutsub set_variable { my ($self, $variable, $value) = @_; return $self->execute("SET VARIABLE $variable \"$value\"");}=item $AGI->stream_file($filename, $digits, $offset)Executes AGI Command "STREAM FILE $filename $digits [$offset]"This command instructs Asterisk to play the given sound file and listen for the given dtmf digits. Thefileextension must not be used in the filename because Asterisk will find the most appropriate filetype. $filename can be an array of files or a single filename.Example: $AGI->stream_file('demo-echotest', '0123'); $AGI->stream_file(['demo-echotest', 'demo-welcome'], '0123');Returns: -1 on error or hangup,0 if playback completes without a digit being pressed,or the ASCII numerical value of the digit if a digit was pressed=cutsub stream_file { my ($self, $filename, $digits, $offset) = @_; my $ret = undef; $digits = '""' if (!defined($digits)); return -1 if (!defined($filename)); if (ref($filename) eq "ARRAY") { $ret = $self->_recurse(@_); } else { $ret = $self->execute("STREAM FILE $filename $digits $offset"); } return $ret;}=item $AGI->tdd_mode($mode)Executes AGI Command "TDD MODE <on|off>"Enable/Disable TDD transmission/reception on a channel. Example: $AGI->tdd_mode('on');Returns: Returns 1 if successful, or 0 if channel is not TDD-capable.=cutsub tdd_mode { my ($self, $mode) = @_; return 0 if (!defined($mode)); return $self->execute("TDD MODE $mode");}=item $AGI->verbose($message, $level)Executes AGI Command "VERBOSE $message $level"Logs $message with verboselevel $levelExample: $AGI->verbose("System Crashed\n", 1);Returns: Always returns 1=cutsub verbose { my ($self, $message, $level) = @_; return $self->execute("VERBOSE \"$message\" $level");}=item $AGI->wait_for_digit($timeout)Executes AGI Command "WAIT FOR DIGIT $timeout"Waits up to 'timeout' milliseconds for channel to receive a DTMF digit.Use -1 for the timeout value if you desire the call to block indefinitely.Example: $AGI->wait_for_digit($timeout);Returns: Returns -1 on channel failure, 0 if no digit is received in the timeout, or the numerical value of the ascii of the digit if one is received.=cutsub wait_for_digit { my ($self, $timeout) = @_; $timeout = -1 if (!defined($timeout)); return $self->execute("WAIT FOR DIGIT $timeout");}1;__END__=back
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -