[asterisk-users] AGI and retreiving data, how to use this data in extensions.conf

Steve Edwards asterisk.org at sedwards.com
Sat Mar 10 16:46:49 CST 2012


On Sat, 10 Mar 2012, bilal ghayyad wrote:

> If I have information that I need to build a decision in the 
> extensions.conf based on it, and these informations can be obtained 
> using this script, so how I will read these informations? What is the 
> method to read it from the database and store it in a variable that I 
> can use it in the extensions.conf to do proper call routing? How?

We must be mis-communicating something. This is almost exactly the same 
question you asked a couple of days ago.

Let's walk through what an example of what I think you are asking and see 
if it answers your questions.

I have a system where calls are answered. The key piece of information at 
the start of the call is 'what number did the caller dial?' This is 
frequently (depending on what part of the world you are in) called the DID 
(Direct Inward Dial) or DNIS (Dialed Number Identification Service). For 
me, and the industries I work in, it's DNIS.

When a call is received, Asterisk saves the DNIS in the EXTEN channel 
variable and sends the call to the context (as defined in sip.conf), the 
exten ${EXTEN}, and the priority 1.

In my dialplan, I save the ${EXTEN} channel variable in a new channel 
variable named DNIS so it will be obvious to 'the next guy' and it won't 
change as I bounce around from context to context in my dial plan.

I invoke an AGI in the dialplan using:

 	agi(lookup-dnis,${DEBUG-MODE})

Where DEBUG-MODE is a global variable set in the [globals] section of 
extensions.conf to either be '--debug' or '--null.'

(My AGIs always use the 'getopt_long()' function to parse the command 
line.)

This AGI reads the DNIS channel variable using (via a library) the AGI 
command 'get variable' and save it in a variable curiously named 'dnis' in 
my AGI compliant application.

My AGI uses the dnis to retrieve a row from my CLIENTS, DNISES, RECIPES 
and STEPS tables using (via a library) the MySQL function 
'mysql_query("select ... from ... where ...").'

The retrieved row contains a bunch (up to about a hundred) of columns, 
most of which my AGI sets as channel variables. Now the cruft from the 
database is available to the rest of my dialplan and my AGI exits.

Back in my dialplan, I use those channel variables like these AEL 
snippets:

                 set(LANGUAGE()=${INITIAL-LANGUAGE});
                 set(RECORDING-PATH=/tmp/${CLIENT-ID}/${CALL-ID}/);
                 system(mkdir --parents ${RECORDING-PATH}/tmp/);
                 if      ("COMPLIANT" = "${PROMPT-RECORDING-MODE}")
                         {
                         MONITOR_EXEC="/scripts/compliant-mixer.sh";
                         MONITOR_EXEC_ARGS="COMPLIANT OUT";
                         };
// note the 'nested expansion' in the next channel variable
                 switch  (${STEP-${IDX}-TYPE})
                         {
                         case AGENT-ID:
                                 verbose(1,AGENT-ID);
                                 agi(agent-id,${DEBUG-MODE},${TEST-MODE},${VERBOSE-MODE});
                                 break;
                         case BRANCH:
                                 verbose(1,BRANCH);
                                 agi(branch,${DEBUG-MODE},${TEST-MODE},${VERBOSE-MODE});
                                 IDX=0$[ ${IDX} - 1 ];
                                 break;

At the end of the call (in the 'h' extension), I invoke another AGI 
('finish-call') which reads various channel variables and writes them into 
a 'CDR-ish' table which is used to create reports and billing statements.

Does this 'cover the bases?'

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list