How do I use Gosub in the extensions.ael?

Dear Asterisk users!

How do I use Gosub in extensions.ael?

Could you please provide an small example for me?

Many thanks,

Michael

Hello Michael.

Do you want to use GoSub, just like using Macro, in Dialplan AEL?

Att.
Delphini (Dell)

So Michael.
You can use GoSub, but you will always get this message.

[Jan 23 13:50:55] WARNING[10343]: ael/pval.c:2526 check_pval_item: Warning: file /etc/asterisk/extensions.ael, line 552-552: application call to Gosub affects flow of control, and needs to be re-written using AEL if, while, goto, etc. keywords instead!

I personally always use if and goto(); I do not use GoSub( ), due to the recommendation of the AEL syntax itself.

Note => goto, jump, and labels

Thank you very much,

yes it should be a replacement for macro, since that is deprecatet

greetings Michael

But if you want to validate, here’s a small example.

_X.    => Gosub(sub-trunk,${EXTEN},1(SIP,trunk,${EXTEN},dontcare,branch));
}

context sub-trunk {
_X. => {
	  Set(CDR(userfield)=${ARG5});
	  Gosub(sub-record-check,s,1(out,${EXTEN},${ARG4}));
      Dial(${ARG1}/${ARG2}/${ARG3},60,);
	  if ("${DIALSTATUS}" = "BUSY")
	  {
	  Noop(BUSY);
	  }
	  if ("${DIALSTATUS}" = "NOANSWER")
	  {
	  Noop(NOANSWER);
	  }
	  if ("${DIALSTATUS}" = "CHANUNAVAIL")
	  {
	  Noop(CHANUNAVAIL);
	  Dial(${ARG1}/${ARG2}2/${ARG3},60,);
	  }
	  if ("${DIALSTATUS}" = "CONGESTION")
	  {
	  Noop(CONGESTION);
	  Dial(${ARG1}/${ARG2}2/${ARG3},60,);
	  }
       }
 }

Yes, Macro( ) is deprecated… I’m using Asterisk Certified 18.9, but I don’t use GoSub( ).

A cordial hug
Att. Dell.

AEL Macro currently compiles to dialplan GoSub! (Macro was eliminated from under AEL’s hood during the original Macro deprecation attempt, or earlier, i.e. around Asterisk 1.8.)

Is AEL still used much? I noticed it being introduced, over a decade ago, when it seemed it was trying to offer a more readable/versatile alternative to extensions.conf. I expected it would take over from the latter if so, but that has never happened, and the old dialplan language seems just as dominant as ever.

I see there is an extensions.lua now, so it seems another attempt is being made to offer a more readable configuration language.

I have been contemplating clever tricks involving #exec and #include to do dynamic generation of configs, using any external language you like (e.g. Python). This also has the advantage of working across all the config files.

Not much, but it isn’t that broken, either. Observing it over a decade – AEL written back then still works! Since it is native to Asterisk, there’s fewer dependency issues than other languages. It is cleaner to read, in many cases, than CONF format dial plans; but it is harder to automatically generate AEL than CONF.

Per OP, you can use ampersand to prefix an AEL “macro”, which is a Gosub() under-the-hood as @david551 describes. See more details and examples in Asterisk wiki; however, you should gloss over the guts of the macro – in particular, the “switch” statement in below link is probably not the best choice to highlight, as the switch pattern matches are probably one of the more easily broken parts of AEL:

https://wiki.asterisk.org/wiki/display/AST/AEL+Macros

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