Read Digits From The User Through Php Agi Script

Home » Asterisk Users » Read Digits From The User Through Php Agi Script
Asterisk Users 3 Comments

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.

3 thoughts on - Read Digits From The User Through Php Agi Script

  • SeKAmW0gbm90IGdvaW5nIHRvIGhlbHAgeW91IGRlYnVnIHlvdXIgY29kZSwgYnV0IEkgd2FudGVk IHRvIHBvc3QgcGFydCBvZiBhIGZ1bmN0aW9uIGZyb20gb25lIG9mIG91ciBpbnRlcm5hbCBBR0lz IHdoaWNoIHJlYWRzIGF1dGggY29kZXMgdXNpbmcgYSBzaW1wbGUgSVZSLiAgVGhlIGNvZGUgaXMg dWdseSBidXQgaXQgbWlnaHQgYmUgaGVscGZ1bCB0byB5b3UuICAgVGhpcyBjb2RlIGlzIHJlbGVh c2VkIHRvIHRoZSBwdWJsaWMgZG9tYWluLg0KDQogICAgLy8gbm8gcGluIHByb3ZpZGVkLCBnZXQg cGluIGZyb20gY2FsbGVyDQogICAgJGFnaS0+YW5zd2VyKCk7DQogICAgdXNsZWVwKDI1MDAwMCk7
    DQoNCiAgICAkdHJ5ID0gMTsNCiAgICAkYmFkX3Bhc3MgPSBGQUxTRTsNCiAgICAkYXV0aF9zdGFy dF90aW1lID0gbWljcm90aW1lKFRSVUUpOw0KICAgIHdoaWxlICgkdHJ5IDwgNCkgew0KICAgICAg ICBpZiAoJHRyeSA9PSAxKSB7DQogICAgICAgICAgICAkYWdpLT5leGVjKCJSZWFkIiwgInBpbiwv aWdjL3NvdW5kcy9jYy1ib25nLCRwaW5zZXRfbGVuLCwxLDMiKTsNCiAgICAgICAgfSBlbHNlIHsN
    CiAgICAgICAgICAgIGlmICgkcGluc2V0X2xlbiA9PSAwKSB7DQogICAgICAgICAgICAgICAgJGFn aS0+ZXhlYygiUmVhZCIsICJwaW4scGxlYXNlLWVudGVyLXlvdXImYWNjZXNzLWNvZGUmL2lnYy9z b3VuZHMvY2MtYm9uZywsLDEsNSIpOw0KICAgICAgICAgICAgfSBlbHNlIHsNCiAgICAgICAgICAg ICAgICAkYWdpLT5leGVjKCJSZWFkIiwgInBpbixwbGVhc2UtZW50ZXIteW91ciZkaWdpdHMvJHBp bnNldF9sZW4mZGlnaXQmYWNjZXNzLWNvZGUmL2lnYy9zb3VuZHMvY2MtYm9uZywkcGluc2V0X2xl biwsMSw1Iik7DQogICAgICAgICAgICB9DQogICAgICAgIH0NCiAgICAgICAgJHRlbXAgPSAkYWdp LT5nZXRfdmFyaWFibGUoInBpbiIpOw0KICAgICAgICAkcGluID0gdHJpbSgkdGVtcFsiZGF0YSJd KTsNCg0KICAgICAgICBpZiAoJHBpbnNldF92ZXJpZnkgPT0gIjEiICYmICRwaW4gIT0gIiIpIHsN
    CiAgICAgICAgICAgICR0ZW1wID0gYXJyYXlfc2VhcmNoKCRwaW4sICRwaW5zKTsNCiAgICAgICAg ICAgIGlmICgkdGVtcCAhPT0gRkFMU0UpIHsNCiAgICAgICAgICAgICAgICAkYWdpLT5zZXRfdmFy aWFibGUoIlNNX1NUQVJUIiwgJHNtX3N0YXJ0ICsgKG1pY3JvdGltZShUUlVFKSAtICRhdXRoX3N0
    YXJ0X3RpbWUpKTsNCiAgICAgICAgICAgICAgICAkYWdpLT5leGVjKCJDRUxHZW5Vc2VyRXZlbnQi LCAiXCJTTSxzdGF0dXMgPT4gT0ssIGNhdXNlID0+MDAwLCBkZXRhaWwgPT4gVmVyaWZpZWQgUElO
    LCBwaW4gPT4gJHBpblwiIik7DQogICAgICAgICAgICAgICAgcmV0dXJuIGFycmF5KCJzdGF0dXMi ID0+ICJPSyIsICJjYXVzZSIgPT4iMDAwIiwgImRldGFpbCIgPT4gIlZlcmlmaWVkIFBJTiIsICJw aW4iID0+ICRwaW4pOw0KICAgICAg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0aW1lIGZvciBtZS4NCg0KLS0NCg0Kw4lsw6h2ZSBJbmfD
    qW5pZXVyIElORTMgw6AgbCdJbnN0aXR1dCBOYXRpb25hbCBkZXMgUG9zdGVzIGV0IFTDqWzDqWNv bW11bmljYXRpb25zICBJTlBUIC0gUmFiYXQgLSBNYXJvYw0KDQpSZXNwb25zYWJsZSBkZSBsYSBj ZWxsdWxlIEFzdGVyaXNrIGF1IENsdWIgRWxlY3Ryb25pcXVlIGV0IFN5c3RlbWVzIEVtYmFycXXD
    qXMgZGUgbCdJTlBUDQpNZW1icmUgZHUgcHJvamV0ICIgaWxlYXJuIiwgU0lGRSBJTlBUDQoNCiAg ICAgVGVsIDogKzIxMjY0MjM5ODc4Mg0KICAgICAgIFNreXBlICA6IGFiaWRhcmJyYWhpbQ0KDQo

  • thank you Eric for your response i will extract what i need in your function even i already test this :
    exten=> 777,1,Answer()
    exten=> 777,n,Read(digits,,1,,,3000)
    exten=> 777,n,SayNumber(${digits})
    exten=> 777,n,Hangup()

    and it works for me but i don’t know how to convert it to PHPAGI

  • 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}