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

[globals]
                   JOHN=Zap/1
                   JANE=SIP/Jane

                   [incoming]
                   exten => 123,1,Answer()
                   exten => 123,n,Background(enter-ext-of-person)
                   exten => 123,n,WaitExten()

                   exten => 1,1,Dial(${JOHN},10)
                   exten => 1,n,Playback(vm-nobodyavail)
                   exten => 1,n,Hangup()
                   exten => 2,1,Dial(${JANE},10)
                   exten => 2,n,Playback(vm-nobodyavail)
                   exten => 2,n,Hangup()
                   exten => i,1,Playback(pbx-invalid)
                   exten => i,n,Goto(incoming,123,1)

                   exten => t,1,Playback(vm-goodbye)
                   exten => t,n,Hangup()
                   [employees]

                   exten => 101,1,Dial(${JOHN})
                   exten => john,1,Dial(${JOHN})
                   exten => 102,1,Dial(${JANE})
                   exten => jane,1,Dial(${JANE})
               Pattern Matching

               If we want to be able to allow people to dial through  Asterisk and have Asterisk connect
               the caller to an outside resource, we need a way to match on any possible phone number
               that the caller might dial. Can you imagine how tedious it would be to manually write
               a dialplan with an extension for every possible number you could dial? Luckily, Asterisk
               has just the thing for situations like this: pattern matching. Pattern matching allows you
               to create one extension in your dialplan that matches many different numbers.

               Pattern-matching syntax
               When using pattern matching, certain letters and symbols represent what we are trying
               to match. Patterns always start with an underscore (_). This tells Asterisk that we’re
               matching on a pattern, and not on an explicit extension name. (This means, of course,
               that you should never start your extension names with an underscore.)

                           If you forget the underscore on the front of your pattern, Asterisk will
                           think it’s just a named extension and won’t do any pattern matching.
                           This is one of the most common mistakes people make when starting
                           to learn Asterisk.


                                                                Building an Interactive Dialplan | 137
   160   161   162   163   164   165   166   167   168   169   170