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))

 

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.

One thought on “Macro : Macro in Asterisk

  • February 5, 2016 at 9:36 am
    Permalink

    After exploring a few of the blog posts on your web page, I really appreciate your technique
    of blogging. I book marked it to my bookmark website list and will be checking back soon. Please
    check out my web site too and let me know what you think.

Leave a Reply