Call-global variables that can be modified

Of course, I read this question, but I am not quite happy with its answer.

So, I want to go something deeper into it: How can I make a variable which is

  • visible throughout the entire call
  • and its value can be changed throughout the entire call. This means, that subsequently opened channels also see exactly this variable and also assign to this variable. No copy of the variable should be created.

What I already tried: Among others the double-underscore prefix notation. It did not help. The hangup extension of the local channel always sees the value as defined in the callfile.

I think it’s impossible to do it using the “normal” variables in asterisk, even with double-underscore…
What you probably need is an AGI or something to access files in your system, and manipulate the variables inside these files or inside a database.
One thing never changes during a call: the linkedid, so I think that’s a starting point for you.

I’m pretty sure you can construct calls where linkedid changes.

I think I’d try to use the ASTDB for this, Create a key/value pair at the start of the call and use it throughout the call, in your hangup handler you can delete the database entry when you are done with the call.

Thanks for the great tip using a simple database. For the time being, I handled this by a PHP programm writing to a self-made delivery notification database (an sqlite3 database). This is more or less the same, just that I do everything at the end of a call. Each call is given a unique id generated with uniqid() in the callfile. By using this unique id, I determine if the call already has a delivery notification. If it has one, and the new one arriving is “Successful” while the first one was “Failed”, then the entry is overwritten. (This can happen because the order of the hangup extension and the hangup subroutine of the Dial application is undetermined.) If the first call to the PHP program says “Successful”, and the second one “Failed”, then the second call simply does nothing.

Note that this PHP program is not an AGI script, it is just invoked by the System application with some command line parameters parsed by getopt().

1 Like