Passing values back to Asterisk dial plan
Asterisk doesn’t allow user to pass values from an AGI script directly back to the dial plan. However, there is a work around – instruct the AGI script to set a value to a variable and then print the SET VARIABLE statement to the standard output (STDOUT).
For example, assuming you want the variable to be named “ScriptResult” and the value to be assigned “100”, you should instruct the AGI script to print the following:
SET VARIABLE ScriptResult 100
How to do it with Perl and PHP?
Perl:
If you want to pass the value of variable “count” back to the dial plan, the line in the Perl script should look like:
print “SET VARIABLE ScriptResult $count”;
PHP:
echo “SET VARIABLE ScriptResult $count”;
You can then use the variable ScriptResult in the dialplan.
As long as you didn’t declare the variable as a global, it will be unique to the specific call and will “disappear” at the end of the call.