• Aucun résultat trouvé

Using the Dial() Application

Dans le document Asterisk : The Future of Telephony ™ (Page 158-161)

One of Asterisk’s most valuable features is its ability to connect different callers to each other. This is especially useful when callers are using different methods of communi-cation. For example, caller A might be communicating over the traditional analog telephone network, while user B might be sitting in a café halfway around the world and speaking on an IP telephone. Luckily, Asterisk takes most of the hard work out of connecting and translating between disparate networks. All you have to do is learn how to use the Dial() application.

The syntax of the Dial() application is a little more complex than that of the other applications we’ve used so far, but don’t let that scare you off. Dial() takes up to four arguments. The first is the destination you’re attempting to call, which (in its simplest form) is made up of a technology (or transport) across which to make the call, a forward

slash, and the remote endpoint or resource. Common technology types include Zap (for analog and T1/E1/J1 channels), SIP, and IAX2. For example, let’s assume that we want to call a Zap endpoint identified by Zap/1, which is an FXS channel with an analog phone plugged into it. The technology is Zap, and the resource is 1. Similarly, a call to a SIP device (as defined in sip.conf) might have a destination of SIP/Jane, and a call to an IAX device (defined in iax.conf) might have a destination of IAX2/Fred. If we wanted Asterisk to ring the Zap/1 channel when extension 123 is reached in the dialplan, we’d add the following extension:

exten => 123,1,Dial(Zap/1)

We can also dial multiple channels at the same time, by concatenating the destinations with an ampersand (&), like this:

exten => 123,1,Dial(Zap/1&Zap/2&SIP/Jane)

The Dial() application will ring the specified destinations simultaneously, and bridge the inbound call with whichever destination channel answers the call first. If the Dial () application can’t contact any of the destinations, Asterisk will set a variable called DIALSTATUS with the reason that it couldn’t dial the destinations, and continue on with the next priority in the extension.*

The Dial() application also allows you to connect to a remote VoIP endpoint not pre-viously defined in one of the channel configuration files. The full syntax for this type of connection is:

Dial(technology/user[:password]@remote_host[:port][/remote_extension])

As an example, you can dial into a demonstration server at Digium using the IAX2 protocol by using the following extension:

exten => 500,1,Dial(IAX2/guest@misery.digium.com/s)

The full syntax for the Dial() application is slightly different when dealing with Zap channels, as shown:

Dial(Zap/[gGrR]channel_or_group[/remote_extension])

For example, here is how you would dial 1-800-555-1212 on Zap channel number 4.

exten => 501,1,Dial(Zap/4/18005551212)

The second argument to the Dial() application is a timeout, specified in seconds. If a timeout is given, Dial() will attempt to call the destination(s) for that number of sec-onds before giving up and moving on to the next priority in the extension. If no timeout is specified, Dial() will continue to dial the called channel(s) until someone answers or the caller hangs up. Let’s add a timeout of 10 seconds to our extension:

exten => 123,1,Dial(Zap/1,10)

* Don’t worry, we’ll cover variables (in “Using Variables”) and show you how to have your dialplan make decisions based on the value of this DIALSTATUS variable.

Building an Interactive Dialplan | 131

If the call is answered before the timeout, the channels are bridged and the dialplan is done. If the destination simply does not answer, is busy, or is otherwise unavailable, Asterisk will set a variable called DIALSTATUS and then continue on with the next priority in the extension.

Let’s put what we’ve learned so far into another example:

exten => 123,1,Dial(Zap/1,10) exten => 123,n,Playback(vm-nobodyavail) exten => 123,n,Hangup()

As you can see, this example will play the vm-nobodyavail.gsm sound file if the call goes unanswered.

The third argument to Dial() is an option string. It may contain one or more characters that modify the behavior of the Dial() application. While the list of possible options is too long to cover here, one of the most popular options is the m option. If you place the letter m as the third argument, the calling party will hear hold music instead of ringing while the destination channel is being called (assuming, of course, that music on hold has been configured correctly). To add the m option to our last example, we simply change the first line:

exten => 123,1,Dial(Zap/1,10,m) exten => 123,n,Playback(vm-nobodyavail) exten => 123,n,Hangup()

Since the extensions numbered 1 and 2 in our dialplan are somewhat useless now that we know how to use the Dial() application, let’s replace them with new extensions that will allow outside callers to reach John and Jane:

[incoming]

exten => 123,1,Answer()

exten => 123,n,Background(enter-ext-of-person) exten => 123,n,WaitExten()

exten => 1,1,Dial(Zap/1,10)

exten => 1,n,Playback(vm-nobodyavail) exten => 1,n,Hangup()

exten => 2,1,Dial(SIP/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()

The fourth and final argument to the Dial() application is a URL. If the destination channel supports receiving a URL at the time of the call, the specified URL will be sent (for example, if you have an IP telephone that supports receiving a URL, it will appear

on the phone’s display; likewise, if you’re using a soft phone, the URL might pop up on your computer screen). This argument is very rarely used.

Note that the second, third, and fourth arguments may be left blank. For example, if you want to specify an option but not a timeout, simply leave the timeout argument blank, like this:

exten => 1,1,Dial(Zap/1,,m)

Dans le document Asterisk : The Future of Telephony ™ (Page 158-161)