Friday, May 1, 2009

Asterisk PBX System Install - 08 Outbound Calls

Issue: Last time we got inbound calls working and it is time to enable outbound calls.

Quick/Visual/Learning:
In our last post we already configured the Cisco 1760 router outbound calls. It was the section of the configuration that looked like:

dial-peer voice 100 pots destination-pattern .T port 0/0 forward-digits all

Where .T is a wildcard that matches all numbers, so Cisco should pass along whatever numbers we send it to our external phone line. Now we just need to tell Asterisk what to send it.

For this I am working again off of Chapter 5 of the book, which is “Dialplan Basics” to learn about pattern matching and variables.

Because we do not know what external number is going to be dialed, we have to get Asterisk to recognize a pattern of numbers that will signal that this is an outside call. We also have to capture what number was dialed and pass that along to the Cisco switch, which is stored in a variable.

Variables are just buckets that hold a piece of information, such as a name or a number. Among other things variables simplify changes. For example if you need to change a sip device and you have called it in several locations of a dialplan then you have to change it in each location. For starters I am going to create a global (seen by the whole dialplan) variable that points to my outbound sip device. The [globals] context is a special context name were you can put these types of variables. Also note that variables are case sensitive.

[globals]
OUTBOUNDTRUNK=SIP/Cisco1760

This sets the contents of our OUTBOUNDTRUNK bucket (variable) to be the name of the Cisco router that I configured in the sip.conf file last time.

To get the contents out of a variable you have to write it like this ${VaribleName}. So per our example, we can use ${OUTBOUNDTRUNK} anywhere in our dialplan where we would normally put the text SIP/Cisco1760.

Now I will look at pattern matching. A typical way of calling an outside number is to dial 9 to get an outside line and then to dial the 7-digit local phone number. I would like Asterisk to match any number that starts with 9 and is followed by 7 digits, like 9XXXXXXX.

To do this you start your pattern with an underscore, and enter your pattern. X matches any number, Z matches 1-9, and N matches 2-9.

So to match a local number the pattern would look like:
_9NXXXXXX
After the 9 we are just going to match numbers 2-9 as a 1 after then 9 would be the pattern for a long-distance call.

One last bit is that we need to pass the number that was dialed to the Cisco 1760 so that the call can be processed. Asterisk has a built in variable that stores this information for us which is ${EXTEN}. We want to pass alone the phone number but not the leading 9, so to strip that off we use ${EXTEN:1}. The 1 says to start with the second number that was dialed. This is position one of the variable. That is a bit confusing but the positions of the variable start with zero like this: 012345678 so position 0 would be the leading 9 and position 1 is the first digit of our local phone number.

Now we should have enough information to update our dialplan.

[outbound-local]
exten => _9NXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
exten => _9NXXXXXX,n,Congestion()
exten => _9NXXXXXX,n,Hangup()

exten => 911,1,Dial(${OUTBOUNDTRUNK}/911)
exten => 9911,1,Dial(${OUTBOUNDTRUNK}/911)

Here we are going to match any local phone number and dial out using our outbound device (Cisco 1760). If this fails for some reason the next step is Congestion(), which play a fast busy tone, and the last step is to hang up the line.

Also we have the options for dialing 911 configured. This is set to work with or without dialing 9 first for an outside line (someone in an emergency might for get to dial 9 first).

Remember that ignorepat is this section of the book does not work with our Cisco phones and you have to use the DIALTEMPLATE file to keep dial tone after pressing 9 (see Asterisk PBX System Install - 05 Cisco SIP Phone)


Our outbound dialing has it’s own context [outbound-local]. Remember contexts are separate from each other. We want our internal users to be able to use this [outbound-loca] context so we need to include it in our [internal] context.

[internal]
include => outbound-local

Time to reload the dialplan.
#asterisk –r
>dialplan reload

Now with these changes we should be able to make an outbound call.

You can also add long distance and 800 number dialing by adding a context like:
[outbound-long-distance]
exten => _91NXXNXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
exten => _91NXXNXXXXXX,n,Congestion()
exten => _91NXXNXXXXXX,n,Hangup()

Remember to include it in the internal context as well.

Next time Voicemail
Asterisk PBX System Install - 09 Voicemail Macros
Asterisk PBX Install - Index

No comments: