5  Calls Handling 

5.1  Inbound Routes (Incoming Calls)

This is where the behaviour of incoming calls from all trunks is being handled.

When an incoming call from PSTN or VoIP trunk is received, asterisk needs to know where to direct it.  It can be directed to a ring group, an extension, Digital Receptionist or Queue.  For this purpose, Inbound Route needs to be set up.

Select the Inbound Routes selection in the left bar of the screen.

Initially, I have set all my incoming calls to be directed to Ring Group 10 as illustrated below (later on in this guide I will create a digital receptionist for this purpose).

I only put in the following data.  The rest are optional.

For each extra trunk, a corresponding inbound route may be created.  All incoming calls from all the different trunks that you may have can have their own individual characteristic by judicious deployment of the time condition facility available in FreePBX (to be discussed later on).

At least one Inbound Route must be created for TRIXBOX to answer incoming calls.  This includes calls from PSTN trunk as well.

As usual, you will need to click on the red bar on top of the screen after each time you submit a new Inbound Route.

To handle the calls that come in without Trunk ID, you may create a Catch-All route.  In my case, I simply create an Inbound Route with the DID Number and Calling ID Number fields left blank.  This will have the effect of handling all calls from trunks that does not have an Inbound Route created (which includes all calls from PSTN and incorrectly created incoming route).  As a matter of fact, this can be the only Inbound Route that you will need if you deploy IVR (to be discussed later on). Besides, without this inbound route created, your 7777 simulated call may not work.

5.2  Time Conditions

You can create various time conditions and use these time conditions in conjunction with your Inbound Route to individualise each of the incoming trunk’s behaviour.

You may create several time conditions and give each of the time condition a Short Name to identify it.  These time conditions can then be assigned to each individual Inbound Route if you choose to do so.

Simple Time Condition

Most private householders, ignore the time condition, instead would prefer to direct all calls to an extension or selected extensions regardless whether it is day or night.  If this is the case, you may ignore time condition altogether, instead, use the inbound route to direct your incoming calls to individual extensions or to the digital receptionist.  However, if you want to accept calls during the day but prefer callers to simply leave voice messages during the night, below is an example of a simple time condition that you can adopt where the time condition will send the calls to IVR during the hour of 8:00am and 8:00pm and anything outside the stipulated hours, the calls will be directed to your voicemail.

o        Time to start: 08:00

o        Time to finish: 20:00

o        Week Day start: Monday

o        Week Day finish: Sunday

Once the above is done, go to Inbound Route, select the appropriate inbound route and under Set Destination, select Time Condition DayNight, submit and click the red bar on top of the screen.

Complex Time Condition

A slightly more complex one can also be crafted eg:  You want o accept calls only between 8:00am till 1:00pm and between 2:00pm and 5:30pm Monday to Friday and any other time you want to direct all the calls to voicemail.

1.  Add a morning time condition.

o        Time to start: 08:00

o        Time to finish: 13:00

o        Week Day start: Monday

o        Week Day finish: Friday

  1. Add an afternoon time condition

o        Time to start: 14:00

o        Time to finish: 17:30

o        Week Day start: Monday

o        Week Day finish: Friday

  1. Go back to time condition OfficeMorning and change the Destination if time does not match to: Time Condition OfficeAfternoon.  Submit and click on the red bar on top of the screen.
     
  2. Once the above is done, go to Inbound Route, select the appropriate inbound route and under Set Destination, select Time Condition OfficeMorning, submit and click the red bar on top of the screen.

What the inbound route will do is, as soon as an incoming call is accepted, it will be forwarded to the OfficeMorning time condition.

If the time condition is met, it will then be forwarded to the IVR.  On the other hand, if it does not match, it will be forwarded to time condition OfficeAfternoon.

If it matches the OfficeAfternoon time condition, the call will be forwarded to IVR, if not, it will be forwarded to the voicemail box that you have determined.

Following the above example, time conditions can be nested to multiple levels deep allowing you to manage your time condition and make them as complex or as simple as the situation demands – imagination is the only restricting factor.

 

5.3  Outbound Routes 

5.3.1  What is an Outbound Route? 

An outbound route works like a traffic cop giving directions to road users to use a predefined route to reach a predefined destination. 

To create a new route using freePBX, select Setup tab and then select the Outbound Route option from the vertical menu on the left. 

 

 

 5.3.2  How does it work? 

Every time you dial a number, asterisk will do the following in strict order; 

To make a call out (except inter extension calls), you will need at least one trunk and one route. 

In my case I created 5 routes:

The International Route will be used for all international phone calls.
The Domestic Route will take care of the Australian phone and mobile.

The other three will do as the names suggest.
 

Click on the Add Route in the menu on the right of the screen. 

5.3.3  International

You will need the following pattern to match international dialling. 

Pattern

Explanation

0011|60NXX.

Most of my International calls are to Malaysia, I have defined the Malaysian PSTN pattern here.

0011|[7-9]XX.

This pattern dials all international numbers by prefixing it with 0011 and any digit between 7 and nine inclusive. Before the number is sent to the trunk the 0011 will be stripped. If required by the trunk, the trunk will insert the 0011.

0011|NXX.

This is the catchall international dialling including International Mobile (excluding USA which is a 1).

In your Dial Patterns box, you will see something like this. 

 

You will then need to pick the Trunk Sequent.  In my case I need Astratel as the trunk for this route and if it fails, I want Pennytel as a second choice/backup 

 

Any number dialled with the 0011 prefix will be routed through the Astratel trunk and should it fail, it will be routed to Pennytel.

5.3.4  Domestic

You need the following pattern to match the Australian Telephone numbers and the Australian Mobile numbers. 

Pattern

Explanation

0|[23478]XXXXXXXX

You will dial Australian telephone number as normal using 03, 02 prefix but the route will strip the leading 0 before it is sent to the trunk.

If the trunk requires the 0, the trunk will insert it.

[2-9]XXXXXXX

If you dial local number and not use the STD prefix, it will send to the trunk as is and the trunk will insert the 02 if required (this is a NSW pattern.  If you are in Victoria you will need to modify the trunk).

ZXX.

This is the catchall dialing for numbers that does not start with a 0 such as 1300, 1800, 13 etc.

 In your Dial Patterns box, you will see something like this. 

 

You will then need to pick the Trunk Sequent.  In this case I need Oztell as the trunk for this route and if it fails, I want Astratel to take over as a second choice/backup 

 

All numbers dialled matching the above pattern will be routed through Oztell and if it failed, it will be routed via Astratel. 

5.3.5  MobileAust

I have only a single pattern for calling Australian mobile – illustrated below.

 

I want all my domestic mobile calls to be routed via Pennytel and I have not nominated a second trunk.  If it fails then I will not be able to make a Mobile call, as I don’t have a second trunk nominated.

5.3.6  Oztellonly

I have the following pattern in my Oztellonly route.  I use Oztell for a number of call types therefore some explanation may be in order.

Pattern

Explanation

0011|601XX.

This pattern will allow me to dial a Malaysian Mobile number.  The 0011 will be stripped before the number is sent to Oztell.  Oztell does not require the 0011.  It only requires the Country code.

0|[378]NXXXXXXX

You will dial Australian telephone number as normal using 03, 02 prefix but the route will strip the leading 0 before it is sent to the trunk.

If the trunk requires the 0, the trunk will insert it.

1[38]XX.

This is for dialing 1300, 1800 and 13 numbers.

899060XX.

For dialing Oztell inter Oztell users

NXXXXXXX

Catchall for dialing a local number that doesn’t start with 1

 In the dial pattern box you will see something like the illustration below.

 

Since the above pattern is for Oztell only, in my trunk sequence, Oztell was chosen to be the only trunk for any of these calls.

5.3.7  Astratelonly

There is only one pattern for Astratel only calls.  It is the Astratel DID for calling inter-Astratel users. I use 1278 as a unique number to identify that this number must be dialled through Astratel.

 

Correspondingly, there is only one trunk selected.


5.4  ENUM 

ENUM is a way for us to use VOIP to establish calls between VOIP systems without using PSTN even though the numbers called are PSTN numbers provided that the numbers called are registered with ENUM.  In short, ENUM offers you the ability to call other telephones directly over the Internet without involving a third party.

I will not enter into any elaborate explanation how enum works, as there are already a number of articles describing this.  In essence, your phone number and server information are stored in a special DNS zone (very similar to a reverse lookup zone).  When an ENUM enabled Asterisk user calls your phone number, it will first attempt to find your phone number in the ENUM DNS zone.  If it finds your phone number it will use the information to set-up a call directly between his Asterisk server and yours, resorting to PSTN only if your number is not found.

Note:  ENUM only works between ENUM enabled Asterisk (or other ENUM enabled VOIP) users.

5.4.1  Setting up ENUM Trunk

Click the Add Enum Trunk link.

  1. In the Outbound Caller ID field enter your callerid information in the format of "Your Name" <61246123456>  (Including the quotes), assuming your telephone number in Sydney is 0246123456.

  2. In the Outgoing Dial Rule enter 612+NXXXXXXX (for local calls without having to dial the 02)

  3. In the second line enter 61+NXXXXXXXX (for dialing Australian numbers where you need to dial the prefix (eg. 03)

  4. In the next line enter ZXXXXXXXX. (including the dot) for dialing International numbers – see example below:


  5. Click the Submit Changes button at the bottom of the page

  6. Click the You have made changes - when finished, click here to APPLY them at the top of the page.
     

5.4.2  Setting up ENUM Outbound Route

  1. Click the Outbound Routing link on the left hand side.

  2. In the routes window on the right-hand side, click the route you would like to enable with ENUM.  I call my route e164.

  3. I decided to use the prefix 164 to force dial through ENUM

  4. In the Dial Pattern, on the first line, I had 1640|[378]NXX. This will allow me to dial an STD number such as 0732123456 where only the 732123456 will be sent to the ENUM trunk.

  5. On the second line I have 1640011|NXX.  This will allow me to call an International number eg. To call Malaysia I will dial 16400116062861234 and only the 6062861234 will be sent to the ENUM trunk.

  6. On the third line I have 164|NXX.  This enamels me to dial NSW local number without having to dial 02.


  7. Make the ENUM trunk the first route in your Trunk Sequence.   You may also add other trunks in the sequence in case ENUM failed.


  8. Click the Submit Changes button at the bottom of the page.

  9. Click the You have made changes - when finished, click here to APPLY them at the top of the page.

  10. You may try calling someone while monitoring Asterisk CLI and you should see the Enumlookup scroll by.

Click here for a Step-by-Step instruction on how to set up an ENUM account.

5.5  How to restrict outgoing calls 

This requirement often manifests itself in an office environment where management restricts staff from making International, Long Distance or even local calls.  In many organization, staff are restricted to making internal calls only.

There is no easy way of imposing this restriction through the freePBX GUI.  The only way that that can be done currently is to introduce special scripts in the extensions_custom.conf file or create a special .conf file.  For now, we will stick with the simplest method.

It is somewhat complicated, but I will try to explain it here and provide an example.

  1. Set up all your trunks and outbound routes as normal. At this stage, users can make unrestricted calls.  This is the normal way of doing it with freePBX.  You probably would have already done this.

  2. Through Config Edit of TRIXBOX, open extensions_additional.conf and locate the [outbound-allroutes] section of the file.  You will notice something like my example below.

[outbound-allroutes]
include => outbound-allroutes-custom
include => outrt-001-PSTN
include => outrt-002-SPA3K
include => outrt-003-Oztell
include => outrt-004-Pennytel
include => outrt-005-TeleGlobal
include => outrt-006-Astratel
include => outrt-007-MyNetFone
include => outrt-008-SpanTalk
include => outrt-009-VoIPBuster
include => outrt-010-Domestic
include => outrt-011-MobileAust
include => outrt-012-International
include => outrt-013-12Number
include => outrt-014-13N1800Numbers
include => outrt-015-USFree
include => outrt-016-e164
include => outrt-017-LA-Link
include => outrt-018-UK-Link
include => outrt-019-SingaporeLink
include => outrt-020-KualaLumpurLink
include => outrt-021-MalaccaLink
include => outrt-022-PenangLink
exten => foo,1,Noop(bar)

; end of [outbound-allroutes]

Highlight them, copy and paste in a notepad text file somewhere.  We will get back to this a little later.

Alternatively you can paste it directly to extensions_custom.conf.  Do not do this if Trixbox is active as it may cause some problem while people using it.

  1. Through Config Edit of TRIXBOX, open extensions_custom.conf and create a section like my example below.  You can get the codes from [from-internal-additional] of extensions_additional.conf. So will have to do some juggling because you can't cut and paste this from another .conf file without having to close one (you can cut and paste from here if you like).

[from-restricted]
;
; These are all the applications that you will require
;
include => app-cf-busy-off
include => app-cf-busy-off-any
include => app-cf-busy-on
include => app-cf-off
include => app-cf-off-any
include => app-cf-on
include => app-cf-unavailable-off
include => app-cf-unavailable-on
include => app-calltrace
include => app-callwaiting-cwoff
include => app-callwaiting-cwon
include => app-dialvm
include => app-directory
include => app-dnd-off
include => app-dnd-on
include => app-echo-test
include => app-recordings
include => app-speakextennum
include => app-speakingclock
include => app-userlogonoff
include => app-zapbarge
include => app-vmmain
include => ext-group
include => ext-fax
include => ext-meetme
include => ext-findmefollow
include => ext-paging
include => ext-queues
include => ext-test
include => ext-local
include => parkedcalls

;
; #### OutBound Routes ##########
; # Below are restricted routes #
; ###############################

Now copy your [outbound-allroutes] that was saved to the text file directly underneath the last line of the above context.  Remember to delete the [outbound-allroutes] label.  Unfortunately you can’t cut and paste my example because they are my routes NOT yours.

Your final handiwork will look something like the example below:

[from-restricted]
;
; These are all the applications that you will require
;
include => app-cf-busy-off
include => app-cf-busy-off-any
include => app-cf-busy-on
include => app-cf-off
include => app-cf-off-any
include => app-cf-on
include => app-cf-unavailable-off
include => app-cf-unavailable-on
include => app-calltrace
include => app-callwaiting-cwoff
include => app-callwaiting-cwon
include => app-dialvm
include => app-directory
include => app-dnd-off
include => app-dnd-on
include => app-echo-test
include => app-recordings
include => app-speakextennum
include => app-speakingclock
include => app-userlogonoff
include => app-zapbarge
include => app-vmmain
include => ext-group
include => ext-fax
include => ext-meetme
include => ext-findmefollow
include => ext-paging
include => ext-queues
include => ext-test
include => ext-local
include => parkedcalls
;
; ###### OutBound Routes ##########
; # Below are all outbound routes #
; #################################
;
; New outbound restricted routes]
include => outbound-allroutes-custom
include => outrt-001-PSTN
include => outrt-002-SPA3K
include => outrt-003-Oztell
include => outrt-004-Pennytel

include => outrt-005-TeleGlobal
include => outrt-006-Astratel
include => outrt-007-MyNetFone
include => outrt-008-SpanTalk
include => outrt-009-VoIPBuster
include => outrt-010-Domestic
include => outrt-011-MobileAust
include => outrt-012-International

include => outrt-013-12Number
include => outrt-014-13N1800Numbers
include => outrt-015-USFree
include => outrt-016-e164
include => outrt-017-LA-Link
include => outrt-018-UK-Link
include => outrt-019-SingaporeLink
include => outrt-020-KualaLumpurLink
include => outrt-021-MalaccaLink

include => outrt-022-PenangLink
exten => foo,1,Noop(bar)
;
; end of [outbound restricted routes] 

Now add the following exten codes underneath that to finish it off.

exten => h,1,Hangup
exten => s,1,Macro(hangupcall)
exten => h,1,Macro(hangupcall)

  1. You may now comment out the outbound routes you do not want the restricted extensions to use.

E.g. If you comment out include => outrt-001-PSTN, the restricted extension cannot use PSTN.

  1. After you have done that, you need to go back to FreePBX and edit the extension that you want to restrict by change the context to from-restricted instead of from-internal.

Now go enjoy yourself with it.