Run synchronous AGI

import sys
import requests
sys.stdout.write(‘EXEC Playback inicial_lig_gravada_ake \n’)

The AGI script is executing the requests before finishing the audio, I don’t want that.
Is it possible to execute the requests line only after I finish playing the Playback?

Don’t send requests blind. AGI scripts should read out the initial AGI parameters and should also read out every response, as it arrives.

There is actually a small risk of a deadlock if don’t do this, as it is possible for the responses to back up to the point where flow control stalls them, in which case the AGI application cannot read further requests. Also you can get broken pipe errors, if you don’t read out responses properly.


I’ll add stdin.readline().strip()
Is it possible to execute the requests line only after I finish playing the Playback?

You’re going down the wrong road.

You should not be ‘talking’ directly to Asterisk. You should use an established library.

AGI is a very simple protocol, but it’s easy to break.

Using the AGI exec command should only be used if a purpose specific command does not exist.

Based on the details at hand, ‘get data’ or ‘stream file’ would be the appropriate AGI command.

I’ve never written an AGI in Python, but for the most popular PHP library these would be the get_data or stream_file methods.

Personally, I write most of my AGIs in C using a library I wrote. I never even bothered to implement ‘get data’ in 20 years of use :slight_smile:

I suspect ‘stream file’ will be a good choice.

You could try my seaskirt module for Python. It offers both synchronous and asynchronous interfaces to AGI, and also FastAGI. And there is also “Async AGI”, which means you send AGI requests via AMI.

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