System information
We used the extension start in this example, but we could have used
anything we wanted as an extension name, either numeric or alpha. We
prefer to use alpha characters for extensions that are not directly diala-
ble, as this makes the dialplan easier to read. Point being, we could have
used 123 or xyz123, or 99luftballons, or whatever we wanted instead of
start. The word “start” doesn’t actually mean anything to the dialplan;
it’s just another extension.
One of the most useful applications in an interactive Asterisk dialplan is the Back
ground()
*
application. Like Playback(), it plays a recorded sound file. Unlike
Playback(), however, when the caller presses a key (or series of keys) on her telephone
keypad, it interrupts the playback and passes the call to the extension that corresponds
with the pressed digit(s). If a caller presses 5, for example, Asterisk will stop playing
the sound prompt and send control of the call to the first priority of extension 5 (as-
suming there is an extension 5 to send the call to).
The most common use of the Background() application is to create voice menus (often
called auto attendants
†
or phone trees). Many companies use voice menus to direct
callers to the proper extensions, thus relieving their receptionists from having to answer
every single call.
Background() has the same syntax as Playback():
[TestMenu]
exten => start,1,Answer()
same => n,Background(main-menu)
If you want Asterisk to wait for input from the caller after the sound prompt has finished
playing, you can use WaitExten(). The WaitExten() application waits for the caller to
enter DTMF digits and is used directly following the Background() application, like this:
[TestMenu]
exten => start,1,Answer()
same => n,Background(main-menu)
same => 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:
same => n,WaitExten(5) ; We recommend always passing a time argument to WaitExten()
* It should be noted that some people expect that Background(), due to its name, will continue onward through
the next steps in the dialplan while the sound is being played. In reality, its name refers to the fact that it is
playing a sound in the background, while waiting for DTMF in the foreground.
† More information about auto attendants can be found in Chapter 15.
‡ See the dialplan function TIMEOUT() for information on how to change the default timeouts. See Chapter 10
for information on what dialplan functions are.
Building an Interactive Dialplan | 117