| Asterisk Support Forum Technical support, how-to guides, troubleshooting, and general assistance, from beginner to seasoned pro, this is where to discuss Asterisk, the most powerful open source PBX. |  | 
August 18th, 2007, 10:42 AM
|  | Junior Member | | Join Date: Aug 2007 Location: Spain
Posts: 1
| | Trying to create my first IVR Hello friends.
First, I must tell that I am really sorry cause my english skill is really poor  but I try to explain my question
I'm new on Asterisk world (I was using Asterisk for my own purposes for 1 year ago) and now I'm trying to build an IVR that saves into a database the keypresses; first, I create a context to hold the IVR Code: [mycontext]
exten => s,1,Answer
exten => s,2,AGI(test1.php)
exten => s,3,Background(press-1-for-castellano)
exten => s,4,Wait(1)
exten => s,5,Background(press-2-for-catala)
;--------- CASTELLANO ---------
exten => 1,1,Background(Gracias)
exten => 1,2,Wait(1)
exten => 1,3,Background(esp/intro-answer-1)
exten => 1,4,Read(tmp,esp/answer-1,1)
exten => 1,5,Set(RESPA=${tmp}|g)
exten => 1,6,Background(Gracias)
exten => 1,7,Background(esp/intro-answer-2)
exten => 1,8,Read(tmp,esp/answer-2,1)
exten => 1,9,Set(RESPB=${tmp}|g)
exten => 1,10,Background(Gracias)
exten => 1,11,Set(LANG=1|g)
exten => 1,12,Hangup
;--------- CATALA ---------
exten => 2,1,Background(Gracies)
exten => 2,2,Wait(1)
exten => 2,3,Background(cat/intro-answer-1)
exten => 2,4,Read(tmp,esp/answer-1,1)
exten => 2,5,Set(RESPA=${tmp}|g)
exten => 2,6,Background(Gracies)
exten => 2,7,Background(cat/intro-answer-2)
exten => 2,8,Read(tmp,cat/answer-2,1)
exten => 2,9,Set(RESPB=${tmp}|g)
exten => 2,10,Background(Gracies)
exten => 2,11,Set(LANG=2|g)
exten => 2,12,Hangup
; -- HANGUP --
exten => h,1,DeadAGI(test2.php|${LANG}|${RESPA}|${RESPB})
exten => h,2,Hangup
exten => i,1,Goto(s,3)
exten => o,1,Goto(s,3)
I was tested that menu and it works... but seems that the scripts (test1.php and test2.php) does'nt work... i think that the system do not execute it.
The scritps are the following:
Test1.php Code: #!/usr/bin/php -q
<?
ob_implicit_flush(false);
error_reporting(0);
set_time_limit(300);
$log = "/var/log/asterisk/test1.txt";
$stdlog = fopen($log, 'a');
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
while (!feof($stdin))
{
$inputvalue = fgets($stdin);
fputs($stdlog, "From stdin: " . $inputvalue . "\n");
$inputvalue = str_replace("\n", "", $inputvalue);
$partes = explode(":", $inputvalue);
$agivar[$partes[0]] = trim($partes[1]);
fputs($stdlog, "agivar[" . $partes[0] . "] = " . trim($partes[1]) . "\n");
if (($inputvalue == "") || ($inputvalue == "\n")) break;
}
fclose($stdin);
fclose($stdlog);
exit;
?>
Test2.php Code: #usr/bin/php -q
<?
ob_implicit_flush(false);
error_reporting(0);
set_time_limit(300);
$debug = 1;
$log = "/var/log/asterisk/test2.txt";
$stdlog = fopen($log, 'a');
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
if ($debug) :
fputs($stdlog, "Script log.\n\n" . date("F j, Y - H:i:s"));
endif;
// Code begins here
while (!feof($stdin))
{
$inputvalue = fgets($stdin);
if ($debug) fputs($stdlog, "from stdin: " . $inputvalue);
$inputvalue = str_replace("\n", "", $inputvalue);
$partes = explode(":", $inputvalue);
$agivar[$partes[0]] = trim($partes[1]);
if (($inputvalue == "") || ($inputvalue == "\n")) break;
}
$LANG = $_SERVER['argv'][1];
$LANG = trim($TLF);
$LANG = ltrim($TLF);
$RESPA = $_SERVER['argv'][2];
$RESPA = trim($RESPA);
$RESPA = ltrim($RESPA);
$RESPB = $_SERVER['argv'][3];
$RESPB = trim($RESPA);
$RESPB = ltrim($RESPA);
if ($debug) :
fputs($stdlog, "LANG: " . $LANG . "\n");
fputs($stdlog, "RESPA: " . $RESPA . "\n");
fputs($stdlog, "RESPB: " . $RESPB . "\n");
fputs($stdlog, "\n\nOpening database...\n");
endif;
$link = mysql_connect("localhost", "root", "passw0rd") or die("Data base connection failed");
mysql_select_db("testdatabase") or die("data base open failed");
if ($debug) :
fputs($stdlog, "Database opened\n");
endif;
$query = "INSERT INTO `test_table` VALUES (" . $TLF . ", `" . $RESPA . "`, `" . $RESPB . "`, `" . $RESPC . "`)";
$result = mysql_db_query($query) or die("Web site query failed");
if ($debug) :
fputs($stdlog, "the query is: " . $query . "\n");
if ($result)
{ fputs($stdlog, "query done.\n");}
else
{ fputs($stdlog, "query failed.\n");}
endif;
if ($debug) :
fputs($stdlog, "... closing database.\n");
endif;
mysql_close($link);
if ($debug) :
fputs($stdlog, "Script log.\n\n" . date("F j, Y - H:i:s"));
endif;
fclose($stdlog);
fclose($stdin);
fclose($stdlog);
exit;
?>
Both files have execution permisions (0755) and the owner is asterisk:asterisk but, i know that the code is'nt executed cause the log files are not created and the database stays empty, where is my error? |  | | Thread Tools | | | | Display Modes | Rate This Thread | Linear Mode | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | |