If none of the requested channels are available the new priority will be n+101 (unless such a priority does not exist or on error, in which case ChanIsAvail will return -1).
If there is an available channel the execution will continue with the execution of the n+1 priority extension and also the variable ${AVAILCHAN} will be set with the name of the available channel. The ChanIsAvail application will return 0.
Purpose and usage
With this application you can check your channels to see whether there is a free one. If an available channel exists, its name will be set in the variable ${AVAILCHAN}.So you can use this variable for different purposes in your next extensions. For example you can use it to dial a user through the available channel.
To see how the application works we recommend to use our IAX softphone Idefisk. You can download it from here. Please also read our tutorial to learn how to configure it to work with Asterisk PBX.
Asterisk PBX configurations
NOTE: This is only an example of what for you can use this application. Of course you can use it and for other things.
We need three registered users in iax.conf file. This is because we are going to use the IAX2 protocol. If you want to use other protocol such as SIP or MGCP, you have to do the configurations below respectively in sip.conf or mgcp.conf.
So, we have registered the users anatoliy, user1 and user2.
Type=friend means that this user can make and receive calls. Host=dynamic means that the IP is not static but dynamic through a DHCP server. Allow=all means that the line which this user will use, could support all audio codecs. Context=test - this shows that this user is working with the extensions in this context of the configuration file extensions.conf.
NOTE: Currently supported channels are ZAP, SIP, mISDN and IAX2. The MGCP channel is not supported.
When somebody dials 111 the Asterisk PBX will answer the cal. The the ChanIsAvail application will be executed. This application will check first the channel IAX2/1 and if it is not available will check IAX2/2.
When one of the channels is available the special variable ${AVAILCHAN} will be set with the name of this channel.
However, the name will contain also the channel’s session ID. You can see this with the Read application.
So, we need to cut this session ID in order to use the variable with the application Dial.
For the purpose we will use the application Cut. In the brackets of Cut you have to write the name of new variable then "=" and then AVAILCHAN. As you can see the variable AVAILCHAN is without ${}. For example: exten => 111,4,Cut(NewVar=AVAILCHAN,,1).
${NewVar} will contain only the name of the channel. Now you can use it with the Dial application. For example: exten => 111,5,Dial($(NewVar)/anatoliy).
If there is no available channel the ChanIsAvail application will continue with the execution of the extension with priority n+101. So, we have made such extension with the application SendText and the message Sorry there are no available channels! Please try again later!. This message will be send to the caller.
2. Additional information
For more information about extensions.conf you can check here.
For more information about iax.conf you can check here.
For more information about indications.cong you can check here.
For more information about the SendText application you can check here.
This application is tested with our IAX softphone Idefisk. You can download it from here. For more information about this softphone please read our tutorial.
If you would like to test this application with the SIP channel you can read our tutorials about the SIP Softphones to learn how to configure them to work with Asterisk PBX