Saturday, September 17, 2016

Play a message on asterisk before calling someone

I had a need to play a reminder message to users who placed a call through our asterisk server that utilized a high toll charge route.  The automatic message reminds them that the call is using a high toll cost trunk, then the number is connected as normal.

This was built on ELASTIX 2.5.0 distribution

FreePBX doesn't let you do this out of the box yet (as of Sept 2016) but I wanted to implement something as simple as I could come up with.
What I did was modify the FreePBX pinset feature to play the message, without the need of entering a pin number and with minimal programming.

FreePBX pinset feature prompts users to enter a PIN before the call connected.  I just changed the message to a custom one I made, and removed the need for users to enter any number.

INSTRUCTIONS

1> Make a custom recording of what you want the new message to be.  I recorded it using the FreePBX GUI sound recordings menu and called it "TollRoute"

2> Open up extensions_additional.conf file and look for [macro-pinsets].  It will look like this:

[macro-pinsets]
include => macro-pinsets-custom
exten => s,1,GotoIf(${ARG2} = 1?cdr,1)
exten => s,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?Authenticate(/etc/asterisk/pinset_${ARG1}))
exten => s,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?ResetCDR())

exten => cdr,1,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?Authenticate(/etc/asterisk/pinset_${ARG1},a))
exten => cdr,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?ResetCDR())

;--== end of [macro-pinsets] ==--;


3> Copy this portion of code and paste it into "extensions_override_freepbx.conf".

4> Now change to two instances to the newly pasted text that contain:
?Authenticate(/etc/asterisk/pinset_${ARG1}))
to:
?Playback(./custom/TollRoute))

AND



?Authenticate(/etc/asterisk/pinset_${ARG1},a))
to:
?Playback(./custom/TollRoute))

Here is what the code should look like based on my example:

[macro-pinsets]
exten => s,1,GotoIf(${ARG2} = 1?cdr,1)
;if extension has PINLESS DIAL set to YES then the message is NOT played
exten => s,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?Playback(./custom/TollRoute))
exten => s,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?ResetCDR())

exten => cdr,1,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?playback(./custom/TollRoute))
exten => cdr,n,ExecIf($["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]?ResetCDR())

5> Save these changes.

6> In the FreePBX GUI, goto PINSETS and create a Pinset called "TollWarning"
You don't need to put any pins in this, you can leave it empty.  Save it.

7> Select the outbound route you want this feature on, and next to "PIN Set:", select "TollWarning" in the drop box.  Save your changes and apply them with the red bar/button at the top of FreePBX

8> make your test.  When you call that route, you should hear your custom message played.  As soon as it is done, your call will automatically dial.

FEATURE:
If you have extension(s) that you dont want this to be applied to (maybe you have different lines of business) you can go to those extensions and enable "PINLESS DIAL"  those extensions will simply automatically bypass this code and goto immediate ringing.

WHAT AM I CHANGING?
Essentially you are changing the "AUTHENTICATE" command, which is triggers asterisk to play the "Please enter your pin" and wait for you to enter a value into your phone, and modifying it to simply play the message, then continue.

WARNING:
This code will affect your PBX pins on any routes that you have in your system currently.

Thursday, September 15, 2016

Customizing FreePBX dialplans

Want to modify the existing code that FreePBX generates slightly for your own and not have it get overwritten every time you update the GUI?  Here's how.

First, find the code that you want to alter

In the example below, I wanted to customize the code that asterisk used when asking for a pin# when someone dials the phone.

So I found the code I wanted to change in: extensions_additional.com

[outrt-11] ; PSTN_PIN
include => outrt-11-custom
exten => _6666X.,1,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _6666X.,n(pinsets),Macro(pinsets,1,1)
exten => _6666X.,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _6666X.,n,Set(_NODEST=)
exten => _6666X.,n,Gosub(sub-record-check,s,1(out,${EXTEN},))
exten => _6666X.,n,Macro(dialout-trunk,2,${EXTEN:4},,off)
exten => _6666X.,n,Macro(outisbusy,)

Copy that code and then paste it in: extensions_override_freepbx.conf

Now alter the file as you need.  You'll see I've added a "NoOp" line to echo a message into the live log.  Remember, don't alter the ["HEADING"], leave as is.

[outrt-11] ; PSTN_PIN
include => outrt-11-custom
exten => _6666X.,1,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _6666X.,n,NoOp( THIS IS THE ALTERED CODE!!!!!!!!!!!!!! )
exten => _6666X.,n(pinsets),Macro(pinsets,1,1)
exten => _6666X.,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _6666X.,n,Set(_NODEST=)
exten => _6666X.,n,Gosub(sub-record-check,s,1(out,${EXTEN},))
exten => _6666X.,n,Macro(dialout-trunk,2,${EXTEN:4},,off)
exten => _6666X.,n,Macro(outisbusy,)

Save the changes then reload the config in asterisk and you will be good to go.

In the above example, the calls behave the same, but in the live log you'll see "THIS IS THE ALTERED CODE" appear when the module is triggered.