AsteriskConfiguration16
From ENUMPlus
Introduction
It's easy to use ENUMPlus with your existing Asterisk installation. These instructions are for Asterisk 1.6.x or later. For instructions on using ENUMPlus with Asterisk 1.4, see the Using ENUMPlus lookups with Asterisk 1.4 page.
Prerequisites
It is expected that you have already configured your account on ENUMPlus as you will require the use of an API key. This key is available under the Accounts tab of your account.
Dialplan
The dialplan for Asterisk is relatively straight forward. We have also enclosed this within it's own context so you simply need to include it in your existing internal context for your devices. We're also using a prefix number of seven (7) for lookups to ENUMPlus specifically. Additionally, this dialplan assumes 10-digit North American dialing.
The first thing we need to do is add some information to our [globals] context. The information we're adding is the link to the API URL and the API key we got from the Accounts tab from your ENUMPlus portal.
[globals] G_ENUMPLUS_API=http://enumplus.org/api G_ENUMPLUS_KEY=0000aaaa1111zzzz2222bbbb3333yyyy
We've included comments below to tell you what is going on at various points within the dialplan.
[enum-lookup]
; save our ${EXTEN} variable to another variable for use in named extensions
exten => _7NXXNXXXXXX,1,Set(SAFE_EXTEN=${FILTER(0-9,${EXTEN:1})})
exten => _7NXXNXXXXXX,n,Goto(lookup,1)
; start our lookup
exten => lookup,1,Verbose(2,Looking up direct dial via ENUM from ENUMPlus: ${SAFE_EXTEN})
exten => lookup,n,Playback(silence/1&doing-enum-lookup)
; this is where all the magic happens. We perform a cURL lookup to the ENUMPlus API using our key and save the result to ${CURL_RESULT}
exten => lookup,n,Set(CURL_RESULT=${CURL(${GLOBAL(G_ENUMPLUS_API)}/${SAFE_EXTEN},key=${GLOBAL(G_ENUMPLUS_KEY)})})
; make sure we got a result -- if not, then handle the blank lookup via the 'no_result' extension
exten => lookup,n,GotoIf($[${ISNULL(${CURL_RESULT})}]?no_result,1)
; if we got a result, then Goto() the 'dial' extension
exten => lookup,n,Goto(dial,1)
exten => dial,1,Verbose(2,Lookup returned: ${CURL_RESULT})
exten => dial,n,Playback(enum-lookup-successful)
exten => dial,n,Set(CALLERID(name)=Bobs Company)
exten => dial,n,Set(CALLERID(num)=4165551212)
; This is where we'll place a call to the FIRST result looked up. It's possible we got multiple results, so you could handle
; failing over to other extensions if you got an error if you wanted. Trick will be using the ${DIALSTATUS} channel variable.
; -- Also note that we're dialing for 30 seconds. You may wish to change this value to suit your needs.
exten => dial,n,Dial(${CUT(CURL_RESULT,|,1)},30)
exten => dial,n,Hangup()
; If we didn't get any results, let the caller know, and then end the call.
exten => no_result,1,Verbose(2,ENUMPlus returned no data.)
exten => no_result,n,Playback(silence/1&enum-lookup-failed)
exten => no_result,n,Hangup()
Now, if you want to perform a lookup, you can do this by including it in your existing context for outbound dialing from your devices. For example, if we have set context=devices in our channel configuration file (sip.conf for example) for a particular device, then we can just include it in that context.
[devices] exten => _NXXNXXXXXX,1,Verbose(2,Standard calling via regular rules) exten => ... include => enum-lookup
Whenever you want to do a lookup via ENUMPlus, just dial with a prefix of seven (7), otherwise, just dial per normal.
Additional examples will be added later which show you how to use ENUMPlus for the initial lookup and call, and if no result is returned, or a failure happens, to utilize your standard trunk as the failover route.
