Friday, August 11, 2017

Play a message to calling party when using a specific trunk in asterisk

Do you have a specific route in asterisk that you want to play an automatic message when its used?
Could be an outbound route for for an expensive LD trunk, or maybe you want to play a reminder to your employees prior to the call being established.

FreePBX/Issabel doesn't let you do this out of the box yet (as of Aug 2017) but a bit of custom code will make this work.

INSTRUCTIONS

1> Determine the outbound route you want to use.  In my example, its called "international" (all international calls go out this connection.

2> In "SYSTEM RECORDINGS", create the recording that you would want to be played to callers who use this trunk.  For example "Warning International call being made" and i will call the recording "internationalwarning"

3> open up the file /etc/asterisk/extensions_additional.conf

Find your outbound route in this dialplan. Below is an EXAMPLE of what mine looked like. Yours will be similar,  " [OUTRT-XX]; NAME " will be different as will some of the phone numbers.

My example, calls that start with 011 as the number that is called that uses this trunk.

------ example ---------------

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

;--== end of [outrt-1] ==--;

----- END EXAMPLE ---------------

4> SELECT and COPY the appropriate code from your dialplan. Make sure you copy the entire section of code for that context.

5> OPEN /etc/asterisk/extensions_override_freepbx.conf  (or _issabel.conf)
(if FOP2 is used, you may need to put this in /etc/asterisk/extensions_override_fop2.conf instead)

PASTE the code into the bottom of this file.

6> Now you want to make a small edit to this file.

You will need to insert a custom code in to each number you have in this route to play the recorded message.  My dialplan uses _011.  Yours might be different so you will need to adjust it accordingly

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

;--== end of [outrt-1] ==--;

Save your changes

7> reload the config in asterisk CLI ( asterisk -cvvr then core reload)
TEST!

What will happen is, when asterisk goes to dial the code, it will run this custom code, play the message then continue the dialing.

PLEASE NOTE!

If you put it in override, future changes to FreePBX wont' over ride this module.

That if you make changes to the numbers contained in this outbound route, you absolutely have to remember to manually update the custom code. Meaning, if you have configured 3 numbers, then you do the above work and remove or add another number, you MUST repeat the above steps, first removing the custom code and replacing it with the one FreePBX generates. The custom override code will supersede and negate any changes you do in FreePBX for that route. This is very important.

No comments:

Post a Comment