[Asterisk-Users] cepstral integration with * using AGI? ->sent last responce to soon stupid me

John Millican john at millican.us
Mon Jan 24 14:54:35 MST 2005


On Monday January 24 2005 3:29 pm, John Middleton wrote:
> Hi, I've looked at the Wiki for this, have seen the Swift.agi
> details, but has anyone got a current script for Cepstral and an
> example of integraton in * please?
>
> I'm a * and linux newbie, so please be gentle ;-)
>
> Thanks
>
> John

I just put swift.agi in agi-bin and used a c++ script to do a db 
look-up in postgres for the information that i wanted read to the 
user, i.e user name and other info based on caller id number. I pass 
calleridnum to the c++ script and then use SETVAR in the script to 
get the info back and read it to the user. recfound is set to 1 if 
any record in the db.
 Extensions .conf look somewhat like this:

[answerMain]
exten => s,1,Ringing()                  ; Send Ring tone to caller
exten => s,2,Wait,5                             ; Wait a 5 seconds to 
get a ring or two
exten => s,3,Answer                             ; Answer the line
exten => s,4,DigitTimeout,5             ; Set Digit Timeout to 5 
seconds
exten => s,5,ResponseTimeout,10 ; Set Response Timeout to 10 seconds
exten => s,6,PrivacyManager
exten => s,7,agi,c++script.cpp|${CALLERIDNUM}; //does db lookup
exten => s,8,GoToIf($[${RECFOUND} > 0]?9:17); // if found a record 
exten => s,9,agi,swift.agi|Welcome to the Reservation System.  We will 
be placing a reservation for  ${varname}.; 
exten => s,10,read(foo,static recording,1); //wait for user input of 1 
digit

I us QT for writting the script but it is just a simple C++ script, 
subject for different mail list. but here is an example.


#include <qsqldatabase.h>
#include <qdatatable.h>
#include <qsqlcursor.h>
#include <qsqlquery.h>
#include <qstring.h>
#include <stdio.h>
#include <qapplication.h>
#include <iostream>
#include <qregexp.h>
#include <qdatetime.h>
#include <qprocess.h>

using namespace std;

#define DRIVER          "QPSQL7"      		/* PostgreSQL Driver*/
#define DATABASE     "DBNAME"      	/* the name of the database */
#define USER              "jmillican"    		/* user name with 
appropriate rights */
#define PASSWORD    "******"           		/* password for USER */
#define HOST              "127.0.0.1"  	/*host on which the database 
is running */
QSqlDatabase * db ;

int main( int argc, char **argv)
{
    bool useGUI = false;
    QApplication a( argc, argv, useGUI);
    setlinebuf(stdout);
    setlinebuf(stderr);

    QString callid;
    QString astvar;


    callid = a.argv()[1];  //get caller id from asterisk


    QSqlDatabase * db = QSqlDatabase::addDatabase( DRIVER );
    db->setDatabaseName( DATABASE );
    db->setUserName( USER );
    db->setPassword( PASSWORD );
    db->setHostName( HOST );

    if (!db->open())
    {
	fputs("db not open \n",stderr);
    }
    
    // get cust_id and stuff from callid
    QSqlQuery query;

    query.prepare("select SQL QUERY HERE);
    query.bindValue(":phone",callid);
    query.exec();
    query.next();
    QString strCustId = query.value(0).toString();
    QString strsomeId = query.value(1).toString();
    QString strsomeName;
  
    QVariant vSize = query.size();
    QString strSize =  vSize.toString();
 
       strsomeName = query.value(2).toString();
             
       strsomeName = strBoatName.replace(" ",",");

     if (query.size() >= 1) //send all info back to asterisk
    {
       fprintf(stdout,"EXEC SETVAR CUSTID=" + strCustId + "\n");
       fprintf(stdout,"EXEC SETVAR BOATNAME=" + strsomeName + " \n");
       fprintf(stdout,"EXEC SETVAR BOATID=" + strsomeId + "\n");
       fprintf(stdout,"EXEC SETVAR RECFOUND=" + strSize + "\n");
   }
     else
     {
        fprintf(stdout,"EXEC SETVAR RECFOUND=0 \n");// if no record 
found
     }
     db->close();

   return 0;

If any one sees this as a bad example please say so with comment on 
how to make it better.
John M



More information about the asterisk-users mailing list