Chris Bagnall
2012-Feb-22 14:40 UTC
[asterisk-users] AGI: blocking script until playback complete
Greetings list, I've done AGI scripting before, but in the past I've always wanted control to be returned to the dialplan as soon as possible. However, today I have a scenario where I want the script to remain running during the playback of a file so that I can read DTMF at the end of playback. However, doing this: GET DATA en_welcome 5000 6 Results (correctly) in the following in the asterisk console: -- <SIP/a.b.c.d-dc027b50> Playing 'en_welcome' (language 'en') But the AGI continues to run on after this point, not waiting for either the sound file to be played, nor for the expected 6 DTMF digits. Adding a simple 10 second sleep/wait to the AGI allows the sound file to be successfully played back. I'm sure I must be missing something very obvious, buy my google-fu is failing me this afternoon. Suggestions gratefully received :-) Thanks in advance. Kind regards, Chris -- This email is made from 100% recycled electrons
Zohair Raza
2012-Feb-22 14:50 UTC
[asterisk-users] AGI: blocking script until playback complete
Try passing escape character GET DATA $filename $timeout $max_digits $escape_character Regards, Zohair Raza On Wed, Feb 22, 2012 at 6:40 PM, Chris Bagnall <asterisk at lists.minotaur.cc>wrote:> Greetings list, > > I've done AGI scripting before, but in the past I've always wanted control > to be returned to the dialplan as soon as possible. > > However, today I have a scenario where I want the script to remain running > during the playback of a file so that I can read DTMF at the end of > playback. However, doing this: > > GET DATA en_welcome 5000 6 > > Results (correctly) in the following in the asterisk console: > -- <SIP/a.b.c.d-dc027b50> Playing 'en_welcome' (language 'en') > > But the AGI continues to run on after this point, not waiting for either > the sound file to be played, nor for the expected 6 DTMF digits. > > Adding a simple 10 second sleep/wait to the AGI allows the sound file to > be successfully played back. > > I'm sure I must be missing something very obvious, buy my google-fu is > failing me this afternoon. > > Suggestions gratefully received :-) > > Thanks in advance. > > Kind regards, > > Chris > -- > This email is made from 100% recycled electrons > > -- > ______________________________**______________________________**_________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > New to Asterisk? Join us for a live introductory webinar every Thurs: > http://www.asterisk.org/hello > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/**mailman/listinfo/asterisk-**users<http://lists.digium.com/mailman/listinfo/asterisk-users> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20120222/2a3d950e/attachment.htm>
Chris Bagnall
2012-Feb-22 15:20 UTC
[asterisk-users] AGI: blocking script until playback complete
On 22/2/12 2:50 pm, Zohair Raza wrote:> Try passing escape character > GET DATA $filename $timeout $max_digits $escape_characterNot sure I follow - according to the docs, there is no parameter $escape_character The problem seems to be that GET DATA returns control to the script before the audio file has even played, let alone any DTMF tones have been entered. I would have expected script execution to be blocked until the result from GET DATA was available. Kind regards, Chris -- This email is made from 100% recycled electrons
Eric Wieling
2012-Feb-22 15:22 UTC
[asterisk-users] AGI: blocking script until playback complete
Are you reading STDIN to initialize your AGI? If not Asterisk may ignore your AGI commands. I recommend using one of the many AGI libs out there. -----Original Message----- From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Chris Bagnall Sent: Wednesday, February 22, 2012 10:20 AM To: asterisk-users at lists.digium.com Subject: Re: [asterisk-users] AGI: blocking script until playback complete On 22/2/12 2:50 pm, Zohair Raza wrote:> Try passing escape character > GET DATA $filename $timeout $max_digits $escape_characterNot sure I follow - according to the docs, there is no parameter $escape_character The problem seems to be that GET DATA returns control to the script before the audio file has even played, let alone any DTMF tones have been entered. I would have expected script execution to be blocked until the result from GET DATA was available. Kind regards, Chris -- This email is made from 100% recycled electrons -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Ron Bergin
2012-Feb-22 15:39 UTC
[asterisk-users] AGI: blocking script until playback complete
Chris Bagnall wrote:> Greetings list, > > I've done AGI scripting before, but in the past I've always wanted > control to be returned to the dialplan as soon as possible. > > However, today I have a scenario where I want the script to remain > running during the playback of a file so that I can read DTMF at the end > of playback. However, doing this: > > GET DATA en_welcome 5000 6 > > Results (correctly) in the following in the asterisk console: > -- <SIP/a.b.c.d-dc027b50> Playing 'en_welcome' (language 'en') > > But the AGI continues to run on after this point, not waiting for either > the sound file to be played, nor for the expected 6 DTMF digits. > > Adding a simple 10 second sleep/wait to the AGI allows the sound file to > be successfully played back. > > I'm sure I must be missing something very obvious, buy my google-fu is > failing me this afternoon. > > Suggestions gratefully received :-) > > Thanks in advance. > > Kind regards, > > Chris > --Have you tried increasing the timeout value in the command? To me, it appears to be too short. Try setting it to 50000. -- Ron Bergin
Steve Edwards
2012-Feb-22 21:13 UTC
[asterisk-users] AGI: blocking script until playback complete
On Wed, 22 Feb 2012, Chris Bagnall wrote:> However, today I have a scenario where I want the script to remain > running during the playback of a file so that I can read DTMF at the end > of playback.If by 'remain running' you mean 'do other stuff while the file is playing' you can stream the file in a separate thread while continuing with the 'mainline' code. If you mean your script is returning to the dialplan before the file is finished playing, you're doing something wrong.> However, doing this: > > GET DATA en_welcome 5000 6 > > Results (correctly) in the following in the asterisk console: > -- <SIP/a.b.c.d-dc027b50> Playing 'en_welcome' (language 'en') > > But the AGI continues to run on after this point, not waiting for either > the sound file to be played, nor for the expected 6 DTMF digits. > > Adding a simple 10 second sleep/wait to the AGI allows the sound file to > be successfully played back.Sure sounds like you are doing something wrong. Anytime a 'sleep' helps, something is definitely wrong. Most AGI 'weirdness' can be traced to violating the AGI protocol. These are the most common mistakes: 0) Not using an established library. Nobody gets it right the first time :) 1) Not reading the AGI environment from STDIN before issuing any AGI requests. 2) Forgetting that every request must be followed by reading the response. 3) Doing any I/O on STDIN or STDOUT. These channels are connected to Asterisk, not any console. Don't even think about popping in a quick 'debugging printf.' Looking over my own AGI code, I don't see any examples where I used GET DATA. I tend to use STREAM FILE and WAIT FOR DIGIT. I'm a 1.2 Luddite, so any bugs I've been exposed to may have been fixed by now. -- Thanks in advance, ------------------------------------------------------------------------- Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000