Your Linux Data Center Experts

One of my biggest complaints about Asterisk, the software PBX, has been that the “programming” of extensions in “extensions.conf” is pretty annoying in a lot of ways. One of the most annoying is that rules needed to be numbered sequentially, starting with 1. If you add a new rule, you need to renumber all following rules. Worse, some commands, if they fail, will jump to the current rule number plus 101. My head starts hurting when I have to figure out which rules I need to renumber. “Ok, I need to renumber 5 through 15, and anything over 105.” Some new features in Asterisk have eliminated this headache though.

There is a new Asterisk extension which allows the extensions to be written in what looks much more like a regular programming language, with braces blocks of code within conditionals, no line numbers, etc… However, that seems to be in a state of flux, and it also doesn't seem to be a particularly good dialect, so I decided to avoid this in rebuilding our PBX.

Using just the regular configuration mechanism though, you can now specify extension priorities beyond “1” (the first priority) by using “n”, which does an auto increment. Additionally, you can associate names with these un-numbered rules, and base other rules incremented from this name, and jump to these names. For example:

exten => s,1,Answer()
exten => s,n,Playback(greeting)
exten => s,n(DialExten),Dial($LOCAL_EXTENSIONS)
exten => s,n,Playback(nobody_here)
exten => s,n(LeaveMessage),Playback(leave_a_message)
exten => s,n,Voicemail()
exten => s,n,Hangup()
exten => s,DialExten+101,Playback(we_are_busy)
exten => s,n,Goto(LeaveMessage)

In other words, answer the call and play a greeting, then forward the call to the local extensions. If the Dial of the local extensions fails (for example, you're on the phone), it jumps to the current rule + 101, which plays a “we are busy” message (assuming you have a sound file named “we_are_busy”), then goes to “LeaveMessage”. If the Dial() command succeeds, meaning nobody answered, it plays a “Nobody is here” message and then falls through to the leave a message section.

The Dial() command, if you answer the extension, never returns, because it runs until one party hangs up.

They have also implemented a “Gosub” command, where you can jump to a named rule, and then do a “Return()”, which resumes execution after the Gosub.

Another rule I ended up using is a “ExecIfTime”, which can take a time/day/month rule, and if that matches will run a rule. I use this for playing a “Our office is closed for the holiday” message on, say, July 4th…

These new features of Asterisk make it much more useful for building complex auto-attendants. I'm quite happy they've been added so I can use them in the revamping of our PBX.

comments powered by Disqus

Join our other satisfied clients. Contact us today.