PBX In A Flash: Custom Dialplans & FreePBX

PIAF is a great collection of Asterisk tools, and I'm pretty happy with the fact that someone has collected them all for me and put them together in a decent package.  However if you're wanting to delve a little deeper and get into more complex Asterisk dial plan scripting, it can be a bit of a trial to work out exactly which config files you can safely modify without tanking your existing installation.  The documentation can be hard to find and/or follow, especially since material is often ambiguous as to the version of PIAF.  So I thought I'd share a little of what I've scraped together for those who want to start rolling up their sleeves and tackling their own scripting with Asterisk!

For the record I'm using PIAF based on CentOS 5.6 (32bit), which is based on Asterisk 1.8, and my main self-study material is the incredibly well written Asterisk: The Definitive Guide (May 2011).

The PIAF developers did a good job of leaving hints in the configuration files for people who want to do their own modifications.  Most of the "do not touch!" files have headers like this:

; Do NOT edit this file as it is auto-generated by FreePBX. All modifications to ;
; this file must be done via the web gui. There are alternative files to make    ;
; custom modifications, details at: http://freepbx.org/configuration_files ;

Most Asterisk references will tell you to edit /etc/asterisk/extensions.conf.  In PIAF, this is a "don't touch" file and gets overwritten by PIAF's FreePBX web interface every time you make a change.  Instead of directly modifying extensions.conf there are a set of secondary files in /etc/asterisk for adding custom modifications that will be appended via the include directive.

For adding my own custom dial plan and context, I edited extensions_custom.conf.  I just scrolled to the bottom, added a new context and started scripting:

exten => frontEnd,1,Answer()
same => n,Wait(0.5)
same => n,Playback(roc/generic/greeting)
same => n,Hangup()

(I placed my custom recordings in WAV PCM 16bit 8KHz format in the English language default sound directory /var/lib/asterisk/sounds/en/)

For adding custom DID extensions I edited extensions_override_freepbx.conf, which along with extensions_addition.conf specifies your inbound DIDs, SIP/IAX devices and the like.  In extensions_override_freepbx.conf I needed to know both the extension configuration and what should be it's enclosing context.  I determined this by

  • creating an inbound DID,
  • searching for the number in extensions_addition.conf and copying it,
  • scrolling up from the extension to determine it's context,
  • pasting the extension information into extensions_override_freepbx.conf under the same context, and then
  • modifying the copied extension information to suit my needs.

My extensions_override_freepbx.conf looks like this:

exten => 5556667777,1,Set(__FROM_DID=${EXTEN})
exten => 5556667777,n,Gosub(app-blacklist-check,s,1)
exten => 5556667777,n,ExecIf($[ “${CALLERID(name)}” = “” ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 5556667777,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 5556667777,n,Set(CALLERPRES()=allowed_not_screened)
exten => 5556667777,n,Set(_RGPREFIX=COG:Carolina OBGYN TEST:)
exten => 5556667777,n,Set(CALLERID(name)=${RGPREFIX}${CALLERID(name)})
exten => 5556667777,n(dest-ext),Goto(my-test-context,frontEnd,1)

I'm sure several of those commands are unnecessary, but I haven't gotten around to playing with those just yet.

And of course you have to reload your configuration files every time you edit them.  I do this from the command line of my box:

$ asterisk -rx "reload"

All that took me a few hours of research, tinkering and experimenting.  I hope this quick summary can save some time for others creating custom dialplans under PBX in a Flash!

Tags: , ,
Copyright Tyler Style 2015. All rights reserved.

Posted 2011-07-07 by Tyler in category "Technology", "Telecommunications

About the Author

Totally a geek engineer type - I like to think, tinker and make things go BOOM! I'm also pretty introspective, and enjoy analyzing most things around me and talk about them (often to exasperation). I don't do much pop culture in general, and don't own a TV - give me lively debate with another inquiring mind instead any day of the week!

Leave a Reply

Your email address will not be published. Required fields are marked *