Howto limit inbound channels on PRI

This is an inbound call center. I have 3 PRIs from my telco. Each PRI is associated with a different RATE CENTER. Inbound calls come in on PRI-1, then PRI-2, then PRI-3. I need to reserve a few channels (4 or 5) on PRI-1 for outbound calls. On each incoming call, I need to get a INBOUND call count, and if => 18, return a message to the telco indicating “no channels available”. The telco will then hunt to the next trunk group (PRI-2).

I’m thinking that i could create a [from-pri1] custom context in extension_custom.conf. I need some help on getting the inbound call count and returning the right message to the telco. Actually, I could use a combination of inbound and outbound as the “count”, and keep the max at 22. This way there would always be one free channel for outbound.

exten => _.,1,“Get Count, goto priority 3 if => 22” <-- Need help here
exten => _.,2,Goto(from-pstn,${EXTEN},1)
exten => _.,3,“Return no channels available to telco” <-- Need help here
exten => _.,4,Hangup()

Any help greatly appreaciated.