Call limitation

Hi there,

I want to set call limit on on my sip provider, we are running call center and we need to set limits for example
when we start calling, first 50 calls should go to provider 1 and then next 51th call should go from provider2 and in the same way if it increase by 100 then 101 call should go from provider3 .
is there anyway to set it in asterisk directly or i need to create agi?

Thank in advance


Sohaib Khan


what do you want exactly? you want a maximum of 50 concurrent calls through one trunk and then go to the other trunk?
Or do you want just first 1-50 calls through the first trunk, 51-100 calles through the second trunk?

First solution:
you can set a call-limit in sip.conf at the peer configuration of your trunk:


Then you could set in the dialplan
exten => _X.,1,Dial(SIP/trunk1/${exten})
exten => _X.,n,GotoIf($["${DIALSTATUS}" = “CONGESTION”]?trunk2)
exten => _X.,n(trunk2),Dial(SIP/trunk2/${exten})
exten => _X.,n,GotoIf($["${DIALSTATUS}" = “CONGESTION”]?trunk3)
exten => _X.,n(trunk3),Dial(SIP/trunk3/${exten})
exten => _X.,n,Hangup()

Second solution:
I would work with the asterisk database.
exten => _X.,1,Set(COUNT=$[${DB(test/count)}+1])
exten => _X.,n,Set(TRUNK=$[${COUNT}%150])
exten=> _X.,n,GotoIf($[${TRUNK}<50]?trunk1)
exten=> _X.,n,GotoIf($[${TRUNK}<100]?trunk2)
exten=> _X.,n,GotoIf($[${TRUNK}<150]?trunk3)
exten => _X.,n(trunk1),Dial(SIP/trunk1/${exten})
exten => _X.,n(trunk2),Dial(SIP/trunk2/${exten})
exten => _X.,n(trunk3),Dial(SIP/trunk3/${exten})
exten=> _X.,n,Hangup()

The dialplan i wrote has not been tested, so some errors can be in!

hi Tom,

Thank you for your prompt reply…
yes, i need to start 50 calls, what heppens in our dialing we have set ratio of dialing 4 calls per agent… and when agent login asterisk starts dialing call, and if it hit 50 the next 51 should go from another carrier, although my provider has set more 51 channels on m account. but i am not sure for that so that is why i need to set only 50 …

Can it be done?


Sohaib Khan

what do you exactly want: that after 50 calls you switch to another provider? Even if there is only 2 agents active?

Or do you want that the first 50 calls go to trunk1,and if it is really busy and a lot of agents are working, the second/third trunk is activated too?

Hi Tom,

I want to send 50 calls with first trunk even if there is only 2 agents active.

is it possible?


Sohaib Khan

Then you need something like this
You count the number of calls and use a gotoif-statement to send them to the right trunk.

exten => _X.,1,Set(COUNT=$[${DB(test/count)}+1]) exten => _X.,n,Set($DIRECTION=$[${COUNT}%150]) exten=> _X.,n,GotoIf($[${DIRECTION}<50]?trunk1) exten=> _X.,n,GotoIf($[${DIRECTION}<100]?trunk2) exten=> _X.,n,GotoIf($[${DIRECTION}<150]?trunk3) exten => _X.,n(trunk1),Dial(SIP/trunk1/${exten}) exten => _X.,n(trunk2),Dial(SIP/trunk2/${exten}) exten => _X.,n(trunk3),Dial(SIP/trunk3/${exten}) exten=> _X.,n,Hangup()

Thanks Tom… Thank you … I will try this today and let you know :smile:

once again thank you dear.