[asterisk-users] read digits from the user through php agi script

A J Stiles asterisk_list at earthshod.co.uk
Wed Sep 24 03:03:10 CDT 2014


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 .



More information about the asterisk-users mailing list