Call limit freeswitch (FusionPBX) on outbound calls

Cristian Livadaru
Jul 28, 2017 · 2 min read

I had a special request to send two inbound calls to a phone number (PSTN), if that phone number already had two active calls it should send the next two callers to a second phone number and if that one received two calls any other caller would just receive a sound file saying all lines are busy. Sounds simple and sounds like something freeswitch limit would handle.

Well, my first problem was that I didn’t see this important note at the beginning:

Note that a limit is active within a given context — if you transfer an inbound call from the public dialplan to an extension in the default dialplan — any limit you just set in the public dialplan will be reset.

Well… what that means is that as soon as you transfer the call, the limit is set back to zero and you have no clue on how many calls you actually already sent out. This is when I came across this blog post regarding execute_on_answer

Another request was to play some audio file while it was ringing, I could have done it with ring groups in fusionpbx but that caused some other issues so I went with a custom dialplan which looks like this.

Dialplan with caller limitation

first we export the limit and execute it on answer

action export nolocal:execute_on_answer=limit db ${domain_name} studio1

Then in a second condition we check if the limit counter is > 1

${cond(${limit_usage(db foo.example.net studio1)} > 1 ? true:false)}

if this is true, we transfer the call to our second dial plan 602.

For the audio playback while ringing to work, this does the trick

ignore_early_media=true
instant_ringback=true
ringback=/var/lib/freeswitch/recordings/foo.examle.net/somefile.wav
transfer_ringback=/var/lib/freeswitch/recordings/foo.examle.net/somefile.wav

Now to our second dialplan which looks like this

Here we basically do the same, only that if the limit on studio2 > 1 we just play the desired audio file and hang up.

Cristian Livadaru

Written by

all kinds of IT Stuff

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade