Page 156 - Asterisk™: The Future of Telephony
P. 156
Background() has the same syntax as Playback():
exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
In earlier versions of Asterisk, if the Background() application finished playing the sound
prompt and there were no more priorities in the current extension, Asterisk would sit
and wait for input from the caller. Asterisk no longer does this by default. If you want
Asterisk to wait for input from the caller after the sound prompt has finished playing,
you can call the WaitExten() application. The WaitExten() application waits for the
caller to enter DTMF digits, and is frequently called directly after the Background()
application, like this:
exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()
If you’d like the WaitExten() application to wait a specific number of seconds for a
response (instead of using the default timeout), simply pass the number of seconds as
the first argument to WaitExten(), like this:
exten => 123,n,WaitExten(5)
Both Background() and WaitExten() allow the caller to enter DTMF digits. Asterisk then
attempts to find an extension in the current context that matches the digits that the
caller entered. If Asterisk finds an unambiguous match, it will send the call to that
extension. Let’s demonstrate by adding a few lines to our example:
exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()
exten => 2,1,Playback(digits/2)
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
If you call into extension 123 in the example above, it will play a sound prompt that
says “main menu.” It will then wait for you to enter either 2, 3, or 4. If you press one
of those digits, Asterisk will read that digit back to you. You’ll also find that if you enter
a different digit (such as 5), it won’t give you what you expected.
It is also possible that Asterisk will find an ambiguous match. This can be easily ex-
plained if we add an extension named 1 to the previous example:
exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
exten => 123,n,WaitExten()
exten => 1,1,Playback(digits/1)
exten => 2,1,Playback(digits/2)
128 | Chapter 5: Dialplan Basics