DUNDi in the dialplan

Submitted by russell on 9 May 2007 - 3:40am.

Some guys on IRC had been asking for this feature for a while, so I finally decided to do it. They wanted a way to do a DUNDi lookup from the dialplan, and to access all of the results, instead of the just the result with the lowest weight (highest priority).

So, I recently added two new diaplan functions into our development trunk: DUNDIQUERY and DUNDIRESULT. DUNDIQUERY lets you inititate a dundi query. DUNDIRESULT allows you to access the results from a previous query executed with DUNDIQUERY.

There are a lot of potential applications for this. You can use the results from a DUNDi lookup to make intelligent decisions in your dialplan.


*CLI> core show function DUNDIQUERY

-= Info about function 'DUNDIQUERY' =-

[Syntax]
DUNDIQUERY(number[|context[|options]])

[Synopsis]
Initiate a DUNDi query.

[Description]
This will do a DUNDi lookup of the given phone number.
If no context is given, the default will be e164. The result of
this function will be a numeric ID that can be used to retrieve
the results with the DUNDIRESULT function. If the 'b' option is
is specified, the internal DUNDi cache will be bypassed.


*CLI> core show function DUNDIRESULT

-= Info about function 'DUNDIRESULT' =-

[Syntax]
DUNDIRESULT(id|resultnum)

[Synopsis]
Retrieve results from a DUNDIQUERY

[Description]
This function will retrieve results from a previous use
of the DUNDIQUERY function.
id - This argument is the identifier returned by the DUNDIQUERY function.
resultnum - This is the number of the result that you want to retrieve.
Results start at 1. If this argument is specified as "getnum",
then it will return the total number of results that are available.

Finally, here is a simple example of the usage:


exten => 1,1,Set(ID=${DUNDIQUERY(1|dundi_test|b)})
exten => 1,n,Set(NUM=${DUNDIRESULT(${ID}|getnum)})
exten => 1,n,NoOp(There are ${NUM} results)
exten => 1,n,Set(X=1)
exten => 1,n,While($[${X} <= ${NUM}])
exten => 1,n,NoOp(Result ${X} is ${DUNDIRESULT(${ID}|${X})})
exten => 1,n,Set(X=$[${X} + 1])
exten => 1,n,EndWhile

How do I download it?

These features have been added to the development trunk for Asterisk in subversion. The features we put here are what will eventually become Asterisk 1.6.

To test out the most recent development code, feel free to check it out from our svn server:


$ svn co http://svn.digium.com/svn/asterisk/trunk