The purpose of this application is to save your time and the writing of one and the same extensions. It is very similar to the Macro application. However, this application gives you the possibility to make a choice between two macros, based on certain conditions. The macros make your work more flexible and the management of your dialplans easier. For example, if you have a big and complicated dialplan with 100 lines and you have to add one and the same additional extensions for each line, it is easier to make one macro with these extensions. Then with just one new line you will call these extensions wherever you want in your dialplan.
MacroIf gives you even more freedom, by giving you the possibility to choose which of two macros to execute, if one condition is true or false.
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 four 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 user1, user2, user3 and user4
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.
First of all, we will create two global variables. The first one is called GERMAN_OPERATORS and the second one is called ENGLISH_OPERATORS. You can learn more about the global variables in our tutorial about the extensions.conf file. We will use the values of these variables, to call the users user1, user2, user3 and user4.
Lets see the two macro contexts. The first one is named [macro-english] and the second one - [macro-german]. They are almost equal. The difference is in the parameter in the dial application, responsible for the users, which have to be connected. In the German context this is the variable ${GERMAN_OPERATORS). In the English context is ${ENGLISH_OPERATOR}.
In both of the macros, we have an extension with the Playback application. Thanks to it the caller will hear a welcome message, in English or German (according to the language of the caller).
There is an extension with the Dial application. In its brackets we have either the ${ENGLISH_OPERATORS} variable or the ${GERMAN_OPERATORS}variable.
The last extension in the macros is the one with the Hangup application. This one will hang up the line after the conversation is over.
When somebody dials 1111, the call will be answered by the Answer application. The next executed extension will be the one which contains the MacroIf application.
As arguments in its brackets, we have to write the condition and which macro to be executed if it is true and which one if it is false.
In our case the condition is a simple check - whether the language is set to de(german) or to something else. If it is de then the macro-german context will be executed. If it is something else, then the macro-english context will be executed.
The check will be performed thanks to the ${LANGUAGE} variable. This variable stores the value of the language variable in the iax.conf file.
The condition is followed by the question mark and then by the name of the german macro context and then by the name of the english macro context. Not the whole name, but only the part of the name, after the dash character. In our case the whole name of the macro context is: macro-german. We have to write in the brackets only: german. The two contexts are separated by the : character.
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.
2. Screenshots of what you can see on the CLI of the Asterisk PBX
1) German Language
2) English Language
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
Hugo (jwyf2s9l at hotmail dot com) 20 December 2015 21:34:05 Actually, I let a plugin to all of my ieatrnnl linking for me now. It looks at how my other posts are tagged and finds the appropriate keyword in the content. I am so slack about linking to my own content that this is the only way it will happen Sometimes it goes a little crazy though. http://mriwuqct.com [url=http://lngmdapge.com]lngmdapge[/url] [link=http://sfqomepn.com]sfqomepn[/link]