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!

Friday, November 11

Trouble shooting FusionPBX/FreeSWITCH

At some point in time you might want to know what is going on on your network between your PBX and a VOIP provider or between your PBX and a phone.

You can do a packet capture directly on the PBX (much simpler than trying to get wireshark loaded on another machine and connected to the network at an appropriate point where it can see all the traffic).  To do this you need to install the ngrep package.  Do this with:

yum install ngrep

Once it is installed if you want to check traffic going to your VOIP providers you can use:
ngrep -W byline port 5080
This works because on FusionPBX all external traffic comes in on port 5080.  So this will capture all packets on the external interface.

If you want to capture all the packets on the internal interface that relate to extension 102 then use:
ngrep 102@ -W byline port 5060

Note that this captures to stdin ie. directly to your console.  To end the capture you press CTRL-C.  If you want to keep your capture you'll need to scroll back in your screen buffer and cut and paste the information and put it into a text file.  There may be another way to do this but I don't know about it.  If you know another way feel free to comment.

Monday, November 7

Unrelated to fusionpbx but maybe you'll find it useful

I've recently started a new general blog.  The new blog will contain information about various technical solutions to things and information about free software solutions that I use and recommend.

If you are interested take a browse to http://techsol.bugs3.com

Please note that it has only just started, so there isn't a lot there yet.  But I'm going to try to add at least one thing most weeks.  Theoretically that will be achievable since there is lots of free software that I use and therefore I should always have something I can comment on.  Apart from free software, whenever I develop a solution for something that is not completely unique and no one else would have a use for it, I'll document it on there for other people to use if they like.

Thursday, October 20

Max_forwards issue

An Australian VOIP provider called iinet insists on delivering calls to consumers with a max_forwards setting of 4.  Max_forwards is a setting in the SIP invitation for a call that specifies the number of times a call can be forwarded.  Forwarding seems to include every pass through the dial plan on the pbx.  Therefore if you want to send the call to an IVR and then to somewhere else and maybe to somewhere else you rapidly use up the available forwards.

The normal setting of this value is 70 by most other VOIP providers.  This setting is designed to be used to stop call loops occurring where for instance you set your office phone to forward to your mobile and your mobile phone to forward to your office phone.  In this circumstance if there was no max_forwards setting the call would keep forwarding forever and would potentially overload the phone systems involved.

To override a low setting just put a line in the inbound route for the service which has it set low and use set max_forwards=65.  You can set it to any number you want, but I figure 65 is a good number - it isn't quite 70 but it is pretty close.

Tuesday, October 18

Voicemail for mobile/cell phone

I've recently changed mobile phone providers and my new provider is charging me more to receive and check voicemails than it costs to divert the call to another number.   Not only this, they are charging me in 30 second increments.

The VOIP service providers I have connected to my FusionPBX server give me better rates than that.  They also only charge in 1 second increments.  Therefore I saw an opportunity...

So my goal was to create a voicemail setup on my FusionPBX server that worked well as a replacement for my mobile phone providers' voicemail service.
1. it needs to take the message for me
2. I need to know if a person has left me a message or not
3. I need to be able to retrieve the messages
4. I need to be able to do all of this cheaply

1 and 3 are easy.  2 is more complicated.  Ideally I'd send an SMS to my phone, like the mobile phone provider does, to tell me the number of messages there.  Well I don't have SMS sending capability on my FusionPBX server at this point so there has to be another way.  The way I decided is this - I get a missed call message whenever someone calls but is diverted to voicemail - so after getting one of those (or after my phone has been switched off or not in a mobile area) I'll phone a number on my FusionPBX server and if it rejects my call then I'll know I have voicemails to listen to, if it rings indefinitely then there are no voicemails to listen to (this was my initial plan anyway, but as you will see below I have now decided to use early media to indicate whether there are messages present or not).  This might not make sense yet but go with me on it.

To address 4.  I'm going to divert the calls to my FusionPBX voicemail box.  Then, to retrieve the calls I will phone FusionPBX and it will reject my call.  I'll hangup and then it will call me back.  That way I'll listen to my voicemails using the rates that my VOIP provider gives rather than the rates my mobile phone company gives.

Testing shows that my mobile phone company delivers diverted calls to my FusionPBX VOIP number as if the caller had been calling that number in the first place.  In other words, the caller id is the original caller's caller ID rather than anything different.  There is no other data provided with the call apart from the max-forwards being 1 lower than a usual incoming call, so although we can tell that this call has been forwarded we cannot determine who it was forwarded for.  So this means we need to dedicate a landing number to each mobile we use this solution with.  Fortunately I have a few spare incoming lines at the moment so we can do this.

So how do we go about doing this?

We're going to use vm_boxcount to tell us if there are any messages waiting (to know how to handle an incoming call from the mobile phone) - http://wiki.freeswitch.org/wiki/Mod_voicemail#vm_boxcount
We're going to use the voicemail application to check our voicemail messages - http://wiki.freeswitch.org/wiki/Mod_voicemail#Check_Voice_Mail
And we're going to use the api_hangup_hook - http://wiki.freeswitch.org/wiki/Variable_api_hangup_hook - to do an originate - http://wiki.freeswitch.org/wiki/Mod_commands#originate - from the dial plan so that we can make a call to the mobile and connect it to our dialplan that plays back the voicemail messages.

We're going to use early media to provide message counts (alternatively if your VOIP provider doesn't support the use of early media (apparently it is not mandatory) we could use ring_ready, followed by sleep 15000 to cause the phone to ring for 15 seconds before answering if there are no messages - that way it doesn't waste money as the call hasn't been answered).  To use early media we use playback before answering the call, this automatically puts it in early media mode, then we hangup at the end rather than answering the call.  (note that pre_answer is not necessary as playback automatically puts the call into early media when it happens)

First we identify the incoming number that will be allocated to mobile phone voicemail.  You will also have to setup an extension on FusionPBX that will be used for your mobile phone voicemail.  Then we define an incoming route for this number that will handle the call if there are NO voicemails waiting:


TagTypeDataOrderadd
  condition  context  public  0edit delete
  condition  destination_number  ^your_destination_number_goes_here$  1edit delete
  condition  caller_id_number  ^your_mobile_number_goes_here$  2edit delete
  condition  ${vm_boxcount(vm_extension@yourdomain)}  ^(0)$  3edit delete
  action  sleep  2000  0edit delete
  action  playback  /usr/local/freeswitch/sounds/en/us/callie/misc/8000/sorry.wav  0edit delete
  action  playback  /usr/local/freeswitch/sounds/en/us/callie/voicemail/8000/vm-you_have.wav  1edit delete
  action  playback  /usr/local/freeswitch/sounds/en/us/callie/voicemail/8000/vm-no_more_messages.wav  1edit delete
  action  playback  /usr/local/freeswitch/recordings/ringing-sound.wav  1edit delete
  action  playback  /usr/local/freeswitch/recordings/ringing-sound.wav  1edit delete
  action  hangup  NO_ANSWER  3edit delete


You will see that we check that the call is for this inbound number, then we check if it is from your mobile, then we check if there are voicemails waiting for you in your voicemail box.  Then if there are no messages we use early media to inform the caller that there are no messages for them and then we play a ringing sound and hang up.  You don't need to play the ringing sound - I just wanted to end that way.  Because we use early media the caller isn't charged for the call as it works in the same way as the messages from your service provider that say the number you called isn't connected.


You need to replace:
- your_destination_number_goes_here
- your_mobile_number_goes_here
- vm_extension
- your_domain
with appropriate values for your implementation.


Next we define an incoming route for this number that will handle the call if there ARE voicemails waiting:

TagTypeDataOrderadd
  condition  context  public  0edit delete
  condition  destination_number  ^your_destination_number_goes_here$ 1edit delete
  condition  caller_id_number  ^your_mobile_number_goes_here$  2edit delete
  action  set  api_hangup_hook=originate {ignore_early_media=true}sofia/gateway/your_outbound_gateway_goes_here/${caller_id_number} 888888 XML default  0edit delete
  action  sleep  3000  0edit delete
  action  playback  /usr/local/freeswitch/sounds/en/us/callie/voicemail/8000/vm-you_have.wav  0edit delete
  action  playback  /usr/local/freeswitch/sounds/en/us/callie/voicemail/8000/vm-messages.wav  0edit delete
  action  sleep  15000  1edit delete
  action  respond  487  4edit delete
  anti-action  transfer  vm_extension XML default  3edit delete

This route differs from the last one in that it sets the api_hangup_hook to originate a new call back to the mobile after this call hangs up.  Again, using early media it indicates this time that there are voicemails available.  Note that if the call is not from the mobile phone we send it to your voicemail box - therefore when you divert your mobile phone you divert it to the same number you use to check your voicemails with.



You need to replace:
- your_destination_number_goes_here
- your_mobile_number_goes_here
- vm_extension
with appropriate values for your implementation.

If you want to use a different extension to handle the call back instructions then replace 888888 with that, otherwise use 888888 for the next dialplan entry.

Next we define a dialplan entry for the callback feature:

TagTypeDataOrderadd
  condition  destination_number  ^(888888)$  1edit delete
  action  sleep  500  3edit delete
  action  answer    3edit delete
  action  set  voicemail_authorized=true  6edit delete
  action  voicemail  check auth default $${domain} vm_extension  7edit delete
Here you can see that we check for the 888888 that we used in the previous route.  Then we pre-authorise voicemail access and use the voicemail application to check voicemail.

You need to replace:
- vm_extension
with an appropriate value for your implementation.

With that you are all done.  Now divert your mobile phone on busy, no answer, and off/no coverage to the number you setup on your fusionpbx server.  What happens now is that incoming calls on your mobile that are not answered go to FusionPBX and are answered there by your voicemail.  If you see a missed call indicator on your phone you call the number you setup on your fusionpbx server and it will tell you either "sorry you have no more messages" or "you have messages" and it will then hangup (or you can hangup - either way is good).  If you have messages then after you hang up it will call you straight back and you can answer the call and will hear your voicemails.

Hopefully you find this as useful as I do to keep costs down from your mobile provider.