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

${EXTEN:1} would give us everything after the first digit, 4169671111 (if the number of
                  digits to return is left blank, it will return the entire remaining string).
                  This is a very powerful construct, but most of these variations are not very common in
                  normal use. For the most part, you will be using ${EXTEN:1} to strip off your external
                  access code.



               Enabling Outbound Dialing
               Now that we’ve introduced pattern matching, we can go about the process of allowing
               users  to  make  outbound  calls.  The  first  thing  we’ll  do  is  add  a  variable  to  the
               [globals] context to define which channel will be used for outbound calls:
                   [globals]
                   JOHN=Zap/1
                   JANE=SIP/Jane
                   OUTBOUNDTRUNK=Zap/4
               Next, we will add contexts to our dialplan for outbound dialing.
               You may be asking yourself at this point, “Why do we need separate contexts for out-
               bound calls?” This is so that we can regulate and control which callers have permission
               to make outbound calls, and which types of outbound calls they are allowed to make.

               To begin, let’s create a context for local calls. To be consistent with most traditional
               phone switches, we’ll put a 9 on the front of our patterns, so that users have to dial 9
               before calling an outside number:
                   [outbound-local]
                   exten => _9NXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
                   exten => _9NXXXXXX,n,Congestion()
                   exten => _9NXXXXXX,n,Hangup()


                           Note that dialing 9 doesn’t actually give you an outside line, unlike with
                           many traditional PBX systems. Once you dial 9 on an analog line, the
                           dial tone will stop. If you’d like the dial tone to continue even after
                           dialing 9, add the following line (right after your context definition):
                              ignorepat => 9
                           This directive tells Asterisk to continue to provide a dial tone on an
                           analog line, even after the caller has dialed the indicated pattern. This
                           will not work with VoIP telephones, as they usually don’t send digits to
                           the system as they are input; they are sent to Asterisk all at once. Luckily,
                           most of the popular VoIP telephones can be configured to emulate the
                           same functionality.

               Let’s  review  what  we’ve  just  done.  We’ve  added  a  global  variable  called  OUTBOUND
                                                                             §
               TRUNK, which simply defines the channel we are using for outbound calls.  We’ve also
               added a context for local outbound calls. In priority 1, we take the dialed extension,


                                                                Building an Interactive Dialplan | 141
   164   165   166   167   168   169   170   171   172   173   174