1. ReadFile - this application allows you to read characters from a file.
NOTE: This application is valid for Asterisk version 1.0.9 and above.
Syntax:
ReadFile(varname=file,length)
List of the possible options
varname - the name of the variable in which you would like to store the read characters. file - the full path to the file, plus its name, plus its extension. length - the number of characters you would like to capture and store in the varname.
Purpose and usage
The purpose of this application is to give you the possibility to read the content of a text file. You can use it, to read any kind of information, which you decide, that is appropriate. The application could read letters as well as numbers.
Below, we will give you an example, how to use this application.
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.
When somebody dials 1111, the call will be answered by the Answer application. The next executed extension will be the one which contains the ReadFile application. As arguments in its brackets we have written the following: test=/tmp/test_file.txt,13.
test - the variable which will store the read characters. In other words, the application will read the specified characters and then it will store them in this variable.
/tmp/test_file.txt - this is the full path to the text file(/tmp/). Also, the filename(test_file) and its extension(.txt)
13 - the number of letters ar digits which the application has to read. It will read the first thirteen characters.
The next executed extension, will be the one with the SendText application. Thanks to it a message will be displayed on the caller’s screen. The message will contain the value of the test variable. In other words it will show us the thirteen letters or numbers, which the ReadFile application read and stored in the variable test
Finally, 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.
NOTE: The ReadFile application could read the characters horizontal as well as vertical. The space between the characters is also counted. Also, the new lines are counted as one character.
NOTE: In the horizontal arranged file the characters are: 1010 test asterisk idefisk. In the vertical file they are arranged like the following:
1010
test
asterisk
idefisk
2. Screenshots of what you can see on your Idefisk and on the CLI of the Asterisk PBX
1) With horizontal arranged characters
2) With vertical arranged characters
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