exten => 1000,1,Dial(${MILES},${DELAYTIME})As the book points out, this is fine for small implementations of *, but as a system scales this becomes massively inefficient. I followed the book example to turn this into a macro and condense everything down to one line outside the macro's definition.
exten => 1000,n,GoToIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => 1000,n(unavail),VoiceMail(1000@default,u)
exten => 1000,n,Hangup()
exten => 1000,n(busy),VoiceMail(1000@default,b)
exten => 1000,n,Hangup()
Macros are created in a pseudo-context prefaced with "macro-" ; I used
[macro-voicemail]
It also differentiates from pure contexts because each step uses the "s" extension. * has some handy built-in variables, including one to call the original extension ${MACRO_EXTEN}. Thus, our macro becomes
[macro-voicemail]This is why I had the mailbox extensions the same as the SIP extensions.
exten => s,1,Dial(${MILES},${DELAYTIME})
exten => s,n,GoToIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => s,n(unavail),VoiceMail(${MACRO_EXTEN}@default,u)
exten => s,n,Hangup()
exten => s,n(busy),VoiceMail(${MACRO_EXTEN}@default,b)
exten => s,n,Hangup()
The last thing to do was strip the last unique variable in the macro and add it back in as an argument. Since this happened to be my name, we can just put that in as the "n"th argument using the ${ARG n} variable built into the Macro() application. The macro becomes:
[macro-voicemail]And now instead of the messy, 6-line statement in the [internal] context in the dialplan we started out with, we can just write
exten => s,1,Dial(${ARG1},${DELAYTIME})
exten => s,n,GoToIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
exten => s,n(unavail),VoiceMail(${MACRO_EXTEN}@default,u)
exten => s,n,Hangup()
exten => s,n(busy),VoiceMail(${MACRO_EXTEN}@default,b)
exten => s,n,Hangup()
exten => 1000,1,Macro(voicemail,${MILES})Here you can see where the ${ARG1} variable gets its value (the first argument after "voicemail" in the Macro application).
