Fixing inbound caller id (CID) so number can be redialed

My outbound trunk is in the UK and hence international numbers start with 00.

When I get calls from the US on my UK trunk, I am seeing the caller ID like this: 01NXXNXXXXXX. It’s not possible to call that back.

I have a US trunk which is inbound only. Similarly, when I get calls on my US trunk, I get 1NXXNXXXXXX and I can’t call those back either! (I use the UK trunk to make the outbound calls, and yes, this is cheaper for me).

Is there some way to modify the inbound caller ID when it matches a pattern so I can fix it up so it can be dialed back out?

I suppose I could match the odd looking phone numbers on the way out and correct it in an oubound rule but this seems somehow wrong and also means I can’t easily copy it to a directory without some editing.

Hi,

You can add this contexts to your extensions_custom.conf file in order to change it:

[from-uk-trunk]
exten => _X./_01NXXNXXXXXX,1,Set(CALLERID(num)=0${CALLERID(num)})
same => n,Goto(from-pstn,${EXTEN},1)
;To Avoid mistakes if the caller id is not in 01NXXNXXXXXX pattern
exten => _X.,1,Goto(from-pstn,${EXTEN},1)

[from-us-trunk]
exten => _X./_1NXXNXXXXXX,1,Set(CALLERID(num)=00${CALLERID(num)})
same => n,Goto(from-pstn,${EXTEN},1)
;To Avoid mistakes if the caller id is not in 1NXXNXXXXXX pattern
exten => _X.,1,Goto(from-pstn,${EXTEN},1)

You can adapt it to your needs. Please note that you need to reload the dial plan on every change in the contexts.
After adding it to the extensions_custom.conf file, please reload the dial plan from the linux console like this:

rasterisk -x'dialplan reload'

After reloading the dial plan, please change the context in your US and UK trunks accordingly:

context=from-uk-trunk

context=from-us-trunk

Finally, adapt your inbound rules or add a general inbound rule to accept the calls.

Thank you,

Daniel Friedman
Trixton LTD.

Thanks Daniel.

I was not able to make this work with exactly what you sent but it has helped me get closer.

First it’s / and not \ that separates the extension from the caller id number.

I see you are inserting this in from-pstn, what about from-trunk or from-trunk-trunkname? In fact, what seems to be happening is that from-trunk-sip-trunkname is being called by default (where trunkname = the name of the trunk). This seems to partly work:

[from-trunk-sip-US-fixcid]
exten => _.,1,Set(CALLERID(num)=CALLERID(ANI))
   same => n,Goto(from-trunk-sip-US,${EXTEN},1)

then added context=from-trunk-sip-US-fixcid to the PEER details for the trunk. Note that for the moment I haven’t even matched on the caller id yet, I just wanted to make sure it was working.

Without this, when I call my US number from my UK mobile phone, I see the caller id start with 07… like it was a UK number.

Using the ANI is more interesting. By doing the above, I get a number that starts with a countrycode (44) in my case, no +, no 00, the mobile number looks like 447… Ok so I tried the following:

exten => _.,1,Set(CALLERID(num)=00${CALLERID(ANI)})

but it doesn’t work at all. When I call it from my UK mobile number, I get a caller id string that starts like 07…, no 44, and the 00 is not there! I tried several variations on this and I found no way to prepend the 00. Even just setting:

exten => _.,1,Set(CALLERID(num)=${CALLERID(ANI)})

you would think I would get the same thing as the above, but nope, I am back to a caller id like 07…

so clearly there is something I don’t understand about appending strings in asterisk and about how the CALLERID() function works. I’m not sure what the difference is between ${CALLERID(ANI)} and just CALLERID(ANI). Can anyone shed some light on this?

Hi,

I have fixed my typo in my example, sorry for that, i have worked with another keyboard set. You do not need to change the context, just leave it like that, and the Freepbx dial plan will forward it to the right context. I do not think that you need to the use the ANI, because you are not using it in your dial plan. Please do not use the _. exten because it is not safe and you will get a warning every time you will run it.

Please provide a verbose logs of your incoming calls so I can determine what is your problem.
Use my example when you are pasting here the logs.

Thank you,

Daniel Friedman
Trixton LTD.

1 Like

Hi Daniel,

Log sent to you. Thanks for your help!

Michael

Caller-IDs arrive from the US without a 1, just the NXXNXXXXXX number. Other calls from outside the US arrive starting with a country code.

With the very kind help of Daniel we managed to get this working. Here’s what we did:

  1. in the trunk, add this to the PEER details (where mytrunk is the name of your trunk above in Trunk Name field:

    context=from-trunk-sip-mytrunk-fixcid

  2. in /etc/asterisk/extensions_custom.conf, add the following lines, again replacing mytrunk

    [from-trunk-sip-mytrunk-fixcid]
    exten => _X./_NXXNXXXXXX,1,NoOp(Caller ID is: ${CALLERID(num)})
    exten => _X./_NXXNXXXXXX,n,Set(CALLERID(num)=001${CALLERID(num)})
    exten => _X./_001NXXNXXXXXX,n,NoOp(Caller ID is now: ${CALLERID(num)})
    exten => _X./_001NXXNXXXXXX,n,Goto(from-trunk-sip-mytrunk,${EXTEN},1)
    exten => _X.,1,Set(CALLERID(num)=00${CALLERID(num)})
    exten => _X.,n,Goto(from-trunk-sip-mytrunk,${EXTEN},1)

Explanation line by line:

  1. create the new from-trunk-sip-mytrunk-fixcid context.
  2. _X. matches any DID number, then a /, then _NXXNXXXXXX matches a US style number in the caller-id, (could be any valid pattern). This line merely logs the current caller id.
  3. sets the new caller id and prepends 001 to US numbers
  4. now here’s the part I missed above, the caller-id has changed, so you must add 001 now to the caller-id match or the call falls through to voicemail or somewhere unknown! This line merely logs the caller-id after it has been edited. You can’t use ‘same =>’ here because IT’S NO LONGER THE SAME.
  5. again, matching the changed caller-id, now send the call back to the trunk. You need this line, you can’t let it fall through or it falls through to voicemail or somewhere unknown.
  6. this catches non-US numbers (or rather things not in the previous pattern sequence) and adds 00 to them
    7, sends them back to the trunk.

Now all calls come into the phone with 00 counry-code number and they can all be redialed.

Another thing that did not help was that my Siemens phone was set to UK mode which removed the 44 in front of numbers and replaced with a 0, hence really confusing the situation because I thought I was getting just a number starting with 0 when I dialed my US trunk!

A big thank you to Daniel who spent a couple hours on the phone with me this morning. I must say I have a better understanding of dialplans now!

1 Like