1
votes

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&param2=value2...&paramN=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:

  1. Comma-separated:

    exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1,array_value2...,array_valueN)
    
  2. Pipe-seperated:

    exten => some_exten,priority,AGI(agi:hostname:port/agi_script.agi?param_array=array_value1|array_value2...|array_valueN)
    
  3. 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&param_array=array_value2...&param_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.

3
afaik asterisk supports only to write arrays as simple variables within the dialplan. I would therefore like to know which array do you have in the dialplan and where does it come from?pce
You can send any value to agi. If any of your form not work, you always can use BASE64 enconding and decode in your script.arheops
The array I have in my dialplan is a collection of separate variables. However, for the purpose of my AGI request, their values need to be all in a single array in the form of: param_array=variable1_value,variable2_value...,variableN_valueElbano Mibelli P.

3 Answers

1
votes

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.
1
votes

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") 
0
votes

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:

  1. Start the fast agi server by issuing: python3 fast_agi_server.py, it will start listening on 127.0.0.1:4573

  2. 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
    
  3. Server source code fast_agi_server.py from pystrix egg.

  4. To send a variable from AGI using pystrix use the SetVariable method:

    agi.execute(pystrix.agi.core.SetVariable("ok", "AGI Rocks"))