Caller ID match and replace

Let say an extension calling out with caller id = 12345 there’s a condition on the dial plan that search for cid = 12345 and if found it will be replaced with 00000.

There are 100+ cid that needs to be matched so there will be a possible need of file where a list of cid stored and their respective equivalent value to be replaced with.

Thanks in Advance!

If the Id behind is the replacement of an internal cid of the stations with a cid for external use and the stations are either SIP or IAX2 based You may achieve this by simpy setting up a channel-variable using setvar in the appropriate config file.

If You’re using other CHANNEL-technologies or got other ideas behind the easiest way (for usage within the dialplan) should be using a dfatabase backend for the pairs. This could be the builtin astdb or any other database of Your choose which You than may access and query by ODBC (res_odbc.conf and func_odbc.conf)

Hi Olaf, thanks for your reply.

It will be an internal replacement, can you please show an example for this so that i can have an idea.

As I mentioned it involves an anticipated 100+ cid that needs to match and replace, so i suppose it will need to have a file that holds the anticipated cid with respective replacement cid that needs to be replaced.

Letts assume You have a sip peer defined in the following way:

[100] callerid=Test <100>

Then You may do the following:

[100] callerid=Test <100> setvar=extCID=12345

Afterwards You may use this in Your extensions in a way like

and You’re done.
The same idea works when storing the information in a database (ARA or something like this).

Thanks Olaf, but caller id will not be determined by extension, it will be read on the dialplan itself

Caller id will be determine by group or campaign not by extension, so i am looking at matching of cid using some sort of IF / ELSE statement inside the dialplan.

Flow is like this:

  • there’s an outbound call it will hit an specific dial plan
  • that will determine the outbound caller id (ex. 12345)
  • after grabbing outbound cid it will search for a match on the record:
    sample record: (either a txt or csv file that composes of 2 column)
    column1 | column2
    12345 | 19020001111
    67890 | 19020001112
    11223 | 19020001112
  • found match 12345 cid will be replaced by 19020001111
  • cid set to 19020001111, proceed with outbound call

CID records will be on a file so that it will be easy to manage especially if you have massive caller id’s and it will be messy on the dialplan

And how do You want to achieve this determination? What is the criteria why a special call gets a 12345? And: Is the external CID for the caller id stable over tome or not. 'cause if it’s stable I didn’t got the clue yet why You’ll need a different (internal) caller id.

BTW: Working with (Text)Files for reading in Asterisk is possible but not really efficient as You would need to read the file sequentially. You would ne more efficient if You store the mapping in any kind of database and make a index-based lookup there (assuming Your mapping is unique)

This is some sort of caller id control before going to voip provider, since there’s a lot of our client assigning random caller id’s wherein there are allocated caller id for them, the purpose of this is to make sure their outbound calls are assigned with their correct caller id since our provider requires correct cid being allocated to us, unless it will be declined.

Here’s my sample dialplan:

exten => _X.,1,Set(CDR(userfield)=${CALLERID(num)})
exten => _X.,n,Set(detectedcid=${CALLERID(num)})
exten => _X.,n,GotoIf($[${detectedcid} = 12345]?acquiredcid12345,s,1)
exten => _X.,n,GotoIf($[${detectedcid} = 67890]?acquiredcid67890,s,1)

; No matched CID - passthru
exten => _X.,n,Set(CALLERID(num)=${CALLERID(NUM)})
exten => _X.,n,AGI(callout.php,1)

exten => s,1,Set(CALLERID(num)=19020001111)
exten => s,n,AGI(callout.php,1)

exten => s,1,Set(CALLERID(num)=19020001112)
exten => s,n,AGI(callout.php,1)

If cid 12345 , will replace with 19020001111
If cid 67890 , will replace with 19020001112
if none match will passthru (just for the sake of test if matching works)

This also use sequential, and will require a lot of line if in case my cid matching will be 100++

1 Like

Ok, but Your approach seems to be a bit inconsistent:

If Your client delivers a more or less random CID how would You - using Your dialplan-snippet as the example - detect the right “cid translation” whenever random cids are used by Your clients ?

In other words: Do You have any criteria allowing You to identify the client in a unique way ? If so, You should use this.

BTW: How are the clients administered ?

Yeah it’s a bit unusual, we have to manually look on the running logs first what they are sending then we can match and replace it then.

Managed to make it work! thanks anyway Olaf, appreciate your help.