How can I pass variable from asterisk dialplan to AGI?

My goal is that when I need to create a new password for my site, I can also create it on my phone number. And for this, I have to pass the variable from the dial plan to an agi script, but it just doesn’t work. This is my configuration:

exten => 1234,1,Answer
exten => 1234,n,Read(digit)
exten => 1234,n,System(/etc/asterisk/agi.php,${digit})
exten => 1234,n,NoOp(digit is ${digit});
exten => 1234,n,Hangup()

Can someone tell me what I messed up?

Being called agi doesn’t make it AGI. This is not an AGI script.

I suspect the comma and the digit will be assumed to be part of the file name of the script, as the shell needs white space as a delimiter.

you can do like this:

exten => _X.,1,Set(Msg=Hello)
same => n,Agi(test.agi,${Msg})

Thanks for the answers! I will take action! If I succeed, I will write🙂

system() != agi()

The system() application executes a shell command and returns APPERROR, FAILURE, or SUCCESS. You can pass command line arguments, but you can’t set channel variables or interact with Asterisk.

Thus, it is best used for simple tasks like creating a directory (‘mkdir’) or logging a message (‘logger’).

The agi() application allows you to interact with Asterisk. You can execute any AGI command including ‘exec’ which allows you to execute any dialplan application.

An AGI can be as simple as playing a file or as complex as a complete application including database access and calling remote APIs (eg, TTS or STT).

A couple of (my personal) suggestions:

  1. Write your AGI in a language you are familiar with.
  2. Use an established library for the language of your choice. Libraries are available for C, Go, the ‘P’ languages, and more.
  3. Log stuff using syslog().
  4. Use a signal handler to intercept a caller hangup.
  5. Use ‘getopt_long’ to parse command line arguments.

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