FusionPBX for ex-Trixbox users

This blog is intended to be read in sequential order as it is a series of steps that I followed to build a fully functioning fusionpbx phone system. However you might just need to find out how to do a particular thing so you might want to use the search box below to find that specific step. Please give feedback - if you know a better way to do something share it!

Thursday, August 5

Dial plans - some recipes

Dial plans are a little complicated to work out, so this section is going to grow over time as I think to document more ways of doing things.  Each item will be in the form of a scenario followed by the solution to it.  I'll try not to use just simple examples each time, so that in each one we learn a little more than the basic scenario requires.

Scene 1:
You want a person to dial an abbreviated code to reach an external number, the abbreviated code might be a number that looks like an extension but the number you reach might be a mobile phone number for instance.  In our example we'll use 1002 - a typical extension number.  We must start the number with ^ and end it with $ - that is a requirement for a regular expression.

tag=condition
type=destination_number
data=^1002$

tag=action
type=bridge
data=sofia/gateway/your_gateway_name/the_external_number_you_wish_to_be_called

What will happen is that FusionPBX will see you dial 1002 and it will connect your call to the external number.  Simple!

Scene 2a:
What about a situation where you want a number you dial to be sent out a specific trunk, different to the default routes you have set up in other dial plan entries?  For instance, I have a trunk on my system that I use just for business calls so that I can track the cost on that independently to personal calls.  I have a number I regularly need to call for business and I want it to automatically be on the business trunk.  Since I regularly call it I also want to be able to use a short dial sequence for it too.  Not only that, but when I go to my company office and dial it from there I have to dial 0 before I dial the number, so when I am doing it from home sometimes I make the mistake and dial 0 first out of habit and therefore I want that to succeed also.

tag=condition
type=destination_number
data=^(\*627|0?the_external_number_I_am_dialing)$

tag=action
type=bridge
data=sofia/gateway/your_gateway_name/the_external_number_I_am_dialing

In this example, my short dial is *627.  In order to make the * be seen as an actual character to be dialled rather than a regular expression character I have to preceed it with \ which tells freeswitch to read the * as a * not as having a special meaning.  

In the example as well you will see the | character.  This tells freeswitch that I can either dial *627 OR whatever is after the | and they should both be considered a match with this dial plan entry.  You can put as many of these | together as you like eg \*627|1110|174538 would let me dial either *627 or 1110 or 174538 and each of these would result in the same action taking place.  After the | you will see 0? - the ? means that the digit before it is optional.  If it said 0?1111 then this expression would be valid if I dialled either 01111 or 1111 on its own.  So this allows me to handle my confusion between dialing at home where 0 is not necessary or dialing at work where 0 is necessary for an outside line (in some countries this is typically 9 rather than 0 and you can do this with 9?).  So if I make the mistake at home and dial 0 it will still work as expected.

Lastly you will see that I have shown both the external_number_I_am_dialing in the condition AND in the action.  This is because I said I wanted to be able to dial my short dial of *627 OR the full number OR 0 followed by the full number and I want all of them to succeed and to go down the correct trunk - specified by your_gateway_name in my example.

Scene 2b:
Although I mostly dial a few specific numbers from home that I want to be charged to my work account, there are times that I need to return a call for someone and so I can't list all of these numbers in my phone system as specific dialplan entries to go onto my work trunk.  Effectively we are setting up a special trunk selector prefix that will cause the call to use a specific trunk (in my thinking trunk=gateway - they appear to be almost synonyms).  To solve this I set up a special prefix in my dialplan.

tag=condition
type=destination_number
data=^11(\d*)$

tag=action
type=bridge
data=sofia/gateway/your_gateway_name/$1

In this example, my prefix is 11 and any time I dial this I want whatever number that follows to be dialled using my work trunk.  In the condition we see \d*, as mentioned earlier, \* means the * character.  In this instance * is not preceeded by \ and therefore it has a special regular expression meaning.  That meaning is "whatever character comes immediately before the * can be repeated infinitely and it will still match."  Therefore we can type as many \d characters as we like and it will be valid.  But what is \d?  That means ANY digit.  Therefore when we say (\d*) we are saying any digit any number of times.

Therefore 110011155555555 will be valid but also 1155555555 will also be valid.  We are saying here that you can dial ANY number after the 11 and it will be valid.  This is good at home for me, but you wouldn't create this sort of entry on a business phone system because people could dial the trunk selector (11) and then could dial any number at all and ring up massive charges by calling adult chat lines etc. which most companies wisely block from being usable from the office phone system.

So a better way of doing this is to create an entry like this for each of the valid number ranges you wish to be able to dial. ie. duplicate your standard dialplan but prefix it with 11.  At least, this is my recommendation until I can find a way of making a generic dialplan that doesn't require me to specify the gateway being used at the time of validating the number that is dialled.  Anyone who has a better way is welcome to provide comments.

Incidentally, originally I wanted to use *8 as my prefix (which would have been written in the dialplan as \*8) however this clashed with some of the internally defined dial plan functions (something to do with eavesdrop I think) so I decided to use 1 as the first digit of any special function since no phone numbers I am aware of in Australia are permitted to start with 11.

More Scenes still to come...

No comments:

Post a Comment