[Asterisk-Users] PHP/AGI Problem
Benjamin West
bewest at gmail.com
Wed May 25 13:09:03 MST 2005
First of all, I don't see where $y is initialised or used except in
the test condition of the while loop. That's probably your problem.
Why not move the logic of the top loop into the dialplan?
exten => s, 1, Answer
exten => s, 2, AGI(script)
exten => s, 3, Hangup()
exten => h, 4, DeadAGI(cleanup)
then in your default case in your script send "SET PRIORITY 2" to *.
On 5/25/05, Jon Farmer <viperdude_uk at yahoo.co.uk> wrote:
> Moises Silva wrote:
>
> >could you post the script, the output of the script in the asterisk
> >console and which asterisk version are you working with?
> >
> >
> >
> See below
>
> This is just a proof of concept script so its a bit basic...
>
>
> #!/usr/bin/php -q
> <?php
> set_time_limit(30);
> require "phpagi.php";
> error_reporting(0);
> $agi = new AGI();
> $agi->agi_exec("ANSWER");
> while($y != 1){
> $response = "";
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/enter_ref #");
> $res = getDTMF("#",7);
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/you_entered #");
> $response .= trim($res);
> sayNumber($response);
> switch($response) {
>
> case "12345":
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/adsl_username_is #");
> $username = "JONFARMER";
> $userarray = myStringSplit(strtolower($username),1);
> $usercount = count($userarray);
> for($i=0;$i<$usercount;$i++){
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/letters/" . $userarray[$i] . " #");
> }
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/domain1t #");
> break;
>
> case "67891":
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/adsl_username_is #");
> $username = "test_user";
> $userarray = myStringSplit(strtolower($username),1);
> $usercount = count($userarray);
> for($i=0;$i<$usercount;$i++){
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/letters/" . $userarray[$i] . " #");
> }
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/domain2 #");
> break;
>
> case "00":
> $agi->agi_exec("STREAM FILE thanks #");
> exit();
> break;
>
> default:
> $agi->agi_exec("STREAM FILE
> /usr/share/asterisk/sounds/adsl/account_not_found #");
> break;
>
> }
> }
> $agi->agi_exec("STREAM FILE thanks #");
> unlink("/tmp/*.wav");
>
>
> function sayNumber($digit) {
> global $agi;
> $res = myStringSplit($digit,1);
> $num = count($res);
> for($x=0;$x<$num;$x++) {
> $agi->agi_exec("STREAM FILE /usr/share/asterisk/sounds/digits/"
> . $res[$x] ." #");
> }
> sleep(1);
> }
>
> function myStringSplit($string, $long){
>
> $long--;
> // Converting the string into an array
> For( $i=0; isset($string{$i}); $i++){
> $myarray[] = $string{$i};
> }
>
> // Making arrays from the array
> $a=0;
> $end = $long;
> $iend = count($myarray) / ( $long + 1 );
> For( $i=0; $i<$iend; $i++){
>
> For( ; $a<=$end; $a++){
>
> $array[$i] = $array[$i].$myarray[$a];
> }
> $end = $end + $long + 1;
> }
>
> return $array;
> }
>
>
> function getDTMF($term, $i) {
> global $agi;
> for($x=1;$x<$i;$x++) {
> unset($res);
> $res = $agi->agi_getdtmf(1,10000,$term,$prompt=FALSE);
> $agi->conlog("Res: " . $res[0]);
> if($res[0] == "") {
> break;
> }
> if($res[0] != "") {
> $result1 .= $res[0];
> //$agi->conlog("Result var: " . $result1);
> }
> $agi->conlog("Result var: " . $result1);
> $agi->conlog("Channel: " . $agi->request["agi_channel"]);
> $status = $agi->agi_channel_status($agi->request["agi_channel"]);
> $agi->conlog("Status code: " . $status["status"]);
> $agi->conlog("Description: " . $status["description"]);
> if($status["description"] != "Line is up") {
> exit();
> }
> }
> return $result1;
> }
> ?>
>
>
> _______________________________________________
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
More information about the asterisk-users
mailing list