I have agi script and I want, when that agi file called (which written in python). I can fetch all asterisk’s variable inside that agi file. Like Extension, Caller ID, Channel, etc.
I have to log all this in one excel file so in future I can refer that for some purpose.
Those variables are already been passed to the AGI script. Look to the:
…
AGI Tx >> agi_channel: PJSIP/1011-00000001
…
Note: The Tx >> means a line sent by Asterisk to the AGI, and Rx << is from AGI to Asterisk.
You are using a library/SDK called “asterisk.agi”, you need to look to the documentation to know how to retrieve the variables that Asterisk always pass to an AGI at the beginning.
If you want to pass other variables (arguments) to an AGI you can do it this way, but using { } not ( ). Like this:
Do you have a specific list of variables or do you really mean ‘all?’
I don’t think there is a way to enumerate through ALL variables.
You can get the value of some variables from the AGI environment passed to your AGI, by asking Asterisk using the AGI commands ‘get variable’ and ‘get full variable,’ and by passing the value to the AGI() application.
Personally, I would retrieve these variables from the AGI environment and then overwrite if specified in the AGI() arguments.
Also, I would specify the AGI() arguments in ‘Unix command line long option’ format.
For example, instead of:
same = n,agi(example,T,F,1001,sedwards,N)
I would code it up like:
same = n,agi(example,--caller-id=sedwards,--debug,--extension=1001,--test,--upload)
and then parse the ‘command line’ using ‘getopt_long()’ in my AGI.
Although ‘wordy,’ this is ‘dead-obvious’ what each argument is used for and is ‘position independent’ so I never have to think 'hey, what was the 5th argument to that AGI I wrote x years ago and I can pass the arguments in whatever order (usually alphabetic) makes the most sense.