in the standard format:
;
[internal]
exten => s,1,Answer
exten => s,n,Background(someivr)
exten => s,n,Read(intgroup,,3)
exten => s,n,Goto(${intgroup},1)
exten => XXX,1,Dial(SIP/${EXTEN})
exten => XXX,n,HangUp
Here is how the same context looks in ael syntax:
context internal {
s=> {
Answer;
Background(someivr);
Read(intgroup,,3);
Goto(${intgroup},1);
}
XXX => {
Dial(SIP/${EXTEN});
HangUp;
}
}
So, the differences are clear. For me, one of the main advantages of ael is the readability of the configuration file: even in this small abstract example, it is evident that reading and understanding the configuration is easier. Although, I admit that this is subjective. The second thing that immediately catches the eye is the absence of priorities (s, n in the code above; however, as noted in the comments, priorities are not mandatory there either) in the dialplan description.
Why are they absent? Or rather, why do they exist in the standard dialplan description?
If you have not previously worked with Asterisk and its standard dialplan, you will be surprised to learn that it lacks loops and conditions. There is only a conditional jump (gotoif), which can theoretically be used to implement loops, but the convenience of this approach is highly questionable. Let us consider the simplest ael code that outputs true or false to the Asterisk console:
if(${var}=foo) {
NoOp(true);
}
else {
NoOp(false);
}
In the standard format, this condition would look like this:
exten=>1,1,GotoIf($[${var}=foo]?label1:label2)
exten=>1,n(label1),NoOp(true)
exten=>1,n,Goto(end_of_if)
exten=>1,n(label2),NoOp(false)
exten=>1,n(end_of_if),...
Not only do we lose readability, but we are also forced to either statically specify priorities everywhere (resulting in completely non-extensible code) or invent labels for every minor detail. Yes, ael also supports labels, but the need for them practically disappears because the syntax allows avoiding goto altogether.
s=> {
Answer;
somelabel:
HangUp;
}
In addition to conditional statements (if/else), ael also allows you to use the switch operator with familiar syntax:
_777X => {
switch (${EXTEN}) {
pattern N11:
NoOp(You called a N11 number-- ${EXTEN});
break;
case 7771:
NoOp(You called 7771!);
break;
case 7772:
NoOp(You called 7772!);
break;
case 7773:
NoOp(You called 7773!);
// fall thru-
default:
NoOp(In the default clause!);
};
