I'm just trying to make a real simple Survey via php. Just want it to play the Question Files, wait for a response, save the response into the correct variable and then email it all. I have no issue playing the audio or emailing. But I can't get it to wait for digits or to properly capture those digits into the variables. I know the code is technically right since the emails have this in place of what Q1 should be "200 result=35 endpos=2400" instead of whatever digit I pressed during testing. Anyway my questions are A. How to have it play the whole audio file before it goes to the next command, without having to use the sleep function preferably. B. How to make it actually wait for digits C. How to get it to actually capture the digits (I think it would if it wasn't streaming thru the whole file without waiting for a response.) I'm just trying to capture digits 1-9 nothing fancy. #!/usr/bin/php -q <?php // Get AGI vars from * $agivars = array(); while (!feof(STDIN)) { $agivar = trim(fgets(STDIN)); if ($agivar === '') { break; } $agivar = explode(':', $agivar); $agivars[$agivar[0]] = trim($agivar[1]); } extract($agivars); // Variable Declarations $agi_uniqueid; $agi_callerid; $agi_calleridname; $agi_extension; $agi_uniqueid; $UNIQUEID = $agi_uniqueid; $CALLERID = $agi_callerid; $CallerName = $agi_calleridname; $EXTEN = $agi_extension; $Q1 = "Did Not Answer"; $Q2 = "Did Not Answer"; $Q3 = "Did Not Answer"; $Q4 = "Did Not Answer"; $Q5 = "Did Not Answer"; // Q1 fwrite(STDOUT, "STREAM FILE /var/lib/asterisk/sounds/1 ###\n"); fwrite(STDOUT, "wait for digit 10\n"); $Q1 = fgets(STDIN); // This section is where the email would be generated, but since that section works. No point making this any longer than need be. ?> James Shigley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20090504/92fe4d3e/attachment.htm
Just my .02. In my asterisk (1.4.21.2 using Polycom phones), The read in AGI doesn't work as expected. This is a simple thing to do in a dialplan and pass to php for the "lifting". Here's what I would do: exten => s,1(readq1),Read(digitq1,record/q1,16,skip,1,10]) exten => s,n,Gotoif($["${LEN(${digitacc})}" < "1"]?readq1) exten => s,n,AGI(checkdigit.php|${digitq1}) Not the answer you want and I'm sure someone will give you the correct answer if I'm wrong. _____ From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of James A. Shigley Sent: Monday, May 04, 2009 3:17 PM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: [asterisk-users] AGI PHP I'm just trying to make a real simple Survey via php. Just want it to play the Question Files, wait for a response, save the response into the correct variable and then email it all. I have no issue playing the audio or emailing. But I can't get it to wait for digits or to properly capture those digits into the variables. I know the code is technically right since the emails have this in place of what Q1 should be "200 result=35 endpos=2400" instead of whatever digit I pressed during testing. Anyway my questions are A. How to have it play the whole audio file before it goes to the next command, without having to use the sleep function preferably. B. How to make it actually wait for digits C. How to get it to actually capture the digits (I think it would if it wasn't streaming thru the whole file without waiting for a response.) I'm just trying to capture digits 1-9 nothing fancy. #!/usr/bin/php -q <?php // Get AGI vars from * $agivars = array(); while (!feof(STDIN)) { $agivar = trim(fgets(STDIN)); if ($agivar === '') { break; } $agivar = explode(':', $agivar); $agivars[$agivar[0]] = trim($agivar[1]); } extract($agivars); // Variable Declarations $agi_uniqueid; $agi_callerid; $agi_calleridname; $agi_extension; $agi_uniqueid; $UNIQUEID = $agi_uniqueid; $CALLERID = $agi_callerid; $CallerName = $agi_calleridname; $EXTEN = $agi_extension; $Q1 = "Did Not Answer"; $Q2 = "Did Not Answer"; $Q3 = "Did Not Answer"; $Q4 = "Did Not Answer"; $Q5 = "Did Not Answer"; // Q1 fwrite(STDOUT, "STREAM FILE /var/lib/asterisk/sounds/1 ###\n"); fwrite(STDOUT, "wait for digit 10\n"); $Q1 = fgets(STDIN); // This section is where the email would be generated, but since that section works. No point making this any longer than need be. ?> James Shigley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20090504/ee4131ae/attachment-0001.htm
On Mon, 4 May 2009, James A. Shigley wrote:> I'm just trying to make a real simple Survey via php. Just want it to > play the Question Files, wait for a response, save the response into the > correct variable and then email it all.If it's "real simple," maybe AGI is overkill. Any particular reason you can't do it in the dialplan?> I have no issue playing the audio or emailing. But I can't get it to > wait for digits or to properly capture those digits into the variables. > I know the code is technically right since the emails have this in place > of what Q1 should be "200 result=35 endpos=2400" instead of whatever > digit I pressed during testing.The code is not "technically right" since you don't understand the AGI protocol. See your code snippet below.> A. How to have it play the whole audio file before it goes to the next > command, without having to use the sleep function preferably.Use "stream file" with the appropriate escape digits.> B. How to make it actually wait for digitsUse "wait for digits" with the appropriate timeout. Accumulate digits for the desired effect.> C. How to get it to actually capture the digits (I think it would if it > wasn't streaming thru the whole file without waiting for a response.)An alternative is to use the background, playback, and read dialplan applications from your AGI.> // Q1 > fwrite(STDOUT, "STREAM FILE /var/lib/asterisk/sounds/1 ###\n"); > fwrite(STDOUT, "wait for digit 10\n");You don't understand the AGI protocol. For every request (the bit you send to Asterisk) you need to read the response (the bit Asterisk sends to you). Issuing 2 requests breaks the protocol. Please use an established library to handle all the little details of AGI for you. You will live longer :) Using an established library will take care of all these seemingly insignificant details and save you a lot of time. Thanks in advance, ------------------------------------------------------------------------ Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000
On 04/05/09 21:17, James A. Shigley wrote:> I?m just trying to make a real simple Survey via php. Just want it to > play the Question Files, wait for a response, save the response into the > correct variable and then email it all.Packt sent me a book to review recently: Asterisk AGI Programming. My write up is here (http://www.theopensourcerer.com/2009/04/16/asterisk-agi-programming-with-packt/) if you are interested, it might be a big help depending on your time-scales etc. Al PS - Disclaimer: Packt sent me this book for free and under no obligation. The review is genuine and unbiased. We are in Packt's affiliate scheme too, so we do get a few cents if you decide to buy the book via a link on my blog.