System information
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(main-menu)
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 “main menu.”
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 further 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(main-menu)
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. This is generally considered friendlier than just hanging up.
If you look up the details of the Goto() application, you’ll find that you
can actually pass either one, two, or three arguments to the application.
If you pass a single argument, Asterisk will assume it’s the destination
priority in the current extension. If you pass two arguments, Asterisk
will treat them as the extension and the priority to go to in the current
context.
In this example, we’ve passed all three arguments for the sake of clarity,
but passing just the extension and priority would have had the same
effect, since the destination context is the same as the source context.
118 | Chapter 6: Dialplan Basics