Inbound Route - Look Ahead

Hello,

I’m running a FreePBX/Asterisk 13 box. When I build inbound routing (exact or pattern), it looks like it creates an entry under context: [ext-did-0001] (pattern match DID) or [ext-did-0001] (exact match DID). Each pattern or exact entry looks like:

[ext-did-0001]
exten => fax,1,Set(__DIRECTION=INBOUND)
exten => fax,n,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})

exten => ****7/_NXXNXXNXXXX,1,Set(__DIRECTION=INBOUND)
exten => ****7/_NXXNXXNXXXX,n,Gosub(sub-record-check,s,1(in,${EXTEN},dontcare))
exten => ****7/_NXXNXXNXXXX,n,Set(__FROM_DID=${EXTEN})
exten => ****7/_NXXNXXNXXXX,n,Set(CDR(did)=${FROM_DID})
exten => ****7/_NXXNXXNXXXX,n,Gosub(app-blacklist-check,s,1())
exten => ****7/_NXXNXXNXXXX,n,ExecIf($[ "${CALLERID(name)}" = "" ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => ****7/_NXXNXXNXXXX,n,Set(__MOHCLASS=)
exten => ****7/_NXXNXXNXXXX,n,Set(__REVERSAL_REJECT=FALSE)
exten => ****7/_NXXNXXNXXXX,n,GotoIf($["${REVERSAL_REJECT}"!="TRUE"]?post-reverse-charge)
exten => ****7/_NXXNXXNXXXX,n,GotoIf($["${CHANNEL(reversecharge)}"="1"]?macro-hangupcall)
exten => ****7/_NXXNXXNXXXX,n(post-reverse-charge),Noop()
exten => ****7/_NXXNXXNXXXX,n,Set(__CALLINGNAMEPRES_SV=${CALLERID(name-pres)})
exten => ****7/_NXXNXXNXXXX,n,Set(__CALLINGNUMPRES_SV=${CALLERID(num-pres)})
exten => ****7/_NXXNXXNXXXX,n,Set(CALLERID(name-pres)=allowed_not_screened)
exten => ****7/_NXXNXXNXXXX,n,Set(CALLERID(num-pres)=allowed_not_screened)
exten => ****7/_NXXNXXNXXXX,n(did-cid-hook),Noop(CallerID Entry Point)
exten => ****7/_NXXNXXNXXXX,n(dest-ext),Goto(app-announcement-399,s,1)

My question:
In my dial plan, is there a way to check if a route exists in prior to taking an action?

I have users that will be adding inbound routes over time and I want to make something that is smart enough to essentially check ext-did-0001 and ext-did-0002 to see if a pattern/number exists. If it exists, I would take one action in the treatment, if it did not, I would take another action.

Like a gotoif command.

I would also do something similar for callerID in another step.

any ideas?

We don’t speak FreePBX. What do you mean by route? It is not an Asterisk term.

Also, how do you define exists?

Its how they define DIDs for routing. It is part of the extensions.conf file under the context of [ext-did-0001] or [ext-did-0002].

I guess what I am asking is there a way to write in the Asterisk dialplan something like a gotoif, with the condition being if the DID _NXXNXXNXXXX or the CallerID(num) ****7 exist in the extensions.conf under context [ext-did-0001]?

Thanks for the help! I appreciate it!

I’m not aware of any way of testing the existence of a dialplan extension other than actually calling it or going to it.

The test is done internally, but there is no normal reason to allow dialplans to do it. They are expected to know what they contain. I guess you could shell out and run dialplan show on it, but that is expensive and complex.

You may be able to read it from the FreePBX database, but that definitely is a question for the FreePBX people.

Thanks, I’ll look into it.

There’s the DIALPLAN_EXISTS function.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+Function_DIALPLAN_EXISTS

2 Likes

I actually was just made aware of this on the FreePBX fourm, but no one had a complete understanding on how to use it. Let me ask here.

I want to know if this CID/DID Pattern exists on my dial plan: CallerID is 111111 DID is 999999

How would I enter this with the CallerID check as well? Under the [ext-did-0001] context, it shows up as:
exten => 111111/_XXXXXX,1,

Thanks again for the help!

${DIALPLAN_EXISTS(ext-did-0001,999999,1/111111 ,1)

1 Like

I don’t think so. It is a front for the internal routine I mentioned, and it looks like it uses the caller ID from the current channel, or NULL, if there is no current channel, and does so implicitly.

It isn’t testing whether a particular pattern exists, but basically whether a GoTo would succeed for the same destination.

As you are interested in it is there any chance of raising a documentation level bug report at issues.asterisk.org, as it incorrectly says “exits” rather than “exists” in the XML used to generate the help information (and someone has blindly copied that into the wiki, as well).