Sam calls Julie's direct dial line and because she's not at her desk (and because of a follow me rule) the call is forwarded to her mobile.

FreePBX forwards the call through the correct outbound route and everything functions as it should except for the CID that is presented on Julie's phone.

Since Sam is calling from a local mobile 07123456789, FreePBX is passing his CID to our outbound carrier without the international dialling code - this is causing a host of unpredictable CID's to appear on Julie's phone.

It's the network that takes care of presenting the "correct" CID - but only if our carrier has the number in the correct format to begin with.

For CID's to be passed on correctly, our outbound provider requires that all numbers be sent through with the international dialling code.
Eg: 447123456789.

How can I tell FreePBX that:

IF a call is being forwarded
and IF it is 11 digits long
and IF it starts with 07 or 020
CHANGE the CID by stripping the leading 0 and add 44.

Yes, our outbound carrier does allow us to send any CID through.

To clarify - FreePBX is sending Sam's CID through.
But because it is sending it as 07123456789 it is showing up (most of the time or not at all) on Julie's phone as +7123456789.

I need the CID to be sent as 447123456789 for the carrier and networks to translate it to 07123456789.


According with your description, CALLERID(num), should be changed if it matches a certain structure. That suggests using regular expressions.

In Asterisk: The Definitive Guide, it is described how to manipulate strings in order to get a new string from regular expressions

expr1 : expr2

This operator matches expr1 against expr2, where expr2 must be a regular expression.[92] The regular expression is anchored to the beginning of the string with an implicit ^.

If the match succeeds and the pattern contains at least one regular expression subexpression—\( ... \)—the string corresponding to \1 is returned; otherwise, the matching operator returns the number of characters matched. If the match fails and the pattern contains a regular expression subexpression, the null string is returned; otherwise, 0 is returned.

I have checked in Online regex tester an debugger that your conditions can be represented by the regex 0((7[0-9]{9})|(20[0-9]{8})).

So, you could try to get the new string inside the FollowMe part of the dialplan in something like:

Set(new_caller_id = 44$[${CALLERID(num)} : 0\((7[0-9]\{9\})|(20[0-9]\{8\})\)]) 

Note that I have put a first "\" before the first "(" to isolate the part of the string we have interested in and concatenate it with 44 in the way it is described in the guide. The other "\" will serve to escape the "{" and "}", that serve in regular expressions as multipliers but that have a special meaning to asterisk (they delimitate variables). I think backslashes to escape curly brackets are necessary in asterisk, byt I'm not sure (sorry, I cannot do now any tests until next weekend).

If the caller id does not match the regex, new_caller_id will be "44" and the string you are searching, otherwise. You could use something such

Set(CALLERID(num) = ${If($[${new_caller_id} = 44]? ${new_caller_id} : ${CALLERID(num))})

I hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.