1. SubString - this application allows you to save sub-stringed digits in a given variable.
NOTE: This application is valid for Asterisk version 1.0.9 and above.
Syntax:
This application is deprecated, so in order to obtain similar result, please use the following syntax:
Set(NewVar=${variable:digit1:digit2})
List with the possible options
digit1 - this argument shows from where the reading of the value to start: from left to right or from the right to left. Also it shows from which digit to start. If the digit is positive the reading will start from the beginning. If the digit is negative then the reading will start from the end of the value. digit2 - this argument shows how many digits to be read.
Purpose and usage
This application will read the value of the variable and then according to the specified digits, it will take some of the letters or digits from the value and it will store them in a new variable.
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.
iax.conf Configurations
We need one registered user 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 user user1
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.
In our example when somebody dials 1111, the call will be answered by the Answer application. The next executed extension, will be the one which contains the Set application. Thanks to it, we will set the following value: 0123456789 - to the variable test.
The next executed extension also contains the Set application. However, here as arguments in the brackets we will set the following: ASD=${test:-2:2}. What would be the effect of this extension? The variable test will be read. -2 means, that we will start from the end of the value and we will read it to the left. 2 means that we will read the first two digits from the left and they will be stored in a new variable. In our case this variable is ASD.
We will use the NoOp application to check the result from the previous operations. The extension with priority 4 will show us the value of the ASD variable. In our case it is 89. These are exactly the last two digits from the value of the test variable. So the operation is successful.
In order to be sure that the Asterisk PBX will hang up the line after the conversation is over, it is a good idea to make an extension for hanging up the line.
2. Screenshots of what you can see on the CLI of the Asterisk PBX
3. Additional information
For more information about extensions.conf you can check here.
For more information about iax.conf 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