text stringlengths 0 152 |
|---|
One of the more useful applications in an interactive Asterisk dialplan is the Back |
ground()8 application. Like Playback(), it plays a recorded sound file. Unlike |
Playback(), however, when the caller presses a key (or series of keys) on their tele‐ |
phone keypad, it interrupts the playback and passes the call to the extension that cor‐ |
responds 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 (assuming there is an extension 5 to send the call to). |
The most common use of the Background() application is to create basic voice |
menus (often called auto attendants, IVRs,9 or phone trees). Many companies use |
voice menus to direct callers to the proper extensions, thus relieving their reception‐ |
ists from having to answer every single call. |
Background() has the same syntax as Playback(): |
[TestMenu] |
exten => start,1,Answer() |
same => n,Background(enter-ext-of-person) |
If you want Asterisk to wait for input from the caller after the sound prompt has fin‐ |
ished playing, you can use WaitExten(). The WaitExten() application waits for the |
caller to enter DTMF digits and is used directly following the Background() applica‐ |
tion, like this: |
[TestMenu] |
exten => start,1,Answer() |
same => n,Background(enter-ext-of-person) |
same => n,WaitExten() |
8 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. |
9 More information about auto attendants and IVR can be found in Chapter 14. |
90 |
| |
Chapter 6: Dialplan Basics |
If you’d like the WaitExten() application to wait a specific number of seconds for a |
response (instead of using the default timeout),10 simply pass the number of seconds |
as the first argument to WaitExten(), like this: |
same => n,WaitExten(5) ; We always pass a time argument to WaitExten() |
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 a match, it will send the call to that extension. Let’s |
demonstrate by adding a few lines to our dialplan example: |
[TestMenu] |
exten => start,1,Answer() |
same => n,Background(enter-ext-of-person) |
same => n,WaitExten(5) |
exten => 1,1,Playback(digits/1) |
exten => 2,1,Playback(digits/2) |
After making these changes, save and reload your dialplan: |
*CLI> dialplan reload |
If you call into extension 201, you should hear a sound prompt that says, “Enter the |
extension of the person you are trying to reach.” The system will then wait 5 seconds |
for you to enter a digit. If the digit you press is either 1 or 2, Asterisk will match the |
relevant extension, and read that digit back to you. Since we didn’t provide any fur‐ |
ther instructions, your call will then end. You’ll also find that if you enter a different |
digit (such as 3), the dialplan will be unable to proceed. |
Let’s embellish things a little. We’re going to use the Goto() application to have the |
dialplan repeat the greeting after playing back the number: |
[TestMenu] |
exten => start,1,Answer() |
same => n,Background(enter-ext-of-person) |
same => n,WaitExten(5) |
exten => 1,1,Playback(digits/1) |
same => n,Goto(TestMenu,start,1) |
exten => 2,1,Playback(digits/2) |
same => n,Goto(TestMenu,start,1) |
These new lines will send control of the call back to the start extension after playing |
back the selected number. |
10 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 |
| |
91 |
If you look up the details of the Goto() application, you’ll find that |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.