Thursday, May 11, 2017

Use asterisk Direct Dial from IVR to goto a different PBX system

So lets say you are running a Cisco or other type of SIP capable PBX in your business, but you want to use asterisk IVR (cost, familiarity whatever) and want to add the feature of "direct dial extension" from that IVR.  The problem is FreePBX gui is designed to only look at the "Extension" list and use that to match.  Which makes perfect sense.  But if your asterisk box is only hosting an IVR, you wouldn't have all the extensions on the asterisk server.  This is basically a work around for that.

I've used this for DEMO purposes.  I wouldn't roll this code into production since its not been tested.  There could be all kinds of vulnerabilities!  Use at your own risk.

What the code does:
We modify the FreePBX IVR code not look at extensions, but to instead match the outbound dial plan of the Asterisk box that triggers calls to use the trunk to your downstream PBX

So if your PBX has 4000-4999 extension, you probably have a dial patter in an outbound route that looks like 4XXX

With this code, if someone in the IVR dial 4001, that will match this outbound route and send the call down the trunk.

1. Create an IVR with the “Direct Dial” option enabled in the GUI.  Note the name of it.  In my example its called IVR_Test

2. Save/Apply changes in FreePBX

3. Open up the file /etc/asterisk/ extensions_additional.conf

4. You want to look for the outbound route that you use to push calls to your downstream PBX Trunk under the [outbound-allroutes] heading.

(it’ll look something like this)
include => outbound-allroutes-custom
include => outrt-16 ; PBX_PROD_01

Explanation of my “outrt-16 PBX_PROD_01” trunk
In my example above, outrt-16 is the outbound route in my gui that I use to trigger calls to send down a trunk.
If the number 4XXX is dialed, outbound route #16 “PBX_PROD_01” will be looked at to send calls down the trunk Called Asterisk_100_11  

5. So, copy the outbound route entry that matches your outbound route that’s used to trigger your Cisco trunk.  (my example you would copy   “include => outrt-16 ; PBX_PROD_01 “

6. Find the IVR in the code…it’ll look something like this:

[ivr-3] ; IVR_Test
include => ivr-3-custom
include => from-did-direct-ivr
exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => s,n,Set(INVALID_LOOPCOUNT=0)
exten => h,1,Hangup
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
;--== end of [ivr-3] ==--;

7. Now paste the line you copied into the IVR and make it look like this:
[ivr-3] ; IVR_Test
include => ivr-3-custom
include => outrt-16 ; PBX_PROD_01
include => from-did-direct-ivr

8. Copy this IVR section and paste it into (Saving the IVR module in this override file ensures that future FreePBX changes won’t overwrite anything)
/etc/asterisk/ extensions_override_freepbx.conf
(Copy everything from [ivr-3] ; IVR_Test   right to ;--== end of [ivr-3] ==--; )
               No need to make any changes.

9. Save changes and close file
Don’t bother saving the changes in “/etc/asterisk/ extensions_additional.conf” as these get overwritten anyway by FreePBX.
You can just close this file without saving changes.
10. Now go into the console of asterisk using  “  asterisk –cvvvvvvr “
11. Type “RELOAD”
12. Now make a test call to your IVR and dial an extension.  See if it works!