Reputation: 11
Fellow stackoverflowers:
I come here bearing a question that I haven't been able to solve on my own so far.
I want to be able to pass the data from an array to an AGI script in my Asterisk PBX's dialplan that's formatted in the following way:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param1=value1¶m2=value2...¶mN=valueN)
But one of the parameters has to receive the array data as if it was an URL parameter in a CGI script, like:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=value1,value2,value3...,valueN)
I know that AGI scripts are able to receive arrays as parameters, but the available documentation for AGI scripts in URL form does not say anything about how to receive array data as a script parameter; which is why I am posting this question here.
I have experimented (with unsuccessful results) passing the data in the following ways:
Comma-separated:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1,array_value2...,array_valueN)
Pipe-seperated:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1|array_value2...|array_valueN)
Semicolon-separated:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1;array_value2...;array_valueN)
But so far, I have only succeeded passing the array data the following way:
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1¶m_array=array_value2...¶m_array=array_valueN)
From what I've read, this is not the correct way to pass parameters to a URL, which is the way that I'm using to pass the data to my AGI script.
I'd greatly appreciate if anyone could shed a light in this matter, because I really don't want to have to pass each array item individually like I've been doing so far.
Upvotes: 1
Views: 2592
Reputation: 72
i would use quotes and split by comma the param_array
in the backed
exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array="a=1,b=2,c=3,d=4")
Upvotes: 1
Reputation: 121
In asterisk:
exten => s,n,Read(ZIPCODE,,8,3) ;ZIPCODE is my variable
exten => s,n,AGI(query-database.php|${ZIPCODE})
In PHP script query-database.php:
$zipcode = $argv[1]; Get the value of first var.
Upvotes: 1
Reputation: 98921
Not exactly the correct answer and also late, but the way I send and receive variables from agi
scripts using python
is the following:
Context:
[agi_demo]
exten => s,1,NoOp()
exten => s,n,AGI(agi://127.0.0.1:4573/demo2,1,2,3,4,5) ; send args 1 2 3 4 5 to demo2
exten => s,n,Verbose(OK = ${ok}) ; receive variable 'ok' from agi
exten => s,n,Hangup()
Debug Log:
-- Executing [s@agi_demo:2] AGI("SIP/trunk-00000016", "agi://127.0.0.1:4573/demo2,1,2,3,4,5") in new stack
-- <SIP/trunk-00000016> Playing 'agi_demo/i_just_called.slin' (escape_digits=12)
-- <SIP/trunk-00000016>AGI Script agi://127.0.0.1:4573/demo2 completed, returning 0
-- Executing [s@agi_demo:3] Verbose("SIP/trunk-00000016", "OK = AGI Rocks") in new stack
OK = AGI Ricks
-- Executing [s@agi_demo:4] Hangup("SIP/trunk-00000016", "") in new stack
Notes:
Start the fast agi server by issuing: python3 fast_agi_server.py
, it
will start listening on 127.0.0.1:4573
My sound files are located on a directory with the same name as the
context
and formatted as WAV PCM 8Khz 16Bits
, i.e:
/var/lib/asterisk/sounds/agi_demo/i_just_called
Server source code fast_agi_server.py from pystrix egg.
To send a variable from AGI
using pystrix
use the SetVariable
method:
agi.execute(pystrix.agi.core.SetVariable("ok", "AGI Rocks"))
Upvotes: 1