Local Channels

Local channels are a method of executing dialplans from the Dial() application. They may seem like a bit of a strange concept when you first start using them, but believe us when we tell you they are a glorious and extremely useful feature that you will almost certainly want to make use of when you start writing advanced dialplans. The best way to illustrate the use of Local channels is through an example. Let’s suppose we have a situation where we need to ring multiple people, but we need to provide delays of different lengths before dialing each of the members. The use of Local channels is the only solution to the problem.

With the Dial() application, you can certainly ring multiple endpoints, but all three channels will ring at the same time, and for the same length of time. Dialing multiple channels at the same time is done like so:

[LocalSets]
exten => 107,1,Verbose(2,Dialing multiple locations simultaneously)
   same => n,Dial(SIP/0000FFFF0001&DAHDI/g0/14165551212&SIP/MyITSP/12565551212,30)
   same => n,Hangup()

This example dials three destinations for a period of 30 seconds. If none of those locations answers the call within 30 seconds, the dialplan continues to the next line and the call is hung up.

However, let’s say we want to introduce some delays, and stop ringing locations at different times. Using Local channels gives us independent control over each of the channels we want to dial, so we can introduce delays and control the period of time for which each channel rings independently. We’re going to show you how this is done in the dialplan, both within a table that shows the delays visually, and all together in a box, like we’ve done for other portions of the dialplan. We’ll be building the dialplan to match the time starts and stops described in Figure 10.1, “Time delayed dialing with local channels”.

Figure 10.1. Time delayed dialing with local channels

Time delayed dialing with local channels

First we need to call three Local channels, which will all execute different parts of the dialplan. We do this with the Dial() application, like so:

[LocalSets]
exten => 107,1,Verbose(2,Dialing multiple locations with time delay)

; *** This all needs to be on a single line
   same => n,Dial(Local/channel_1@TimeDelay&Local/channel_2@TimeDelay
&Local/channel_3@TimeDelay,40)
   same => n,Hangup()

Now our Dial() application will dial three Local channels. The destinations will be the channel_1, channel_2, and channel_3 extensions located within the TimeDelay dialplan context. Remember that Local channels are a way of executing the dialplan from within the Dial() application. Our master timeout for all the channels is 40 seconds, which means any Local channel that does not have a shorter timeout configured will be hung up if it does not answer the call within that period of time.

As promised, Table 10.1, “Delayed dialing using Local channels” illustrates the delay configurations.

Table 10.1. Delayed dialing using Local channels

Time period (in seconds)channel_1channel_2channel_3
0 Dial(SIP/0000FFFF0001,20) Wait(10) Wait(15)
5   
10  Dial(DAHDI/g0/14165551212)  
15   Dial(SIP/MyITSP/12565551212,15)
20 Hangup()   
25   
30   Hangup()
35   
40   

In this table, we can see that channel_1 started dialing location SIP/0000FFFF0001 immediately and waited for a period of 20 seconds. After 20 seconds, that Local channel hung up. Our channel_2 waited for 10 seconds prior to dialing the endpoint DAHDI/g0/14165551212. There was no maximum time associated with this Dial(), so its dialing period ended when the master time out of 40 seconds (which we set when we initially called the Local channels) expired. Finally, channel_3 waited 15 seconds prior to dialing, then dialed SIP/MyITSP/12565551212 and waited for a period of 15 seconds prior to hanging up.

If we put all this together, we end up with the following dialplan:

[LocalSets]
exten => 107,1,Verbose(2,Dialing multiple locations with time delay)

; *** This all needs to be on a single line
   same => n,Dial(Local/channel_1@TimeDelay&Local/channel_2@TimeDelay
&Local/channel_3@TimeDelay,40)
   same => n,Hangup()

[TimeDelay]
exten => channel_1,1,Verbose(2,Dialing the first channel)
   same => n,Dial(SIP/0000FFFF0001,20)
   same => n,Hangup()

exten => channel_2,1,Verbose(2,Dialing the second channel with a delay)
   same => n,Wait(10)
   same => n,Dial(DAHDI/g0/14165551212)

exten => channel_3,1,Verbose(2,Dialing the third channel with a delay)
   same => n,Wait(15)
   same => n,Dial(SIP/MyITSP/12565551212,15)
   same => n,Hangup()

You’ll see Local channels used throughout this book, for various purposes. Remember that the intention is simply to perform some dialplan logic from a location where you can only dial a location, but require some dialplan logic to be executed prior to dialing the endpoint you eventually want to get to. A good example of this is with the use of the Queue() application, which we’ll discuss in the section called “Using Local Channels”.

Additional scenarios and information about Local channels and the modifier flags (/n, /j, /m, /b) are available at https://wiki.asterisk.org/wiki/display/AST/Local+Channel. If you will be making any sort of regular use of Local channels, that is a very important document to read.