Digit collect

Hello,

I am trying to make a rule in extensions.conf that should behave like this:

  • play a dial tone
  • when the user starts dialing, stop the dialtone after the first digit (like the behavior of your standard phone)
  • when the user finishes dialing (by either timeout or the user dialing #), dial that number.

What I have did is:

[extdial]
exten => s,1,Answer()
exten => s,2,Playtones(440)
exten => s,3,Set(TIMEOUT(digit)=4)
exten => s,4,WaitExten(600)

exten => _0XZ.,1,Dial(SIP/${EXTEN}@gateway)

The problem is that Playtones does not stop after the first digit dialed, and that WaitExten does not consider the digit collecting process ended by #.

Is it possible to make the dialtone stop after the first digit dialed?

And the more important thing: is it possible to configure the digit collection somehow to be ended by #, like on a Cisco gateway or most of the IVR systems? I have tried:
exten => _0XZ.#,1,Dial(SIP/${EXTEN}@gateway)
but nothing changed.

I have found the solution:

exten => s,1,Set(collect=A)
exten => s,2,Set(erase=0)
exten => s,3,Set(TIMEOUT(digit)=1)
exten => s,4,Set(TIMEOUT(response)=600)
exten => s,5,GotoIf($["${collect}" = "A"]?6:7)
exten => s,6,Playtones(440)
exten => s,7,WaitExten(600)

exten => _X,1,StopPlaytones()
exten => _X,2,Set(collect=${collect}${EXTEN})
exten => _X,3,Goto(s,7)

exten => *,1,GotoIf(${erase}?2:4)
exten => *,2,Playback(clear)
exten => *,3,Goto(s,1)
exten => *,4,SayDigits(${collect:1})
exten => *,5,Set(erase=1)
exten => *,6,Goto(s,7)

exten => #,1,GotoIF($["${collect:1:2}" = "00"]?2:4)
exten => #,2,Dial(SIP/${collect:1}@gateway)
exten => #,3,Hangup()
exten => #,4,Playback(you-dialed-wrong-number)
exten => #,5,Playback(please-try-again)
exten => #,6,Goto(s,1)

It collects digit by digit, plays the dialtone until the first digit is pressed and ends with #. Pressing * once plays the number, pressing * the second time erases the number.