Page 155 - Asterisk™: The Future of Telephony
P. 155

[incoming]
                   exten => s,1,Answer()
                   exten => s,n,Playback(hello-world)
                   exten => s,n,Hangup()
                                                                      ‖
               If you have a channel or two configured, go ahead and try it out!  Simply create a file
               called extensions.conf, (probably in /etc/asterisk) and insert the four lines of dialplan
               code we just designed. If it doesn’t work, check the Asterisk console for error messages,
               and make sure your channels are assigned to the [incoming] context.
               Even though this example is very short and simple, it emphasizes the core concepts of
               contexts, extensions, priorities, and applications. If you can get this to work, you have
               the fundamental knowledge on which all dialplans are built.
               Let’s build upon our example. After all, a phone system that simply plays a sound file
               and then hangs up the channel isn’t that useful!

               Building an Interactive Dialplan

               The dialplan we just built was static; it will always perform the same actions on every
               call. We are going to start adding some logic to our dialplan so that it will perform
               different actions based on input from the user. To do this, we’re going to need to
               introduce a few more applications.

               The Background(), WaitExten(), and Goto() Applications

               One of the most important keys to building interactive Asterisk dialplans 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 goes 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.
               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 call-
               ers to the proper extensions, thus relieving their receptionists from having to answer
               every single call.





               ‖ In fact, if you don’t have any channels configured, now is the time to do so. There is a real satisfaction that
                 comes from passing your first call into an Asterisk system that you built from scratch. People get this funny
                 grin on their face as they realize that they have just created a telephone system. This pleasure can be yours
                 as well, so please, don’t go any further until you have made this little dialplan work.
               # It should be noted that some people expect that Background(), due to its name, would continue in the dialplan
                 while the sound is being played, but its name refers to the fact that it is playing a sound in the background,
                 while waiting for DTMF in the foreground.

                                                                Building an Interactive Dialplan | 127
   150   151   152   153   154   155   156   157   158   159   160