[Asterisk-Users] AbsoluteTimeout Inside A Macro

Christopher L. Wade clwade at sparco.com
Wed Aug 11 06:45:59 MST 2004


Mike Coakley wrote:
> Chris,
> 
> Actually it is a documented feature of Macro. Macro only executes 
> extension "s" there are no other extensions in the macro context. I ran 
> into this while working through building our dial plan. It was driving 
> me nutz. (But the WIKI rescued me.) What I had to do is use the Macro to 
> setup the call as needed and then Goto a context that had all the 
> extensions I needed.
> 
> For a complete example:
> 
> I wanted to be able to call an station and if that station didn't answer 
> I wanted to present the user with a menu that they could press #1 to 
> leave a voicemail, #2 to try again, #4 to go to the main menu, #8 to 
> call the group/department the station belongs to, #9 to go to the 
> group/department directory or #0 to go to operator. Here is what I had 
> to do BECAUSE Macro can only execute the "s" extension.
> 
> [macro-stationcall]
> exten => s,1,SetVar(STATION_EXT=${ARG1})
> exten => s,2,SetVar(STATION_MAILBOX=${ARG2})
> exten => s,3,SetVar(STATION_GROUP=${ARG3})
> exten => s,4,SetVar(STATION_MENU=${ARG4})
> exten => s,5,SetVar(STATION_DIRECTORY=${ARG5})
> exten => s,6,Goto(stationcall_menu,s,1)
> 
> [stationcall_menu]
> exten => s,1,Answer
> exten => s,2,Wait(1)
> exten => s,3,DigitTimeout(5)
> exten => s,4,ResponseTimeout(5)
> exten => s,5,AbsoluteTimeout(30)
> exten => s,6,Dial(${STATION_EXT})
> exten => s,7,Background(${STATION_MENU})
> exten => 1,1,Voicemail(u${STATION_MAILBOX})
> exten => 2,1,Goto(s,6)
> exten => 4,1,Goto(main_menu,s,1)
> exten => 8,1,Macro(groupcall,${STATION_GROU})
> exten => 9,1,Directory(${STATION_DIRECTORY})
> exten => 0,1,Goto(operator,s,1)
> exten => i,1,Playback(invalid)
> exten => i,2,Goto(s,7)
> exten => t,1,Goto(s,7)
> exten => T,1,Hangup
> 
> I simplified this example (trust me) but I hope you get the idea. Also 
> realize that SetVar puts a variable in the scope of the current call.
> 
> Hope this helps.
> 
> Mike
> 
> On Aug 10, 2004, at 5:59 PM, Christopher L. Wade wrote:
> 
>> Okay, time for an update.
>>
>> I posted this as a bug.  Very quickly got informed that it is not a 
>> bug, but instead, an undocumented 'feature'.
>>
>> AbsoluteTimeout is treated as an *exception* (ie it looks like a 
>> hangup) by most applications, including Macro, which makes most 
>> applications exit.
>>
>> This being said, this is why a 'T' extension in the calling context 
>> would run, but not a 'T' extension inside the macro.  Once macro 
>> exists, the macro context no longer exists, and the 'T' extension 
>> inside the macro becomes 'inaccessible'.
>>
>> Oh well, I guess I'll have to implement my logic without macros. 
>> Hopefully variables aren't screwed up by AbsoluteTimeout.
>>
>> Thanks,
>> Chris
>>

Well, according to the wiki - see the macro-stdexten, 's' is not the 
only extension that can be used within a macro.  The stdexten macro uses 
Goto and ${DIALSTATUS} to branch to s-${DIALSTATUS} (you can change this 
to just ${DIALSTATUS} if you want, it still works, but pattern matching 
that to group unhandled values isn't as clean and recognizable as 's-.' is.

Also, the following example shows you can branch as much as you like 
inside a macro:

[macro-testM]
exten => s,1,Goto(test,1)
exten => test,1,NoOp(${CONTEXT},${MACRO_CONTEXT})

This macro, when run, will print the following assuming you start 
asterisk CLI with verbosity high enough and debug on (I always start it 
this way).

Executing NoOp("Zap/1-1", "macro-testM|internal") in new stack

So, again, the wiki is "wrong".  Well, not quite, the wiki is right in 
that you *must* have the 's' extension and that this is where your macro 
execution will *always* start.  But, once inside the macro, you can do 
just about anything you want, except use exceptions.

Thanks,
Chris




More information about the asterisk-users mailing list