このスクリプトは、指定したキューに関するコール数を調べ、しきい値と比較した後、任意のサブメニューに移動するスクリプトのサンプルです。Runscript(コマンドを実行)というメニューから利用できます。
#!/usr/bin/perl use strict; use Asterisk::Manager; use Asterisk::AGI; ################################################################### # 2010 Communication Business Avenue, Inc. # GoToNextSubMenu Script # goto_nextsubmenu.agi QUEUE1 CallsNum SUBMENU1 SUBMENU2 # if Calls=<callsnum _x002D_=""> goto SUBMENU1 # if Calls>CallsNum -> goto SUBMENU2 ################################################################### $|=1; # Setup some variables my %AGI; my $tests = 0; my $fail = 0; my $pass = 0; use vars qw($astagi $astman $filename); $astagi = new Asterisk::AGI; $astman = new Asterisk::Manager; $astagi->verbose("*********** GotoNextSubmenu Check Start......"); # grab the queue1 my $queue1 = shift; $queue1 =~ s/([_\-0-9a-zA-Z]*?)/$1/; $queue1 = trim($queue1); $astagi->verbose("*********** QUEUE1=".$queue1); # grab the callNum my $callnum = shift; $callnum =~ s/([0-9]*?)/$1/; $astagi->verbose("*********** CallNum=".$callnum); # grab the submenu1 my $submenu1 = shift; $submenu1 =~ s/([_\-0-9a-zA-Z]*?)/$1/; $submenu1 = trim($submenu1); $astagi->verbose("*********** SUBMENU1=".$submenu1); # grab the submenu2 my $submenu2 = shift; $submenu2 =~ s/([_\-0-9a-zA-Z]*?)/$1/; $submenu2 = trim($submenu2); $astagi->verbose("*********** SUBMENU2=".$submenu2); $astman->user('AMIユーザ名'); $astman->secret('AMIパスワード'); $astman->host('localhost'); $astman->setcallback('DEFAULT', \&default_callback); $astman->connect || die $astman->error . "\n"; my $res = $astman->sendcommand( Action => 'QueueStatus', Queue => $queue1, Member => 'dummy111222333444555' ); $astagi->verbose("*********** res==".$res); $astman->eventloop; $astman->disconnect; sub default_callback { my $flag = 0; my $calls = 0; my (%stuff) = @_; foreach ( keys %stuff) { #$astagi->verbose("## key $_ ==>".$stuff{$_}."\n"); } foreach (keys %stuff) { if($stuff{$_} eq "QueueStatusComplete"){ $flag = 1; $astagi->verbose("***END OF THE DATA***"); }else { my $element = $_; if($element){ if($element eq "Calls"){ $calls = $stuff{$_}; $astagi->verbose("**** Found calls:".$calls); $astman->sendcommand( Action => 'Logoff'); $flag = 1; } #$astagi->verbose($element.":".$stuff{$_}); } } } if($flag){ $astman->sendcommand( Action => 'Logoff'); ################# # Last check ################# if($calls < $callnum){ $astagi->verbose("******** GOTO SUBMENU1:".$submenu1." **********"); $astagi->exec("GOTO ".$submenu1."|s|1"); } else { $astagi->verbose("******** GOTO SUBMENU2:".$submenu2." **********"); $astagi->exec("GOTO ".$submenu2."|s|1"); } ################# exit(0); } } sub trim { my @out = @_; for (@out) { s/^\s+//; s/\s+$//; } return wantarray ? @out : $out[0]; } sub checkresult { return; my ($res) = @_; my $retval; $tests++; chomp $res; if ($res =~ /^200/) { $res =~ /result=(-?\d+)/; if (!length($1)) { print STDERR "FAIL ($res)\n"; $fail++; } else { print STDERR "PASS ($1)\n"; $pass++; } } else { print STDERR "FAIL (unexpected result '$res')\n"; $fail++; } } </callsnum>
画像 0 | ||
---|---|---|
ギャラリーに表示すべき画像はありません。 |