• Idefisk
  • Tools
  • Tutorials
  • Reviews
  • VoIP Providers
  • Archives
ZOIPER softphone
Back to Tutorials

6.1.2.37. Macro (dialplan application)

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.

Below, we will give you an example.

 


Prerequisites

To use this application you need a working Asterisk PBX with registered users in iax.conf, sip.conf or mgcp.conf(It depends on which protocol you would like to use) and made extensions. Also you need to create a [macro-name] context in extensions.conf file.

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.

iaxtwouserscid.jpg

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.

databasemacro.jpg

Now lets take a look at the extensions.conf file.

extmacro.jpg

On the picture above you can see our extensions.conf file.

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
idemacro1.jpg

cli112wait.jpg

2) Caller ID 2222 - not blacklisted
climacro2.jpg

 


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

 


4. Uploaded files

extensions.conf
iax.conf

 


5. Similar dialplan applications

MacroExit()
MacroIf()

 

 
User Comments
JasonAspix (1758zascpt0jm at mantilia48 dot fancycarnavalmasks dot com)
02 March 2019 19:41:36
cialis nedirbrand name cialis for sale Buy Cialis <a href="http://xcialis20mg.com">xcialis20mg.com</a>
Ali (sfcr777 at yahoo dot com)
08 August 2008 11:34:40
Hi,
I want to configure the call center setup, can
someone help me.
Jose Maria (sarachaga at yahoo dot com)
13 February 2007 23:48:17
Hi you all

I'm trying to configure a dialplan where you dial into the system and hangup, and after a few seconds the system calls you back and take you to a certain context.

I can make the automatic call be made, but never takes me to the context i need, like if the Dial application was holding the execution control, and don't let me execute more applications.

Any advise?

Here is my extensions.conf

[CallOutBT]
exten => s,1,Wait(1)
exten => s,n,Hangup()
exten => h,1,Dial(SIP/1392@10.80.232.25 & s@BTService)

I've tried with a macro, using the M() option on the Dial application but does the same.

Any advise on this?

Thanks in advance
 
Add Comment
Name:
Email:
Comment:
In order to prevent automatic posting on our website, we kindly request you to type in the number you see in the picture below.
Image Verification:
 

Latest Headlines:

  • T.38 faxing with Zoiper 2.15 is now easier than ever
    section: voip software
  • Asterisk 1.4.21 Released
    section: Asterisk
  • Asterisk 1.4.20 Released
    section: Asterisk
  • Asterisk 1.4.20-rc2 Released
    section: Asterisk
  • Asterisk 1.4.20-rc1 Now Available
    section: Asterisk
  • News Archives (older news)

Latest Tutorials:

  • Sending Fax from Zoiper to Zoiper using T.38
    added 08/Dec/2008 18:16
  • VMAuthenticate (dialplan application)
    added 01/Mar/2008 15:57
  • Siptronic ST-530
    added 06/Nov/2007 17:57
  • Siemens C455 IP hardphone
    added 05/Nov/2007 10:24
  • Zoiper
    added 22/Oct/2007 17:53

Latest Comments:

  • https://donde-ver-ant-man-y-la-avispa-qu...
    tutorial: Digium Wildcard TE405 / Wildcard TE410P
  • https://donde-ver-scream-6-tyt.statuspag...
    tutorial: Digium Wildcard TE405 / Wildcard TE410P
  • https://donde-ver-guardianes-de-la-noche...
    tutorial: Digium Wildcard TE405 / Wildcard TE410P
  • https://donde-ver-demon-slayer-villa-de-...
    tutorial: Digium Wildcard TE405 / Wildcard TE410P
  • https://www.reddit.com/r/BenavidezvPlant...
    tutorial: Digium Wildcard TE405 / Wildcard TE410P
 
contact us at: support@asteriskguru.com - asterisKGuru.com © all rights reserved   |   *asterisk is registered trademark of © Digium™