微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Asterisk perl agi

近期在研究asterisk的agi,因使用了perl去写脚本,故参考了voip-info的文章

现将perl agi的模块转进来,以供日后参考。

以下为原文:

Asterisk perl agi

Asterisk::AGI perl module documentation

NAME

Asterisk::AGI – Simple Asterisk Gateway Interface Class

SYnopSIS

use Asterisk::AGI;

$AGI = new Asterisk::AGI;

# pull AGI variables into %input

%input = $AGI->ReadParse();

# say the number 1984

$AGI->say_number(1984);

DESCRIPTION

This module should make it easier to write scripts that interact with the asterisk open source pbx via AGI (aster�isk gateway interface)

CALLBACKS

Callbacks provide a handy way receiving events like hangups. To use the callback function,simply define a function to handle the callback and then tell Perl AGI which funtion it is by sending it a reference. Here is an example:

use Asterisk::AGI;

# the AGI object

my $agi = new Asterisk::AGI;

# send callback reference

$agi->setcallback(/&callback);

# our callback function

sub callback(){

warn “The call has ended/n”;

set_context($context);

exit;

}

AGI COMMANDS

* $AGI->stream_file($filename,$digits)

Executes AGI Command “STREAM FILE $filename $digits”

This command instructs Asterisk to play the given sound file and listen for the given dtmf digits. The fileextension must not be used in the filename because Asterisk will find the most appropriate file type.

Example: $AGI->stream_file(‘demo-echotest’,‘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.

* $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.

* $AGI->send_image($image)

Executes AGI Command “SEND IMAGE $image

Sends 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.

* $AGI->say_number($number,$digits)

Executes AGI Command “SAY NUMBER $number $digits”

Says the given $number,returning early if any of the $digits are received.

Example: $AGI->say_number(‘98765′);

Returns: -1 on error or hangup,or the ASCII numerical value of the digit of one was pressed.

* $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,or the ASCII numerical value of the digit of one was pressed.

* $AGI->answer()

Executes AGI Command “ANSWER”

Answers channel if not already in answer state.

Example: $AGI->answer();

Returns: -1 on channel failure,or 0 if successful.

* $AGI->get_data($filename,$timeout,$maxdigits)

Executes AGI Command “GET DATA $filename $timeout $maxdigits”

Streams $filename and returns when $maxdigits have been received or when $timeout has been reached. Timeout is specified in ms.

Example: $AGI->get_data(‘demo-welcome’,15000,5);

* $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.

* $AGI->set_context($context)

Executes AGI Command “SET CONTEXT $context”

Changes the context for continuation upon exiting the agi application.

Example: $AGI->set_context(‘dialout’);

Returns: Always returns 0.

* $AGI->set_extension($extension)

Executes AGI Command “SET EXTENSION $extension”

Changes the extension for continuation upon exiting the agi application.

Example: $AGI->set_extension(‘7′);

Returns: Always returns 0.

* $AGI->set_priority($priority)

Executes AGI Command “SET PRIORITY $priority”

Changes the priority for continuation upon exiting the agi application.

Example: $AGI->set_priority(1);

Returns: Always returns 0.

* $AGI->hangup($channel)

Executes AGI Command “HANGUP $channel”

Hangs up the passed $channel,or the current channel if $channel is not passed. It is left to the AGI script to exit properly,otherwise you Could end up with zombies.

Example: $AGI->hangup();

Returns: Always returns 1.

* $AGI->exec($app,$options)

Executes AGI Command “EXEC $app $options”

The most powerful AGI command. Executes the given application passing the given options.

Example: $AGI->exec(‘Dial’,‘Zap/g2/8005551212′);

Returns: -2 on failure to find application,or what ever the given application returns.

* $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.

* $AGI->get_variable($variable)

Executes AGI Command “GET VARIABLE $variablename”

Gets the channel variable <variablename>.

Example: $AGI->get_variable(’status’);

Returns: The value of the variable,or undef if variable does not exist.

* $AGI->verbose($message,$level)

Executes AGI Command “VERBOSE $message $level”

Logs $message with verboselevel $level.

Example: $AGI->verbose(“System Crashed/n”,1);

Returns: Always returns 1.

* $AGI->database_get($family,$key)

Executes AGI Command “DATABASE GET $family $key”

Example: $var = $AGI->database_get(‘test’,’status’);

Returns: The value of the variable,or undef if variable does not exist.

* $AGI->database_put($family,$key,$value)

Executes AGI Command “DATABASE PUT $family $key $value”

Set/modifes database entry <family>/<key> to <value>.

Example: $AGI->database_put(‘test’,’status’,‘authorized’);

Returns: 1 on success,0 otherwise.

* $AGI->database_del($family,$key)

Executes AGI Command “DATABASE DEL $family $key”

Removes database entry <family>/<key>.

Example: $AGI->database_del(‘test’,’status’);

Returns: 1 on success,0 otherwise.

* $AGI->database_deltree($family,$key)

Executes AGI Command “DATABASE DELTREE $family $key”

Deletes a family or specific keytree within a family in the Asterisk database.

Example: $AGI->database_deltree(‘test’,’status’);

Example: $AGI->database_deltree(‘test’);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐