AGI: How To Break Out Of AGI When Stream_file Escape_digits Are Detected In Middle Of Long Sequence Of Files?

Home » Asterisk Users » AGI: How To Break Out Of AGI When Stream_file Escape_digits Are Detected In Middle Of Long Sequence Of Files?
Asterisk Users 2 Comments

For reasons best known to myself, I call a python agi (PYST2 – love it!) which streams a series of very short files in quick succession.

Like this:

escape_digits = str(“0”)
agi.stream_file(promptFile,escape_digits)

and this is what I see on the AGI debug:

AGI Tx >> 200 result=0 endposg84
AGI Rx << STREAM FILE /home/DefaultPrompts/en_GB/female/wx/low "0" 0 -- Playing
‘/home/DefaultPrompts/en_GB/female/wx/low.alaw’ (escape_digits=0)
(sample_offset 0) (language ‘en_GB’)
AGI Tx >> 200 resultH endpos40

The FIRST line is a file that finished normally, with result=0, the LAST line is a file that was interrupted, and receives resultH from asterisk.

Yes, zero stops the file playing, but it just goes onto the next file.

So, how do I get that variable? It doesn’t become available in python, and trying to get it via either

agi.env[result’]
agi.get_variable(‘result’)

just makes python choke and the AGI quits. That would be fine if it was a result of result being 48!

I feel like I’m going slightly bonkers here because it’s something so obvious, and yet I’ve googled so hard over this!

Thanks.

2 thoughts on - AGI: How To Break Out Of AGI When Stream_file Escape_digits Are Detected In Middle Of Long Sequence Of Files?

  • Hello,

    as the docs on stream_file() mention it returns the digit if one was pressed. So you might want to try something like:

    pressed_digit = agi.stream_file(promptFile,escape_digits)

    in you case the raw value 48 is converted to its ascii equivalent so pressed_digit will have the value 0

  • Arrrgh! You are correct, of course. I hadn’t realised you could do it that way – I was assuming it was a variable that was returned to the dialplan/channel.

    Some of the finer points of AGI are still a slight mystery to me!

    Thank you very much – working perfectly now, with your help and the following code. Thank you again.

    escape_digits = str(“*”)
    pressed_digit=agi.stream_file(promptFile,escape_digits)
    if pressed_digit == “*”:
    sys.exit(0)