[Home]

Summary:ASTERISK-09561: Calling macros from Dial(), MACRO_RESULT is impossible to populate properly due to extension handling.
Reporter:Dayton Turner (dayton)Labels:
Date Opened:2007-05-31 16:16:23Date Closed:2011-06-07 14:08:04
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Applications/app_macro
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:If I call a macro from Dial(), for example:

Dial(Tech/number,20,M(coolmacro))

When the execution goes into macro-coolmacro, asterisk handles both dialed dtmf digits, as well as exten 'h' by exiting the macro and executing it in the context that called the Dial().  You can see another example of someone describing this behavior on the voip-info wiki here:

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

The relevant section of the page being:
"Note that 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. (The same appears to happen also with jumps to the 'h' extension: if a macro executes a Dial(), when the called party hangs up the control passes to the 'h' extension of the calling context. However, please note that 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.)"

Now, the way I am using the macro, is to do call screening. I need to set MACRO_RESULT to CONTINUE if the callee rejects the call (by hangup) or set it to nothing if 1 is pressed.

The real issue is that since Macro() is passing '1' or 'h' back to the calling context, it is now too late to set MACRO_RESULT as the macro has already been exited.

I have seen other people attempt this exact thing, and seem to have had success in the past. Maybe something changed in 1.2 that prevented this code from working?  A similar example can be found here:

http://www.voip-info.org/wiki/view/Asterisk+tips+findme

In the macro:
[macro-screen]
exten => s,1,Wait(1)
exten => s,n,Background(press-1-to-be-connected-to-the-caller)
exten => s,n,Set(TIMEOUT(response=5))
exten => 1,1,NoOp(Caller accepted) ; Do not set MACRO_RESULT to anything to connect the caller
exten => i,1,Set(MACRO_RESULT=CONTINUE)
exten => t,1,Set(MACRO_RESULT=CONTINUE)

This is the code I am using, and it is not working. (they used 'i' for hitting invalid DTMF here instead of my preferred 'hangup')
Comments:By: Tilghman Lesher (tilghman) 2007-05-31 18:08:24

You should try using the Read() application instead of implicitly waiting for DTMF.  The problem is not what you suspect; it's that when Macro runs out of priorities to execute, it immediately returns.

By: Tilghman Lesher (tilghman) 2007-06-01 08:23:43

I think I sufficiently explained this on IRC.