<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Here is a simple AGI using cagi that creates a user event when a call is connected with a queue member:<div><br></div><div><br></div><div><div>#include <stdio.h></div><div>#include <stdarg.h></div><div><br></div><div>#include "cagi.h"</div><div><br></div><div><br></div><div>int main (int argc, char *argv[]) {</div><div> AGI_TOOLS agi;</div><div> AGI_CMD_RESULT res;</div><div> int rtn;</div><div> char channel_name[200], uniqueid[200], Interface[200], Event[1000];</div><div><br></div><div> rtn = AGITool_Init(&agi);</div><div><br></div><div> // rtn = AGITool_verbose(&agi, &res, AGITool_ListGetVal(agi.agi_vars,</div><div> // "agi_request"), 0);</div><div> // sprintf(Event, "Do verbose= %d", rtn);</div><div> // AGITool_verbose(&agi, &res, Event, 0);</div><div><br></div><div> rtn = AGITool_get_variable2(&agi, &res, "CHANNEL",</div><div> channel_name, sizeof(channel_name));</div><div> // sprintf(Event, "Get CHANNEL = %d", rtn);</div><div> // AGITool_verbose(&agi, &res, Event, 0);</div><div><br></div><div> rtn = AGITool_get_variable2(&agi, &res, "UNIQUEID",</div><div> uniqueid, sizeof(uniqueid));</div><div> // sprintf(Event, "Get UNIQUEID = %d", rtn);</div><div> // AGITool_verbose(&agi, &res, Event, 0);</div><div><br></div><div> rtn = AGITool_get_variable2(&agi, &res, "MEMBERINTERFACE",</div><div> Interface, sizeof(Interface));</div><div> // sprintf(Event, "Get MEMBERINTERFACE = %d", rtn);</div><div> // AGITool_verbose(&agi, &res, Event, 0);</div><div><br></div><div> sprintf(Event, "DidQueue|\"%s & %s & %s"", uniqueid, channel_name, Interface);</div><div> rtn = AGITool_exec(&agi, &res, "UserEvent", Event);</div><div> // sprintf(Event, "Do UserEvent = %d", rtn);</div><div> // AGITool_verbose(&agi, &res, Event, 0);</div><div><br></div><div> AGITool_Destroy(&agi);</div><div><br></div><div> return 0;</div><div> } /* main */</div><div><br></div><div><br></div><div>
<div style="font-family: Helvetica; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">-- </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">Jim Dickenson</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><a href="mailto:dickenson@cfmc.com">mailto:dickenson@cfmc.com</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; ">CfMC</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><a href="http://www.cfmc.com/">http://www.cfmc.com/</a></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px; "><br></span></font></div></div><br class="Apple-interchange-newline">
</div>
<br><div><div>On Jun 30, 2010, at 8:31 AM, Jonas Kellens wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div text="#000000" bgcolor="#ffffff">
<font face="Helvetica, Arial, sans-serif">Taking my first steps into
AGI then :<br>
<br>
<br>
[root@asterisk agi-bin]# cat sample.agi <br>
#!/usr/bin/php -q<br>
<?php<br>
$MYSQLSERVER2="localhost";<br>
$MYSQLUSER2="user";<br>
$MYSQLPASSWD2="passwd";<br>
<br>
set_time_limit(30);<br>
require('phpagi/phpagi.php');<br>
$agi = new AGI();<br>
<br>
$db=mysql_connect("$MYSQLSERVER2", "$MYSQLUSER2", "$MYSQLPASSWD2");<br>
mysql_select_db(Asterisk, $db);<br>
<br>
$QUERY="SELECT vmcontext FROM AstDB WHERE ID='40'";<br>
$agi->verbose("query is: $QUERY", 3);<br>
$result=mysql_query($QUERY);<br>
$VMCONTEXT=mysql_fetch_array($result);<br>
$agi->verbose("VMCONTEXT is: $VMCONTEXT", 3);<br>
$vmcontext=$VMCONTEXT['vmcontext'];<br>
<br>
$exten = $agi->request['agi_extension']; //Dialed extension<br>
// the result is stored in $exten<br>
$agi->verbose("variable exten : $exten", 3);<br>
$agi->verbose("variable vmcontext : $vmcontext", 3);<br>
//<br>
?><br>
<br>
<br>
[Jun 30 17:26:04] -- Executing [123@test:3]
AGI("SIP/test-00000054", "sample.agi") in new stack<br>
[Jun 30 17:26:04] -- Launched AGI Script
/var/lib/asterisk/agi-bin/sample.agi<br>
[Jun 30 17:26:04] -- sample.agi: query is: SELECT vmcontext FROM
AstDB WHERE klantID='40'<br>
[Jun 30 17:26:04] -- sample.agi: VMCONTEXT is: <br>
[Jun 30 17:26:04] -- sample.agi: variable exten : 123<br>
[Jun 30 17:26:04] -- sample.agi: variable vmcontext : <br>
[Jun 30 17:26:04] -- AGI Script sample.agi completed, returning 0<br>
<br>
<br>
Does AGI not interpret my query correctly ? As there is no output for
$vmcontext...<br>
<br>
<br>
<br>
Jonas.<br>
<br>
</font><br>
On 06/30/2010 04:54 PM, Jim Dickenson wrote:
<blockquote cite="mid:AEFA434A-8F06-4E6E-8EBE-93B733915090@cfmc.com" type="cite">
<div>Yes it gets called when the call is connected to a queue member.</div>
<div><br>
</div>
In version 1.4.x you can execute an AGI instead of a sub or macro.<br>
</blockquote>
<br>
</div>
-- <br>_____________________________________________________________________<br>-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com">http://www.api-digital.com</a> --<br>New to Asterisk? Join us for a live introductory webinar every Thurs:<br> <a href="http://www.asterisk.org/hello">http://www.asterisk.org/hello</a><br><br>asterisk-users mailing list<br>To UNSUBSCRIBE or update options visit:<br> <a href="http://lists.digium.com/mailman/listinfo/asterisk-users">http://lists.digium.com/mailman/listinfo/asterisk-users</a></blockquote></div><br></div></body></html>