Incoming CallerID: 10 digits and 11 digits

I have 2 carriers who are passing on different CallerID formats to me: one using 10 digits and the other use 11 digits (1+phone number).

This creates a problem for CallerID retrieval from MySQL database for Caller Names.

Does anyone know a way to unify the incoming CallerID format, or should FreePBX build such a option for inbound routing?

(not for same reason as you) was to write a script called fixup-cid.php and put it in the agi-bin directory. i then called it from the extensions_custom.conf from the custom inbound context, and canonicalize the CID by stripping the leading ‘1’ if present (even worse, one of my providers prefixes the CID with ‘+1’, which I gather is E164 format, so I strip the “+” too…)

you can do as dan describes. You may want to consider writing it in asterick cli commands for something that lite weight though just to lower the overhead. Of course if your system is very quiet, the cpu cycles are cheap…

Thanks, all. I will give a try.

i am in u.s., using an european voip trunk for outbound. for inbound i use ipkall.
dial plans are configured and work quite nicely, however i have one daunting issue with CID.

because the voip provider is in europe as mentioned, i have to send 11 digits (ie, 1NXXNXXXXXX) for it to pass the CID properly. for example, if i send a 10-digit number, say (822) 352-9999, it will either take it as a bad number (so sending out the default company CID instead) or at best, take it as a number from seoul, korea (+8223529999 where 82=country code, 2=city code).

luckily, i can control CID’s at both trunk and extension level when any of my extensions call out, so no problems there.

however, incoming calls (ipkall sends me 10-digit CID) routed via followme (which uses that european trunk to forward calls) to outside pstn/mobile numbers, would yield and pass 10-digit CID. —> results in another cigarette bud.

  1. now the first obvious challenge is to covert all or some of the incoming CID’s to 11-digit format by adding 1 in front.
  2. also, if i were to add a u.s. trunk which would take 10-digit CID’s only, then what?
  3. i suspect solutions are likely to be out of freepbx gui range, thus requiring some sorta scripts or something. can this be taken care at gui level somehow, if not now, in the future?


you can massage incoming CIDs by sending all incoming calls to a small custom context prior to sending them on their way to from-pstn. You can massage all outgoing CID information by writing a custom context and hooking into the outbound dialing context flow creating a macro named: “macro-dialout-trunk-predial-hook” which will be called prior to all calls being dialed and then you can examine what trunk it is going out of, what the CID looks like and how you may want to modify it, etc.

thanks, philippe.
i think i get what you’re saying but i have no idea how to go about fixing it.
you see, i use freepbx because i’m no coder.
show me bit more?

How to change incoming CallerID

You’re welcome! :slight_smile:

thanks wise for the good documents. and philippe, i’ll worry about u.s. trunk later :-o

  1. please take a look at the below code, see if it looks okay.

; this will add “1” in front of incoming 10-digit-US callerID
exten => _X./_NXXNXXXXXX,1,Set(CALLERID(num)=1${CALLERID(num)})
exten => _X./_X.,1, Noop
exten => _X.,n,Goto(from-trunk,${EXTEN},1)

  1. well, make long story short, putting that code in from-trunk-custom did not work as first few lines of CLI output shown below.

    – Executing Set(“SIP/”, “__FROM_DID=12064249999”) in new stack
    – Executing Gosub(“SIP/”, “app-blacklist-check|s|1”) in new stack
    – Executing LookupBlacklist(“SIP/”, “”) in new stack
    – Executing GotoIf(“SIP/”, “0?blacklisted”) in new stack
    – Executing Return(“SIP/”, “”) in new stack
    – Executing GotoIf(“SIP/”, “1 ?cidok”) in new stack
    – Goto (from-trunk,12064249999,5)
    – Executing NoOp(“SIP/”, “CallerID is “SEATTLE WA” <3602813333>”) in new stack
    – Executing Set(“SIP/”, “FAX_RX=disabled”) in new stack

note all of my inbound calls are from IP Kall (no trunk, only DID) and they forward pstn calls like this: sip/12064249999@my_ip_address.

which file should i modify? from-sip-external?

thanks again!