EVAL_EXTEN(priority[,context,extensions])
The EVAL_EXTEN function looks up a dialplan entry by context,extension,priority, evaluates the contents of a Return statement to resolve any variable or function references, and returns the result as a string.
You can use this function to create simple user-defined lookup tables or user-defined functions.
[call-types]
exten => _1NNN,1,Return(internal)
exten => _NXXNXXXXXX,1,Return(external)
[udf]
exten => calleridlen,1,Return(${LEN(${CALLERID(num)})})
[default]
exten => _X!,1,Verbose(Call type ${EVAL_EXTEN(call-types,${EXTEN},1)} - ${EVAL_EXTEN(udf,calleridlen,1)})
Any variables in the evaluated data will be resolved in the context of that extension. For example, ${EXTEN} would refer to the EVAL_EXTEN extension, not the extension in the context invoking the function. This behavior is similar to other applications, e.g. Gosub.
same => n,Read(input,${EVAL_EXTEN(prompts,${CALLERID(num)},1)})
[prompts]
exten => _X!,1,Return(default)
exten => _20X,1,Return(welcome)
exten => _2XX,1,Return(${DB(promptsettings/${EXTEN})})
exten => _3XX,1,Return(${ODBC_MYFUNC(${EXTEN})})
Extensions on which EVAL_EXTEN is invoked are not different from other extensions. However, the application at that extension is not executed. Only the application data is parsed and evaluated.
A limitation of this function is that the application at the specified extension isn't actually executed, and thus unlike a Gosub, you can't pass arguments in the EVAL_EXTEN function.
If you need the ability to evaluate more complex logic that cannot be done purely using functions, see EVAL_SUB.
contextextensionspriorityrequired
User Notes
Know a tip or gotcha for this topic? Share it below and help others.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.