Don't see it? Ask!

Friday, October 31, 2008

BLF and FreePBX feature codes

One of the really cool things added to the latest version of FreePBX is support for Russell's devstate backport for Asterisk 1.4. Today I decided to have a look at how it works, and I found it to be extremely simple and straightforward to set up. Obviously, you need to add the backport to asterisk. Luckily, that is extremely easy - just follow the directions in the readme.

Next, add the following line to amportal.conf (if it isn't already there):

USEDEVSTATE=true

I was looking to see the status of my Follow-Me, so I needed to configure one of the BLF's on my phone to reflect on the its status. To do that I needed to set the BLF to watch feature code that I would normally dial to activate the Follow-Me: *21200. I updated my 00000000.xml directory configuration file for my Polycom 650 as follows:

<item>
<fn>Call Forwarding</fn>
<ct>*21200</ct>
<sd>7</sd>
<ad>0</ad>
<ar>0</ar>
<bw>1</bw>
<bb>0</bb>
</item>


I then rebooted my phone, and like the magic that FreePBX is, I can now tell by a glance what the Follow Me status is. Now if only setting up an orb would be as simple!

Moshe Brevda, FreePBX Development Team
lazytt - FreePBX forums
hi365 - IRC

Continue reading...

Tuesday, October 28, 2008

Howto: list Asterisk contexts and includes

After all our discussions of asterisk contexts, you my be looking for a simple way to list all your asterisk contexts and their includes. Just type (or copy and paste) the following at you're Linux CLI:

asterisk -rx 'dialplan show' | \
awk -F"'" '
BEGIN {printf "digraph dialplan {\n";};
/^\[ Context/ {context=$2};
/^ Include =>/ {printf "\t%s -> %s\n",context,$2};
END {printf "}\n"}
'

After pressing enter, you will see something like this:

from-pstn -> from-pstn-custom
from-pstn -> ext-did
from-pstn -> ext-did-post-custom
from-pstn -> from-did-direct


Got a better way to list your asterisk includes? Show it in the comments!

Moshe Brevda, FreePBX Development Team

Found this tip useful? Don't forget to donate by click the donate button on the right!

Continue reading...

Thursday, October 16, 2008

Miscellaneous/Custom application/extensions: How to extend FreePBX with custom dialplan (part 2 of 2)

In part 1, we were discussing the basics of how the Asterisk dialplan works. To recap: asterisk is made up of contexts, which can in turn include more context, creating the whole dialplan. FreePBX takes advantage of this structure by creating a lot of contexts and then included these in each other. Until now, the easiest way to include your own custom dialplan was to put it in one of custom context that FreePBX intentionally leaves blank for the purpose of customization. Now (actually since version 2.3) FreePBX includes a module to make the process easier, simpler and cleaner.

To include your own dialplan in the call flow, we use a combination of modules. First, we need to tell FreePBX where in our dialplan we would like to point to. To do this, we set up a Custom Destination (from the tools tab) with the custom description pointing to out custom dialplan in the format of context, extension, priority. To refer back to our previous example, we would set the custom destination to: play-monkeys,66,1. We will also add a Description so that we can easily remember what this dialplan refers to. Lets call it play-monkeys. Then click submit.

Next, we need to create a Miscellaneous Application. The Misc Application module allows us to set up an extension (remember, in Asterisk an extension is somewhere in the dialplan that you can call - not necessarily a phone) that can point to anywhere. For example, if you want your users to be able to call an IVR which is usually only heard by inbound callers, you can set a feature code to call the IVR every time the feature code is dialed. Now we will set up a feature code to call out custom context: Click Misc Application from the setup tab, and enter a feature code, say 11234. Next Enter a description, say call monkeys. Finally, chose our custom Application form the Destination menu Custom Application: play-monkeys and finally click submit.

Now your all set! Reload FreePBX by clicking the orange bar, and call 11234 - you should hear the tt-monkeys file being played back!

There is one more thing to keep in mind. Sometimes, for whatever reason, you don't want to call your custom dialplan directly from FreePBX. Nevertheless, it is important to make sure that you don't accidentally assign a duplicate extension in both FreePBX and the dialplan. Being that FreePBX automatically picks a lot of the extensions it assigns, we need to let it know which extensions NOT to use. To do that, we use the Custom Extension module (tools tab), and we enter the extension number we want to prevent FreePBX from using. This will prevent FreePBX from chosing an extension that you already assigned manually in the dialplan.

That's all. Be sure to check back again next week for a tip on how to list all of the contexts and their includes from the dialplan!

Moshe Brevda, FreePBX Development Team
lazytt - FreePBX forums
hi365 - IRC

Continue reading...

Monday, October 6, 2008

Miscellaneous/Custom application/extensions: How to extend FreePBX with custom dialplan (part 1 of 2)

FreePBX was primarily designed to be a simple and easy to tool for programming asterisk dialplan and call flow. In the name of simplicity, however, it is sometimes necessary to sacrifice advanced features and overly complex ways of doing things. FreePBX takes a great middle ground in providing the best of both worlds: on one hand, an extremely powerful yet intuitive and simple GUI, and on the other hand a really neat way to seamlessly extend the gui into 'raw' dialplan. This is done using a combination of the Custom and Miscellaneous modules.


First, a small refresher on Asterisk Dialplan. Every asterisk instruction is composed of four parts:
  • Context
  • Extension
  • Priority and
  • Application
For example:

[play-monkeys]
exten => 66,1,Playback(tt-monkeys)

In this example, when a call hits extension 66, priority 1 in context play-monkeys asterisk will Playback the tt-monkeys voice prompt. Additionally, Asterisk also includes the ability to include one (or more) contexts inside another using the (believe it or not...) include command, for example:

[some-context]
exten => stuff here
include some-other-context

FreePBX takes advantage of the include feature to keep its dialplan simple and clean by breaking up the dialplan in to smaller contexts. The context FreePBX uses for its call routing is the from-internal context. from-internal itself is pretty much a blank context - accept for two includes. You can see it here:

[from-internal]
include => from-internal-xfer
include => bad-number

from-internal-xfer includes (amongst others) from-internal-additional and from-internal-custom. from-internal-additional is also pretty sparse - except for some more includes of many, many smaller context, corresponding to the entire FreePBX generated dialplan. from-internal-custom is always included - and always empty - so that you can use it as you'd like. Simply start a new context in /etc/asterisk/extensions_custom.conf and add your dialplan there. So to include our play-monkeys context in the FreePBX generated context we would add the following to /etc/asterisk/extensions_custom.conf:

[from-internal-custom]
include => play-monkeys

[play-monkeys]
exten => 66,1,Playback(tt-monkeys)

followed by a dialplan reload (asterisk -rx "dialplan reload" or asterisk -rx "extension reload" if your on asterisk 1.2). That's all! Now pick up an extension and dial 66. You should hear the tt-monkeys file being played back.

While this method is really simple, its got its drawbacks: If you were to include some code with, say, extension 66, and then you would set up a phone at extension 66 in FreePBX - what would happen when you dial 66?

That's right, asterisk would be kinda confused: it wouldn't know which '66' to call (actually it would pick one of them - but which is another story). In order to prevent such a situation, FreePBX rigorously protects the dialplan from having a double entry. You can't, ever, have two extension with the same extension number (try it!). You also can't have other 'destinations' (which are also called extension in asterisk dialplan language) such as ring groups or queues with the same extension number as another extension.

to be continued...

update: part 2 is here!

Moshe Brevda, FreePBX Development Team
lazytt - FreePBX forums
hi365 - IRC
Continue reading...