Outbound Routing Based on Caller ID

I know you can control your outbound routing based on the extension by the following method:

1NXXNXXXXXX/1000 Would force extension 1000 out over this route if it was above any other suitable routes.

How can I do that using the caller ID instead of the extension number??
I have searched and searched for this but I cannot find an answer!


There is a module called custom-contexts that would fix that for you, the down side is you need to be veryu well versed in how FreePBX works before you use it…

Thanks for the reply - I had noticed a few references to that custom-contexts module here and there.

I was a bit reluctant to install it but i guess I can set up a VM Asterisk and have a look at it there if you think it’s a possible solution.

Any other suggestions would be greatly appreciated.

After a lot of reading and expecting a lot of failures, you will usually get to success. ( I did;-) )

Good Luck.

Any other ideas guys - the custom-contexts module is not availabe for my version of FreePBX.

Please Please - I really need to get this working!!

Up-dateing you FreePBX is only a few clicks away, no?

What version are you using?

I believe I am using the latest Asterisk (Ver.

What version of freepbx, custom contexts works fine wit 2.10 the latest version.

Humm when I went to install customcontexts-2.8.0rc1.1.tgz FreePBX warned me as follows:

Custom Contexts cannot be installed:

A FreePBX version below 2.8.0alpha1 is required, you have 2.10.0

Please try again after the dependencies have been installed.

Any ideas?

Don’t try and upload it from the local machine, just “check Online” from the module admin page.

Thanks for the replies guys.

Phillippe, I see your sentance

“If the call came from outside the system such as a forwarded call, then the CDI field will apply the the CID that the call came in with and route it accordingly”

But I am still not sure how to use this to select the outbound Route.

So I have several Legacy phone systems sitting in a cage in a colo, connected to my Asterisk via Pri’s we created with a Redfone. The Legacy extensions outbound calls are pushed through the Asterisk and out to the SIP provider. So I still can’t figure how to push the calls over particular outbound routes based on the caller ID generated in the legacy system. 1NXXNXXXXXX/1000 this works for a local extension 1000 on the Asterisk but if I were to give that extension caller ID of say 1231231234 1NXXNXXXXXX/1231231234 does not work. (obviously) but is there a switch or something that can be used here to make it work? Then if so will it work with an extesnion caming in from the Legacy system?

Thanks for the help.

Ok I got it installed like you said but it’s a bit much for me I don’t understand how to use that.
Anyway the reson I needed has gone to be honest. - What I was needing it for was to route faxes out over our SIP providers T38 rate deck but we have just came to the conclusion (again)that Faxes and SIP are a complete waste of time, yes you might get away with sending a few here and there but you hook up a medical facility to an ATA (never mind running it through an Asterisk) and start routing dozens of 50 - 60 page faxes everyday - forget about it as far as we can see.


yes faxes can be a bit of a challenge though if you are doing end-to-end T38 with a proper carrier that can always route those out their end correctly, I’ve heard it can be pretty reliable. You may want to ping Tony on this as I think they have a solution which might meet the need.

Anyhow … that was a bit of a tangent. Getting back to the question on CID routing, the CID field will do both. If the call is originated from “inside” the CID field is going to be the extension as you pointed out and that is what is going to be used in the routing decision. If the call came from outside the system such as a forwarded call, then the CDI field will apply the the CID that the call came in with and route it accordingly.

As far as custom context, I’m not sure how that would apply at all in this scenario unless there is something in that module that I have long forgotten?

I can tell you that faxing from an ATA with Asterisk works fine in the Pharmacy of a large psychiatric hospital (I never run call to that client, I always worry they won’t let me leave). As Philippe pointed out, you must have end to end t.38.

My company is a Schmooze partner and we use their FAX gateway that takes that acts as a t.38 gateway and terminates the calls on a PRI.

Hi I have came across another use for this if I could figure it out.
Any help you be greatly appreciated:

Here’s the scenerio:
I have a Legacy phone system connected to my Asterisk via a back to back Pri. The Legacy extensions outbound calls are pushed through the Asterisk and out to the SIP provider.
I would like to be able to select the Outbound Route in the FreePBX based on the Caller ID generated by the extension in the legacy system.

I see that I can do this with an Asterisk extension using the extension number, for example 1NXXNXXXXXX/1000 this works for Asterisk extension 1000
Is there any way to do something similar but using the caller ID instead of the extension number?

If it’s not routing based on the incoming CID then you would have to provide a trace to see more details why.

When a call comes in, if that call is forwarded in any form, it should maintain the CID it came in with at the point where the outbound route is being selected.

The outbound routing code generated simply routes based on target number and CID when you configure it that way. If your CID is not in the exact same format as you have specified it won’t work. For example if your CID comes in an e164 format and you have not corrected it but try to route it out based on a 10 digit format, it won’t recognize it.

The reason that extensions route on their extension numbers when a call is originated instead of routing on their outbound CID, is that the extension number IS their CID (from an Asterisk perspective) at the time the routing decision is made and it is not until further down in the dialplan that a choice is made to determine if we should be displaying a different external CID and which one.