Adding Logic to the Dialplan

The dialplan we just built was static—it always performs the same actions on every call. Now we’ll start adding some logic to our dialplan so that it will perform different actions based on input from the user. We’ll start by introducing a few more applications.

The Background() and Goto() Applications

One important key to building interactive Asterisk systems is the Background() 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 goes to the extension that corresponds with the pressed digit(s). If a caller presses 5, for example, Asterisk will stop playing the sound file and send control of the call to the first priority of extension 5.

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():

    exten => 123,1,Background(hello-world)

Another useful application is Goto(). As its name implies, it is used to send the call to another context, extension, and priority. The Goto() application makes it easy to programmatically move a call between different parts of the dialplan. The syntax for the Goto() application calls for us to pass the destination context, ...

Get Asterisk: The Future of Telephony now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.