Asterisk AGI: How to get or set the value of a global variable?

不羁的心 提交于 2019-12-06 06:16:01

I found a workaround to make it work.

First, the global variable must not be declared in the dial plan under the [globals] section. And, it seems you cannot set a global variable from within an AGI script. However, you can set a channel variable (local to the current channel). So to set a global variable from an AGI script, you first set the value to a channel variable and when you return from the script into the dial plan, you retrieve the value of the channel variable and assign it to a global variable. Basically, it seems you can only assign global variables from within the dial plan, not from within an AGI script.

sample code:

//in dial plan

exten => _XXXX,n,AGI(myagiscript.php)
exten => _XXXX,n,Set(GLOBAL(someGlobalVariable)=${myLocalVar})


// in myagiscript.php

$agi->set_variable("myLocalVar", "value");

Asterisk wiki info about AGI says different things about global variables: ... Global variables are not passed to the AGI script in this manner. You must get them using the "get variable" AGI command...

and in other part: ...GET VARIABLE: Does not work with global variables. Does not work with some variables that are generated by modules....

For setting global value you can execute:

EXEC SetGlobalVar <var_name>=<value>

For getting I thing that get_variable should work but there was bug in Asterisk: https://issues.asterisk.org/view.php?id=7609

This bug was in Asterisk 1.2.20, what version of Asterisk do you use?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!