TUTORIAL Custom trunks for custom applications

Joined
Feb 22, 2008
Messages
152
Reaction score
0
This is more of a tutorial than a question. I did a lot of :banghead: trial-and-error getting this figured out, so I wanted to document it somewhere (to benefit the whole PiaF community).

Background: I'm trying out VoicePulse for some of my outbound calling, but I want to use their "least cost" automatic routing function. In short, they provide some code to insert into your dialplan that does a cost lookup in real-time as the call is placed providing the per-minute charge for the call, allowing you to automatically route a call to another provider if the per-minute price is better. Their application code is available, but integrating it with a system while still using FreePBX for administering the system as a whole is not obvious (and not easy).

This technique is more universally applicable if you want to put just a little custom code in your system, but don't want to make everything else hard to maintain. I haven't completed the whole Voicepulse integration, but I've got a clean way to call custom code when dialing out through a trunk.

First, create a Custom Trunk in FreePBX
Browse to your.pbx.ip.address/admin and select Trunks. Click on "Add Custom Trunk." Set your Outbound Caller ID (I'm not sure if it will be used as configured, but it can't hurt) and, if desired, the Maximum Channels. For Dial Rules, make sure you don't accidentally pass a number without an area code by including the rules 1+NXXNXXXXXX, 1512+NXXXXXX (where 512 is your local area code). If you use a dialing prefix, you can add a 9| in front of the patterns to strip the extra digit, if desired. Finally, the Custom Dial String for this trunk is:

Local/$OUTNUM$@leastcost-custom

The "$OUTNUM$" token inserts the number dialed into the dial string. I used the context name "leastcost-custom," but you can call your context anything you like, but include "custom" in the name. Save the trunk and apply the settings.

Next, Create the Custom Context to handle the calls
Select "Tools" in FreePBX and go to "Config Edit" to add the custom context. Select the file "extensions-custom.conf" and add the following before the [from-internal-custom] context:
[leastcost-custom]
;exten => _X.,1,Dial(SIP/arrivaltel/${EXTEN},120,tr)
exten => _X.,1,Dial(IAX2/voicepulse1/${EXTEN},120,tr)
exten => _X.,2,Hangup

(Note that I have a commented out line for a SIP trunk, but I'm actually using an IAX2 trunk.)
Don't forget to click Update to save your changes and re-read config to apply the settings.
For the moment, this does nothing more than place the call out through the IAX2 trunk called voicepulse1 (the same name used in the "Trunks" section of FreePBX) but any arbitrary code can be inserted here, including routing to the least cost code from VoicePulse. I plan to update this post once I have that working.

Finally, Configure (an) outbound route(s) to use the trunk
Set this trunk as the only one for one of your outbound routes for testing. Once you are sure the code is working correctly, add the trunk to whatever outbound routes you please. Be sure that any Dial Patterns passed by the routes will be valid after being processed by your trunk Dial Rules.
 

Members online

Forum statistics

Threads
25,821
Messages
167,814
Members
19,247
Latest member
mdauck
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top