Freepbx dynamic routing module
Introduction
The script could be of help if you use:
- asterisk
- freepbx
- and need a way to control inbound call routing based on a database lookup or dtmf input.
This is a freepbx module and has no additional prerequisites. The module has been tested with mysql database.
This module allows you to send incoming calls to different destinations based on the result of a mysql query that can use special variables [NUMBER] which is substituted by callerid and [INPUT] which is substituted by dtmf input.
Additionally the dtmf input or mysql query result can be stored into named variables for later use. That would typically be on a further pass through a dynamic route (where those variables can be accessed in the subsequent queries using [VARIABLE-NAME] or in custom extensions where they can be accessed with the prefix DYNROUTE_ i.e. DYNROUTE_VARIABLE-NAME
This can be used to:
- play different annoucement to some callers
- send some callers into different IVRs or queues
- set queue priority for some callers
- ring different extensions based on recognised callerid
- have recognised customers received announcements in their own language
- request caller to input customer number and check against db
The following is just an example of how it could be setup to read the class of a caller from a database:
Example table mapping customers callerids to a priority +-----------------+-------------+---------------+ | calleridname | calleridnum | cust_priority | +-----------------+-------------+---------------+ | Customer Name 1 | 12345678 | top | | Customer Name 2 | 12345679 | important | | Customer Name 3 | 12345670 | normal | +-----------------+-------------+---------------+
Then in the freepbx query under dynamic route module set up a route which uses this query:
select cust_priority from calleridlookup where calleridnum like '%[NUMBER]' and length('[NUMBER]') > 4
and then set up some routing destinations in the options part of the screen where every value returned by cust_priority is mapped to a specific destination. Example:
- top -> rings an extension
- important -> sent to a queue
- normal -> sent to an ivr
the destinations can be anything that is allowable as a destination in freepbx. An option called default should be set to indicate where to route calls if database does not return any of the forseen values.The built in default destination is to hang up.
I have used this module to make an out of hours support IVR that requests users to input their support contract number and if it is valid asks them to input their contact number and then passes these values (and customer id which is looked up in the db) to a custom extensions which calls an AGI script to email/sms support personnel.
Implementation notes: this module takes code from calleridlookup and ivr.
Obtaining and installing
Download
The following files are not part of the install but are needed if you want to verify the gpg signature of the downloaded file:
GPG signature for dynroute-2.8.0.0.tar.gz
John Fawcett public key
Installation
- download the files
- (optionally) verify the files, for example: gpg --verify dynroute-2.8.0.0.tar.gz.sig
- in freepbx go to module administration and use upload module to add the downloaded file to freepbx modules
- under Inbound Call Routing section install the Dynamic routes module. If all goes well after install you will find the Dynamic routes menu item in freepbx in order to configure the newly installed module.
- Set up a new Route (see above).
- In the options part of the pagde add the various values that can be returned from the sql query or user dtmf input and the destination to use for each one. It is wise to define an option called "default". This is a catch-all option, since this will be used if a value returned from the db does not match any other option. If there is no default and the value returned from the db does not match any option, the call will be hang up.
- Ensure the database is populated with some data that can be used to test the routing.
- Under Inbound routes chose the newly set up dynamic route as the destination for an inbound trunk. Alternatively you can use the dynamic route as a destination from other modules (like ivr, day/night control etc.)
- Save and reload.
- Make some test calls, changing data in the database to affect the routing and check the calls are routed as expected.
Contact
john at gufonero.com
Last Modified: Thursday, 08-Mar-2012 23:17:57 CET