Macro : Macro in Asterisk

In Asterisk, a macro is a special kind of context which can be expanded within the definition of another context. Its name must begin with “macro-”.

A macro is expanded by using the Macro command.

All the lines of the macro definition should only use the s extension; the actual extension will come from the line in the calling context on which the macro is expanded.

Macro Life Cycle:

  1. Executes a macro using the context macro- name
  2. Jumping to the s extension of that context
  3. Executing each step
  4. Returning when the steps end.

What if, Called Party Hangup while Macro Executing:

If a macro executes a Dial() and the called party hangs up, then the control passes to the ‘h’ extension of the calling context.

is h – extension required in Macro Context:

The ‘h’ extension is still needed inside the Macro context in case of a command, application, or extension exiting non-zero – i.e. the user hangs up in the middle of a Record() – in this case the ‘h’ extension of the Macro context is used, not the ‘h’ extension of the calling context.

Nesting of Macros:

Asterisk Macros are not very good at going several levels deep. It is by design limited to 7 levels deep, although some people tweak it to go many levels deep, and I’ve even seen a crash caused by nesting of macros.

Point to be Noted:

you cannot use any other extension than ‘s’ to construct the macro as control is returned to the calling context when the end of the ‘s,’ priorities is reached.

 Not strictly true. Other extensions can be used (as are used in the examples below), but ‘macro-name,s,1’ is always the starting point. The macro exits when, for the current extension, the priority ‘current priority’ + 1 does not exist (assuming that control would have passed to that priority had it have existed)

key presses within a macro will cause a jump to the calling context and WILL NOT jump to the appropriate extension within the macro context. This is a shame and means code becomes a lot more complex

Reference: -http://www.voip-info.org/wiki/view/Asterisk+cmd+Macro

[macro-screen]
exten => s,1,Wait(1)
exten => s,n,set(ph=${CALLERID(num):6})
exten => s,n,NoOp(Dial Status:${UNIQUEID})
exten => s,n,Set(CURLOPT(httptimeout)=1)
exten => s,n,Set(CURLOPT(conntimeout)=1)
exten => s,n,set(foo=${CURL(http://192.168.1.6//Connected/${ph}/0/${UNIQUEID})})

[test]

exten => _XXXXXXXXXX,1,Dial(DAHDI/g0/${EXTEN},,M(screen))

 

Related Posts

  • 48
    What is Asterisk? Asterisk is an open source framework for building communications applications. Asterisk turns an ordinary computer into a communications server. Asterisk powers IP PBX systems, VoIP gateways, conference servers and other custom solutions. It is used by small businesses, large businesses, call centers, carriers and government agencies, worldwide.…
    Tags: asterisk
  • 44
    Dialplan Introduction:  
    Tags: asterisk
  • 42
    Contexts Dialplans are broken into sections called contexts. Contexts are named groups of extensions, which serve several purposes. 1. Contexts keep different parts of the dialplan from interacting with one another. 2. An extension that is defined in one context is completely isolated from extensions in any other context, unless interaction is specifically…
    Tags: context, asterisk
  • 39
    Welcome to the Asterisk Knowledge Base and Tutorial
    Tags: asterisk
  • 36
    Create mysql user id after logging through root user. mysql -u root -p yourpasswordforroot CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass'; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount*. TO 'monty'@'localhost'; FLUSH PRIVILEGES;  
    Tags: asterisk

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: