Pass parameter to AGI na Queue

How to pass parameters to protocolo.agi script?


Note: I’m not using the asterisk.agi library in Python

You could just set the parameters you need, as channel variables, before adding the queue, then read them in the AGI script as any other channel variable.

Also checked the app_queue source, and it does not appear to have a way to parse command line arguments to the AGI script.

In Python how do I retrieve a variable from Asterisk?

You would write a GET VARIABLE request, on standard output, and read the response on standard input, according to the standard AGI protocol, having, of course, already read the initial information from AGI:

However, most people would use a class library, a partial list of which can be found here:

The order is like this for the variable ${EXTEN}?


I’m not sufficiently familiar with python to say for certain, but that looks plausible.

You will need to read and parse the response, and you will also have to have previously read out the initial AGI specific variables dump.

No clue with the library you use, I figured the available libraries all sucked too much when I had to make some AGI scripts, so I made my own.

But you basically write something like this in your dialplan, sometime before you call the AGI application

same => n,Set(Parameter1=Value1)
same => n,Set(Parameter2=Value2)

Then, in your AGI script, you write to standard output (stdout) the following:


Then parse the result from Asterisk, the result looks like

result=0 (Value1)

I don’t remember the full line, or if the success value is 0 or 1, but the value of the variable will always be in the ending parentheses.

The library you’re using, most likely has it’s own function to retrieve a channel variable, but you’ll have to look in the manual to figure it out.

I don’t think they are using any AGI library. What they are using looks like code to implement “write to standard output”.

You should use an established library for the language of your choice.

AGI is a simple protocol (request/response), but not following the protocol (like reading the AGI environment before any requests) can lead to failure when you least expect it. And nobody gets it right the first time.

Plus it’s easier, more robust, and more maintainable :slight_smile:

Also, you’ll learn that some ‘channel variables’ (like caller ID, channel, context, dnid, extension, language) are part of the AGI environment so you basically get them ‘for free.’

You’re apparently right… I missed a “not” in the “I’m NOT using” when I read it. :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.