Incoming routing based on DID

Hi All,
I have a pri link with this number pattern: 56789XXX.
I want to route incoming calls based on XXX that caller dials, to the extension number XXX.
How can I do this in FreePBX?

Inbound route let’s you set the destination directly to an extension

emmm how?
I want if someone dials 56789120, exten 120 will get the call.
if someone dials 56789150, exten 150 will get the call.

If you are sure, please tell me how?

The easiest way, without the need to code it yourself if you would like to do it programatically, would be to create one inbound route per DID, that is, for every DID you want directly routed to an extension, create an inbound route and set the DID to the desired number and destination to the desired extension. That’s it.

Thank you. But we have about 500 extens.
what about coding? I have to create custom destination?

I’ve never done coding myself on asterisk, but I think I remember reading about a custom context that is already included that you could adapt for your specific scenario. Maybe someone else can chime in and remind you the name of this custom context.

You can e.g. add context=from-sip-provider to your trunk, and then add this to your extensions_custom.conf:

exten => _56789XXX,1,Goto(from-did-direct,${EXTEN:-3},1)

The [from-sip-provider] is an arbitrary name, the from-did-direct context is built into FreePBX to do what you require.

Explained more in detail here:

or here:

1 Like

You could also use the bulk handler and a bit of text manipulation to create the routes in inbound routes. If it were me, I would create the first route and export to CSV. I would then use a scripting language (I use AutoIT mostly) to take the single line of data and create a new CSV with all 500 extensions. This way I have all of the routes programmed into the PBX in the event somebody were to leave the company or something and I needed to do something different later.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.