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.

No comments:

Post a Comment