Check if SIP trunk have channel available?

How can I test if a SIP trunk have channel available? I tried to use DEVICE_STATE() function and CHANISAVAIL() application but the both didn’t work.

Example DEVICE_STATE():

exten => s,4,Noop(DEVICE_STATE = ${DEVICE_STATE(PJSIP/39875*${ARG1}@provider1)})

Return INVALID

Example CHANISAVAIL():

exten => s,3,Noop(AVAILCHAN = ${AVAILCHAN})

Variable AVAILCHAN return the channel same when it was BUSY.

PS: I am using Asterisk 13 with PJSIP.

SIP trunks don’t have fixed numbers of channels. Any such limit is a commercially applied constraint, or the result of limited bandwidth. Asterisk will have no idea of what limits apply.

If you acquired a limited amount of simultaneous channel’s, you can use GROUP_COUNT() to sum your trunk usage and check/update for every inbound/outbound trunk call.

Thanks, I used this function to build the solution. Basically I control the amount of channels hired for the SIP trunk and didn’t send more calls to it if was in the max limit.