Redirecting outbound dialed numbers


Within our company we all have Local Lines assigned to our mobiles; and cost per minute to a local number is free, and the a mobile incurs cost.

We have a database that is populated with both the mobile and the local number.

I would like to look up this database on an outbound call (where the outbound call is to a mobile (starts with 02), and if a match is found, I would like to dial the number that is located within the database.

The first question is where would I reference this within FreePBX?


There is a pre-defined macro context that is called just before the number is dialed [macro-dialout-trunk-predial-hook]. By creating some dialplan in this context, you can use outbound number, in a SQL query (or API call) and redirect the call if the lookup returns a value. Additional reading:

Thanks Lorne

Ideally I need this to happen before the outbound trunk is selected, etc - as the trunk needs to be correct for the outbound number.

I thought perhaps from-internal-custom would be the right place?


I’ve had a bit more of a look at this, and keen for any insights on how I would achieve it.

I believe (and I might well be wrong); but it needs to be in from-internal-custom; to ensure it happens early on, to ensure the outbound trunk that is selected is the correct outbound trunk for the actual number that is to be dialed.

An an example, the user is going to call 027 987 1239; but I will require FreePBX to dial 06 865 7494.

I’m also not sure how I override the dialed number.

Any and all ideas are welcome.


If someone were to commission us to do this this here in support, I would use [macro-dialout-trunk-predial-hook]. I would perform a lookup on the outbound number and if a replacement is found, I would send the call back to the [from-internal] context with the new extension. For fail-safe, I would also set a variable to ensure there is a mechanism to prevent the same call from being looked up more than once and end up in a loop.