Brahim Abidar
2014-Sep-23 17:25 UTC
[asterisk-users] read digits from the user through php agi script
hi everyone, actually i want to release an IVR system using PHPAGI API , in this IVR i want to get value from the user. I already used get_data defined in phpagi but they are not able to get the value given by the user and store it in a php variable. i tested this : $result = $agi->get_data('beep', 3000, 20); $keys = $result['result']; but every time i found in $keys variable 0. please any help or suggestions thank you for spending your valuable time for me. -- *?l?ve Ing?nieur INE3 ? l'Institut National des Postes et T?l?communications * *INPT - Rabat - Maroc* *Responsable de la cellule Asterisk au **Club Electronique et Systemes Embarqu?s de l'INPT* *Membre du projet " ilearn", SIFE INPT* * Tel : +212642398782* * Skype : abidarbrahim* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20140923/dd4d056e/attachment.html>
Eric Wieling
2014-Sep-23 17:31 UTC
[asterisk-users] read digits from the user through php agi script
I?m not going to help you debug your code, but I wanted to post part of a function from one of our internal AGIs which reads auth codes using a simple IVR. The code is ugly but it might be helpful to you. This code is released to the public domain. // no pin provided, get pin from caller $agi->answer(); usleep(250000); $try = 1; $bad_pass = FALSE; $auth_start_time = microtime(TRUE); while ($try < 4) { if ($try == 1) { $agi->exec("Read", "pin,/igc/sounds/cc-bong,$pinset_len,,1,3"); } else { if ($pinset_len == 0) { $agi->exec("Read", "pin,please-enter-your&access-code&/igc/sounds/cc-bong,,,1,5"); } else { $agi->exec("Read", "pin,please-enter-your&digits/$pinset_len&digit&access-code&/igc/sounds/cc-bong,$pinset_len,,1,5"); } } $temp = $agi->get_variable("pin"); $pin = trim($temp["data"]); if ($pinset_verify == "1" && $pin != "") { $temp = array_search($pin, $pins); if ($temp !== FALSE) { $agi->set_variable("SM_START", $sm_start + (microtime(TRUE) - $auth_start_time)); $agi->exec("CELGenUserEvent", "\"SM,status => OK, cause =>000, detail => Verified PIN, pin => $pin\""); return array("status" => "OK", "cause" =>"000", "detail" => "Verified PIN", "pin" => $pin); } } else if ($pinset_verify != "1" && $pin != "") { $agi->set_variable("SM_START", $sm_start + (microtime(TRUE) - $auth_start_time)); $agi->exec("CELGenUserEvent", "\"SM,status => OK, cause =>000, detail => Unverified PIN, pin => $pin\""); return array("status" => "OK", "cause" =>"000", "detail" => "Unverified PIN", "pin" => $pin); } if ($try != "1") { $agi->exec("Playback", "bad&access-code"); } $try++; } $agi->set_variable("SM_START", $sm_start + (microtime(TRUE) - $auth_start_time)); $agi->exec("CELGenUserEvent", "\"SM,status => ERROR, cause =>851, detail => Verified PIN, pin => $pin\""); return array("status" => "ERROR", "cause" =>"851", "detail" => "Verified PIN", "pin" => $pin); } From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Brahim Abidar Sent: Tuesday, September 23, 2014 1:26 PM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: [asterisk-users] read digits from the user through php agi script hi everyone, actually i want to release an IVR system using PHPAGI API , in this IVR i want to get value from the user. I already used get_data defined in phpagi but they are not able to get the value given by the user and store it in a php variable. i tested this : $result = $agi->get_data('beep', 3000, 20); $keys = $result['result']; but every time i found in $keys variable 0. please any help or suggestions thank you for spending your valuable time for me. -- ?l?ve Ing?nieur INE3 ? l'Institut National des Postes et T?l?communications INPT - Rabat - Maroc Responsable de la cellule Asterisk au Club Electronique et Systemes Embarqu?s de l'INPT Membre du projet " ilearn", SIFE INPT Tel : +212642398782 Skype : abidarbrahim -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20140923/21878ace/attachment.html>
A J Stiles
2014-Sep-24 08:03 UTC
[asterisk-users] read digits from the user through php agi script
On Tuesday 23 Sep 2014, Brahim Abidar wrote:> hi everyone, > actually i want to release an IVR system using PHPAGI API , in this IVR i > want to get value from the user. > I already used get_data defined in phpagi but they are not able to get the > value given by the user and store it in a php variable. > i tested this : > $result = $agi->get_data('beep', 3000, 20); > $keys = $result['result']; > > but every time i found in $keys variable 0. > > please any help or suggestions > thank you for spending your valuable time for me.Why do you want to do this in an AGI? It's easy enough to do in the dialplan. Here's how I did it; you'll need to substitute your own sound bytes, obviously, but I've added comments showing what they say: [get_pin] exten => s,1,Set(pin=) exten => s,n,Set(PINLENGTH=4) ; "Enter your PIN. If you make a mistake, press STAR." exten => s,n(prompt),Background(ajs-enter_pin) ; Build up the PIN digit by digit. The WaitExten() will be cut short by any ; keystroke, so we can use a quite longish timeout. exten => s,n(nextdigit),WaitExten(30) ; "Sorry, I didn't get that." exten => s,n,Playback(ajs-sorry_didnt_get) exten => s,n,GoToIf($[${LEN(${pin})}<1]?prompt:saysofar) ; "The digits entered so far are:" exten => s,n(saysofar),Playback(ajs-digits_so_far) exten => s,n,SayDigits(${pin}) exten => s,n,Goto(nextdigit) ; This context needs to have a "h" extension; because we may well be ; placing a call from here, if the PIN was correct. exten => h,1,NoOp(Clearing up) ; ..... carry on tidying up after ourselves ; "PIN cleared. Start again from the beginning." exten => *,1,Playback(ajs-start_again) exten => *,2,GoTo(get_pin,s,1) exten => #,1,Hangup() exten => _X,1,Set(pin=${pin}${EXTEN:0:1}) exten => _X,n,NoOp(PIN so far is ${pin}) exten => _X,n,GoToIf($[${LEN(${pin})}>=${PINLENGTH}]?got_all:need_more) exten => _X,n(need_more),GoTo(get_pin,s,nextdigit) ; We have all 4 digits ..... exten => _X,n(got_all),NoOp(PIN is ${pin}) ; ..... and we continue from here with the PIN in ${pin} -- AJS Note: Originating address only accepts e-mail from list! If replying off- list, change address to asterisk1list at earthshod dot co dot uk .