1. Macro - this application allows you to execute a macro, which has been defined beforehand.

NOTE: This application is valid for Asterisk version 1.0.9 and above.

Syntax:

Macro(macroname|arg1|arg2)

Purpose and usage

The purpose of this application is to save your time and the writing of one and the same extensions. For example, if you have a big and complicated dialplan with 100 lines and you have to add 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.

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 two 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 1111 and 2222

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. Callerid=1111 <> means that the Caller ID of this user will be 1111 and there won’t have a Caller ID Number because the space between the <> characters is blank . You have to write it in the shown way, because there is no separate option for Caller ID Number. This is a way to assign a number to a specific user.

extensions.conf Configurations

First of all, we will put the number 1111, in the Asterisk’s database, as blacklisted. We can do this by typing the CLI command - database put blacklist 1111 1. You can see a screenshot below.

We have to create a macro context. This is a context which starts with the word macro, followed by the dash character and then by the desired name of the context. In our example, the macro context has the name [macro-macrotest]. In the macro context, we have to write the extensions, which we would like to be executed, when the macro is called by the Macro application. Each extension has to start with the letter s, which shows that this is a special extension called Start extension. You can learn more about it in our tutorial about the extensions.conf file.

In our example we will make a simple filter for the incoming calls. We will make a check, whether the Caller ID is in our database as blacklisted or not.
The check will be made by the LookupBlacklist application. If the Caller ID is in the Asterisk’s database, then the next executed extension will be the one with priority n+101(n is the number of the current extension). In our case this will cause the sending of a text message to the caller. The message is: You do not have permission to access our system. The message will be send thanks to the SendText application. The next extension will execute the Dial application.

We want to use this macro in a great number of contexts. So we need it to be more universal. That is why, we will use the ${ARG1} variable as an argument in the brackets of the Dial application. This is some kind of temporary variable. It points to another variable, which will be define later, when we will call the macro context with the Macro application.

The macro context is ready and we have to call it in the test context. For the purpose we will use the Macro application. Its usage is very simple.

When somebody dials 1111, the call will be answered by the Answer application. The next executed extension will be the one which contains the Macro application. As arguments in its brackets, we have to write the name of the macro context and the desired variable, which to replace the ${ARG1} variable. 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-macrotest. We have to write in the brackets only: macrotest.

The variable in our case will be ${EXTEN}. This variable, will cause the Dial application to connect the call to the user with the same name as the dialled extension number. In other words, if you dial number 1111 the call will be connect to the user with username 1111. The connection in our case will be performed through the IAX2 channel. This is enough to call the macro context.

The execution of the Macro application will cause the jumping in the macro context, starting from the extension with priority 1.

So the Caller ID will be checked and if it is not in our blacklist, the call will be connected to the user 1111 through IAX2 channel. If the Caller ID is blacklisted then a message will appear on the screen of the caller.

We can use the same macro in other contexts and with another extension numbers. On the picture of our extensions.conf file, you can see, that we have used it also with the extension number 2222

We will show you the both variants, by using two separate users, registered in our iax.conf file.

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 your Idefisk and on the CLI of the Asterisk PBX

1) Caller ID 1111 - blacklisted

2) Caller ID 2222 - not blacklisted

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