Variable like ${MACRO_EXTEN} in the subroutine

Colleagues, please tell me the answer to the my question!

If I write a macro for the dialplan, then “s” is set as exten, however, the variable ${MACRO_EXTEN} is available in the macro, and it contains the real exten from the context that called the macro.
Sometimes it is very necessary.

And if I write not a macro, but a subroutine, is there a similar variable?

Thank you in advance for your reply,
Ogogon.

Macro set some channels variables like MACRO_EXTEN,Gosub doesnt have a similar variable or at least I havent fund it on the documenation but you can use argument to save that variable
same => n,Gosub(it-gosub,s,1(${EXTEN}))

The tactic suggested in sample configuration is use GOSUB(named-priority), so that the extension remains unchanged.

Macro need s extension but gosub not so you can use the same extension

That is how I do it. However, it seems to me that ${MACRO_EXTEN} was a good, correct idea.
It is very strange that in routines there is no such functionality.

Please explain this in more detail. Unfortunately, I did not understand what you mean.

https://github.com/asterisk/asterisk/blob/master/configs/samples/extensions.conf.sample (for example line 575).

When you call a Marco() you do Marco(test,arg1,arg2) which will execute [macro-test] (as macro’s need the marco- prefix in the context name). Which means a Macro() requires the use of the ‘s’ extension in its dialplan.

When you call a GoSub you so GoSub(context,exten,priority(arg1, arg2). Just like you would with a GoTo statement except with the args option. So now you can do GoSub(dial,${EXTEN},1(arg1)) which means that it will exten the [dial] context and look for a match against ${EXTEN}. So it would be like:

[dial]
exten => _1NXXNXXXXXX,1,NoOp(Running Dial GoSub)
same => n,NoOp(Dialing ${EXTEN})
same => n,NoOp(ARG1 = ${ARG1} - Setting Timer)
same => n,NoOp(ARG2 = ${ARG2} - Setting Dial Options)
same => n,Dial(PJSIP/${EXTEN}@pstn-trunk,${ARG1},${ARG2})

vs

[macro-dial]
exten => s,1,NoOp(Running Dial GoSub)
same => n,NoOp(Dialing ${ARG1} - Dest to Dial)
same => n,NoOp(ARG1 = ${ARG2} - Setting Timer)
same => n,Dial(PJSIP/${ARG1}@pstn-trunk,${ARG2})
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.