问题
I am writing an IVR menu and I need to allow my users to press 0 anytime during the communication to exit. The following is how I do it:
exten => 0,1,Playback(good-bye)
exten => 0,2,Playback(beep)
exten => 0,3,Hangup
However, by doing so, when the user presses zero while some file is being played back or some other operation is taking place, he/she cannot exit, it is like if he/she didn't press zero. I hope I am clear enough and that you can help me out with this. cheers
回答1:
For an IVR, you want to use Background() and/or WaitExten() instead of Playback(). Here's a sample IVR dialplan:
[ivr_main]
; answer and play announcement
exten => s,1,Set(TIMEOUT(response)=2)
exten => s,2,Set(TIMEOUT(digit)=2)
exten => s,3,BackGround(/your/audio/file/announcement)
exten => s,4,WaitExten(2)
exten => s,5,GoTo(s|3) ; careful of this loop here! should GoTo() somewhere else!
; handle key presses
exten => 0,1,Playback(good-bye)
exten => 0,2,Playback(beep)
exten => 0,3,Hangup()
exten => 1,1,NoOp(do this if user presses 1)
exten => 2,1,NoOp(do this if user presses 2)
exten => 3,1,NoOp(do this if user presses 3)
exten => 4,1,NoOp(do this if user presses 4)
exten => 5,1,NoOp(do this if user presses 5)
; handle invalid key presses
exten => i,1,Playback(pbx-invalid)
exten => i,2,GoTo(s|3)
; handle time out (user did not make a selection)
exten => t,1,GoTo(0|1) ; go to Hangup :-)
Hope this helps.
In the Asterisk CLI, do 'show application Background' and 'show application WaitExten' for the manual of these applications.
回答2:
AFAIK, Asterisk would only be able to pick up on the key press when you've called Background, or WaitExten. So if you're running some AGI, it will have to have invoked one of those two commands.
回答3:
Asterisk is not always waiting for user input. Only during the Background, WaitExten, Read commands. If you're using Playback(), Asterisk ignores any DTMF while it's playing the audio file.
You can replace Playback with Read() but you have to set the read timeout to a very low value or there will be a silence after every audio file you play with Read(). If you use Read() then you have to check the value input by the user to check for exit, something like this...
Instead of
exten => x,n,Playback(yourfile)
exten => x,n,somethingelse...
you need
exten => x,n,Read(Exit,yourfile,1)
exten => x,n,GotoIf($["${Exit}" = "0"]?0,1)
exten => x,n,somethingelse...
来源:https://stackoverflow.com/questions/925621/seek-help-concerning-ivr-menu-in-asterisk