# Asterisk Project : More ENUMLOOKUP Examples

Added by mdavenport , edited by seanbright on May 15, 2012

All examples below except where noted use "e164.arpa" as the referenced domain, which is the default domain name for ENUMLOOKUP. All numbers are assumed to not have a leading "+" as dialed by the inbound channel, so that character is added where necessary during ENUMLOOKUP function calls.

extensions.conf

    ; example 1
    ;
    ; Assumes North American international dialing (011) prefix.
    ; Look up the first SIP result and send the call there, otherwise
    ; send the call out a PRI. This is the most simple possible
    ; ENUM example, but only uses the first SIP reply in the list of
    ; NAPTR(s).
    ;
    exten => _011.,1,Set(enumresult=${ENUMLOOKUP(${EXTEN:3})})
    exten => _011.,n,Dial(SIP/${enumresult})
    exten => _011.,n,Dial(DAHDI/g1/${EXTEN})

    ;
    ; example 2
    ;
    ; Assumes North American international dialing (011) prefix.
    ; Check to see if there are multiple SIP NAPTRs returned by
    ; the lookup, and dial each in order. If none work (or none
    ; exist) then send the call out a PRI, group 1.
    ;
    exten => _011.,1,Set(sipcount=${ENUMLOOKUP(${EXTEN:3},sip,c)}|counter=0)
    exten => _011.,n,While($["${counter}"<"${sipcount}"])
    exten => _011.,n,Set(counter=$[${counter}+1])
    exten => _011.,n,Dial(SIP/${ENUMLOOKUP(${EXTEN:3},sip,,${counter})})
    exten => _011.,n,EndWhile
    exten => _011.,n,Dial(DAHDI/g1/${EXTEN})

    ;
    ; example 3
    ;
    ; This example expects an ${EXTEN} that is an e.164 number (like
    ; 14102241145 or 437203001721)
    ; Search through e164.arpa and then also search through e164.org
    ; to see if there are any valid SIP or IAX termination capabilities.
    ; If none, send call out via DAHDI channel 1.
    ;
    ; Start first with e164.arpa zone...
    ;
    exten => _X.,1,Set(sipcount=${ENUMLOOKUP(${EXTEN},sip,c)}|counter=0)
    exten => _X.,2,GotoIf($["${counter}"<"${sipcount}"]?3:6)
    exten => _X.,3,Set(counter=$[${counter}+1])
    exten => _X.,4,Dial(SIP/${ENUMLOOKUP(${EXTEN},sip,,${counter})})
    exten => _X.,5,GotoIf($["${counter}"<"${sipcount}"]?3:6)
    ;
    exten => _X.,6,Set(iaxcount=${ENUMLOOKUP(${EXTEN},iax2,c)}|counter=0)
    exten => _X.,7,GotoIf($["${counter}"<"${iaxcount}"]?8:11)
    exten => _X.,8,Set(counter=$[${counter}+1])
    exten => _X.,9,Dial(IAX2/${ENUMLOOKUP(${EXTEN},iax2,,${counter})})
    exten => _X.,10,GotoIf($["${counter}"<"${iaxcount}"]?8:11)
    ;
    exten => _X.,11,NoOp("No valid entries in e164.arpa for ${EXTEN} - checking in e164.org")
    ;
    ; ...then also try e164.org, and look for SIP and IAX NAPTRs...
    ;
    exten => _X.,12,Set(sipcount=${ENUMLOOKUP(${EXTEN},sip,c,,e164.org)}|counter=0)
    exten => _X.,13,GotoIf($["${counter}"<"${sipcount}"]?14:17)
    exten => _X.,14,Set(counter=$[${counter}+1])
    exten => _X.,15,Dial(SIP/${ENUMLOOKUP(${EXTEN},sip,,${counter},e164.org)})
    exten => _X.,16,GotoIf($["${counter}"<"${sipcount}"]?14:17)
    ;
    exten => _X.,17,Set(iaxcount=${ENUMLOOKUP(${EXTEN},iax2,c,,e164.org)}|counter=0)
    exten => _X.,18,GotoIf($["${counter}"<"${iaxcount}"]?19:22)
    exten => _X.,19,Set(counter=$[${counter}+1])
    exten => _X.,20,Dial(IAX2/${ENUMLOOKUP(${EXTEN},iax2,,${counter},e164.org)})
    exten => _X.,21,GotoIf($["${counter}"<"${iaxcount}"]?19:22)
    ;
    ; ...then send out PRI.
    ;
    exten => _X.,22,NoOp("No valid entries in e164.org for ${EXTEN} - sending out via DAHDI")
    exten => _X.,23,Dial(DAHDI/g1/${EXTEN})

## Comments:

I tried example 3 under Asterisk 1.8.2.3 and it generated some errors due to outdated syntax, I have corrected the errors in the below dialplan if it helps anyone. example 3
    ;
    ; This example expects an ${EXTEN} that is an e.164 number (like
    ; 14102241145 or 437203001721)
    ; Search through e164.arpa and then also search through e164.org
    ; to see if there are any valid SIP or IAX termination capabilities.
    ; If none, send call out via DAHDI channel 1.
    ;
    ; Start first with e164.arpa zone...
    ;
    exten => _X.,1,Set(sipcount=${ENUMLOOKUP(${EXTEN},sip,c)})
    exten => _X.,2,Set(counter=0)
    exten => _X.,3,GotoIf($["${counter}"<"${sipcount}"]?4:7)
    exten => _X.,4,Set(counter=${MATH(${counter}+1,int)})
    exten => _X.,5,Dial(SIP/${ENUMLOOKUP(${EXTEN},sip,,${counter})})
    exten => _X.,6,GotoIf($["${counter}"<"${sipcount}"]?4:7)
    ;
    exten => _X.,7,Set(iaxcount=${ENUMLOOKUP(${EXTEN},iax2,c)})
    exten => _X.,8,Set(counter=0)
    exten => _X.,9,GotoIf($["${counter}"<"${iaxcount}"]?10:13)
    exten => _X.,10,Set(counter=$[${counter}+1])
    exten => _X.,11,Dial(IAX2/${ENUMLOOKUP(${EXTEN},iax2,,${counter})})
    exten => _X.,12,GotoIf($["${counter}"<"${iaxcount}"]?10:13)
    ;
    exten => _X.,13,NoOp("No valid entries in e164.arpa for ${EXTEN} - checking in e164.org")
    ;
    ; ...then also try e164.org, and look for SIP and IAX NAPTRs...
    ;
    exten => _X.,14,Set(sipcount=${ENUMLOOKUP(${EXTEN},sip,c,,e164.org)})
    exten => _X.,15,Set(counter=0)
    exten => _X.,16,GotoIf($["${counter}"<"${sipcount}"]?17:20)
    exten => _X.,17,Set(counter=${MATH(${counter}+1,int)})
    exten => _X.,18,Dial(SIP/${ENUMLOOKUP(${EXTEN},sip,,${counter},e164.org)})
    exten => _X.,19,GotoIf($["${counter}"<"${sipcount}"]?17:20)
    ;
    exten => _X.,20,Set(iaxcount=${ENUMLOOKUP(${EXTEN},iax2,c,,e164.org)})
    exten => _X.,21,Set(counter=0)
    exten => _X.,22,GotoIf($["${counter}"<"${iaxcount}"]?24:26)
    exten => _X.,23,Set(counter=${MATH(${counter}+1,int)})
    exten => _X.,24,Dial(IAX2/${ENUMLOOKUP(${EXTEN},iax2,,${counter},e164.org)})
    exten => _X.,25,GotoIf($["${counter}"<"${iaxcount}"]?24:26)
    ;
    ; ...then send out PRI.
    ;
    exten => _X.,26,NoOp("No valid entries in e164.org for ${EXTEN} - sending out via DAHDI")
    exten => _X.,27,Dial(DAHDI/g1/${EXTEN})
    ; end example 3 for Asterisk 1.8
Posted by johnkiniston at Mar 08, 2011 09:35