blocking script until playback complete
Tags: asterisk, CONTROL, dtmf, Greetings, playback, scenario
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:
Zohair Raza said:
Feb 22, 12 at 10:50 amTry 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
wrote:
"Danny Nicholas" said:
Feb 22, 12 at 10:55 amYou don’t state the Asterisk version you are running, but personal
experience tells me you’d better invest in some Rogaine if you’re depending
on the built-in stuff from AGI for DTMF input. I have personally wasted
weeks trying it.
[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Zohair Raza
Sent: Wednesday, February 22, 2012 8:50 AM
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
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:
Chris Bagnall said:
Feb 22, 12 at 11:13 amSorry, should have said, latest 1.4 release.
Care to elaborate a little on the issues you found when you tried it?
Chris Bagnall said:
Feb 22, 12 at 11:20 amNot 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.
Eric Wieling said:
Feb 22, 12 at 11:22 amAre 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.
Chris Bagnall said:
Feb 22, 12 at 12:21 pmThanks for the suggestion – I tried 50000, but no difference, it’s not
waiting at _all_ for the playback to complete.
Just for giggles, I tried exactly the same test on a 1.8 box I have for
testing, and the same problem occurs.
I’m sure I must be doing something wrong here
Steve Edwards said:
Feb 22, 12 at 5:13 pmIf 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.
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.
Steve Edwards said:
Feb 22, 12 at 5:25 pmWhy? Is this ‘extra’ parameter documented in your version of Asterisk?
Steve Edwards said:
Feb 22, 12 at 5:34 pmI’ve written complete ‘applications*’ as single AGIs so the combination of
STREAM FILE and WAIT FOR DIGIT works reliably for me.
*) voicemail, chat services, credit card processing, listen to stories,
blah, blah, blah.
Eric Wieling said:
Feb 22, 12 at 6:02 pmYes, but it doesn’t seem to indicate if the timeout is in seconds of milliseconds.
"Danny Nicholas" said:
Feb 22, 12 at 6:09 pmWhile it is never actually safe to assume anything about Asterisk, the
general setting for seconds is milliseconds.
Zohair Raza said:
Feb 23, 12 at 4:21 amStrange, it’s not there in wiki but phpagi is using this
* @link http://www.voip-info.org/wiki-get+data
* @param string $filename file to play. Do not include file extension.
* @param integer $timeout milliseconds
* @param integer $max_digits
* @param char $escape_character
* @return array, see evaluate for return information. ['result'] holds
the digits and ['data'] holds the timeout if present.
*
* This differs from other commands with return DTMF as numbers
representing ASCII characters.
*/
function get_data($filename, $timeout=NULL, $max_digits=NULL,
$escape_character=NULL)
{
return $this->evaluate(rtrim(“GET DATA $filename $timeout $max_digits
$escape_character”));
}
Regards,
Zohair Raza