Page 157 - Asterisk™: The Future of Telephony
P. 157
exten => 3,1,Playback(digits/3)
exten => 4,1,Playback(digits/4)
Dial extension 123, and then at the main menu prompt dial 1. Why doesn’t Asterisk
immediately read back the number one to you? It’s because the digit 1 is ambiguous;
Asterisk doesn’t know whether you’re trying to go to extension 1 or extension 123. It
waits a few seconds to see if you’re going to dial another digit (such as the 2 in extension
123). If you don’t dial any more digits, Asterisk will eventually time out and send the
call to extension 1. (We’ll learn how to choose our own timeout values in Chapter 6.)
Before going on, let’s review what we’ve done so far. When users call into our dialplan,
they will hear a greeting. If they press 1, they will hear the number one, and if they press
2, they will hear the number two, and so on. While that’s a good start, let’s embellish
it a little. We’ll use the Goto() application to make the dialplan repeat the greeting after
playing back the number.
As its name implies, the Goto() application is used to send the call to another part of
the dialplan. The syntax for the Goto() application requires us to pass the destination
context, extension, and priority on as arguments to the application, like this:
exten => 123,n,Goto(context,extension,priority)
Now, let’s use the Goto() application in our dialplan:
[incoming]
exten => 123,1,Answer()
exten => 123,n,Background(main-menu)
exten => 1,1,Playback(digits/1)
exten => 1,n,Goto(incoming,123,1)
exten => 2,1,Playback(digits/2)
exten => 2,n,Goto(incoming,123,1)
These two new lines (highlighted in bold) will send control of the call back to the 123
extension after playing back the selected number.
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 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.
Building an Interactive Dialplan | 129