For years, my Asterisk dial plan as been complicated because I use a combination of wire line carriers and VOIP providers to route the outbound calls. The wire line guys don’t want E.164 formatted numbers and the use, or inclusion of the area code is based on the three digit exchange you are calling from. Also, different area codes included in “metro calling” plans are a headache. In my case, I have also assigned private VOIP numbers to staff. I would like to assign the correct outbound called-id to these private extensions. Lastly, some VOIP providers allow you to alter the outbound caller-id if you prove to them you own the number. This is very helpful to always present the same company caller-id regardless of the outbound trunk used. To address this, I wrote a simple php script that queries a couple of mysql tables to correctly format the dial string. Along the way, I found an Asterisk addition that worked perfectly and allows you to parse json data in the dial plan! Even though it is two years old, it compliled with no problems on both CentOS x64 and Raspbian on the Raspberry Pi 2 board. The creator of this add in did a great job. This can be found at:
https://github.com/drivefast/asterisk-res_json
Since json is relatively compact and widely used, I wanted to give it a try, There are many ways to solve this problem, even initiating the call from the PHP script. But this is a simple example using json in the dial plan. The scripts are attached as well as a simple sql dump. Note that in the case if 6 digit routing such as area code + exchange, they should be entered in the “outbound” table first since the search is ordered by ID ASC. Also, the majority of the script is actually for logging, and may be removed for a production release. Also, the dial plan could be shortened but I kept it verbose for logging sake.
Example table structure: outbound
PHP script: get_route
Sample dial plan usage: dial