Throttling outbound calls with call files

While there seems to be a lot of topics about throttling incoming calls, I had a hard time tracking down info on how to do it on outbound - specifically call files, so I thought I would consolidate it here if anyone needed.

I am using a sip provider that lets me make multiple calls on the same DID since I am setting callerid on each call, but there is a limit to how many simultaneous I can make. They do have a burst option available, but it is $0.25/call so we would want to minimize that as much as possible.

We are using a PHP script that builds the call files in /var/spool/asterisk/outgoing/ which would look like this:

Channel: Local/1@sip-queue
MaxRetries: 5
SetVar:DIALNUM=4805551234
Callerid: <9286664321>
Context: outboundmsg
Extension: s
Priority: 1

This would call using a Local extension that checks to see how many calls are in use, and what the max is. This is defined first in the globals section:

[globals]
MAXCALLS=4
.....

Then at the bottom of my extensions.conf file:

[sip-queue]
; Set Group
exten => _X,1,Set(GROUP()=OUTBOUND_GROUP)
; Are we exceeding the limit?
exten => _X,n,GotoIf($[${GROUP_COUNT()} > ${MAXCALLS}]?999)
exten => _X,n,Dial(SIP/${DIALNUM}@SET_YOUR_SIP_PROVIDER_HERE)
exten => _X,n,Set(DIALSTATUS=CHANUNAVAIL)

This local extension is used before it addresses the context of “outboundmsg” and defers any extra call files till later.

So we have 5 max simultaneous without burst, so I will set the max at 4, so that we can still take an incoming call, if by chance we get a 2nd incoming call at the same time, we would be billed that $0.25 which would be OK.

2 Likes