System information
same => n,Verbose(2,The result of the lookup was ${DUNDi_Result})
same => n,Hangup()
The arguments passed to DUNDILOOKUP() are: extension,context,options. Only one op-
tion, b, is available for the DUNDILOOKUP() function, and that is used to bypass the local
cache. The advantage to using the DUNDILOOKUP() function is that it is straightforward
and easy to use. The disadvantage is that it will only set the first value returned; if
multiple values are returned, they will be discarded.
You won’t always want to use the bypass option when performing look-
ups, because the use of the cache is what will lower the number of re-
quests over your network and limit the amount of resources required.
We’re using it in our examples simply because it is useful for testing
purposes, so that we know we’ve returned a result each time rather than
just a cached value from the previous lookup.
To parse through multiple returned values, we need to use the DUNDIQUERY() and DUN
DIRESULT() functions. Each plays an important part in sifting through multiple returned
values from a lookup. The DUNDIQUERY() function performs the initial lookup and saves
the resulting hash into memory. An ID value is then returned, which can be stored in
a channel variable. The ID value returned from the DUNDIQUERY() function can then be
passed to the DUNDIRESULT() function to parse through the returned values from the
query.
Lets take a look at some dialplan that uses these functions:
[TestContext]
exten => _1XXX,1,Verbose(2,Looking up results for extension ${EXTEN})
; Perform our lookup and save the resulting ID to DUNDI_ID
same => n,Set(DUNDI_ID=${DUNDIQUERY(${EXTEN},extensions,b)})
same => n,Verbose(2,Showing all results returned from the DUNDi Query)
; The DUNDIRESULT() function can return the number of results using 'getnum'
same => n,Set(NumberOfResults=${DUNDIRESULT(${DUNDI_ID},getnum)})
same => n,Set(ResultCounter=1)
; If there is less than 1 result, no results were returned
same => n,GotoIf($[${NumberOfResults} < 1]?NoResults,1)
; The start of our loop showing the returned values
same => n,While($[${ResultCounter} <= ${NumberOfResults}])
; Save the returned result at position ${ResultCounter} to thisResult
same => n,Set(thisResult=${DUNDIRESULT(${DUNDI_ID},${ResultCounter})})
; Show the current result on the console
same => n,Verbose(2,One of the results returned was: ${thisResult})
; Increase the counter by one
same => n,Set(ResultCounter=${INC(ResultCounter)})
520 | Chapter 23: Distributed Universal Number Discovery (DUNDi)