Dialplan functions are not a new concept. In Asterisk 1.2, they should be used where possible. Many applications that perform the same operation as a corresponding function will eventually be removed in favor of the function. Functions allow you to add more power to your expressions—you can think of them as being similar to operators, but more advanced. For example, dialplan functions allow you to calculate string lengths, dates and times, MD5 checksums, and so on, all from within a dialplan expression.
Dialplan functions have the following basic syntax:
Much like with variables, you reference a function’s name as above, but you reference a function’s value with the addition of a dollar sign, an opening curly brace, and a closing curly brace:
Functions can also encapsulate other functions, like so:
argument)})} ^ ^ ^ ^ ^^^^ 1 2 3 4 4321
As you’ve probably already figured out, you must be very careful about making sure you have matching parentheses and braces. In the above example, we have labeled the opening parentheses and curly braces with numbers and their corresponding closing counterparts with the same numbers.
Functions are often used in conjunction with the
Set() application to either get or set the
value of a variable. As a simple example, let’s look at the
LEN() function. This function calculates the string length of its argument. Let’s calculate ...