Manipulating incoming CID

Hi Folks,

I’ve read hours and hours of posts and make slow progress, but I’m stuck now and would be grateful for any help.

What I want to do seemed simple for me:
If a incoming CID starts with a 0 replace the zero to 0049.
If it starts with a number prepend 0049621.

That’s it!

What I did, was adding a new context in the extensions_custom.conf:

[from-trunk-international]
exten => _ZX.,1,Set(CALLERID(num)=0049621${CALLERID(num),1})
exten => _0ZX.,1,Set(CALLERID(num)=0049${CALLERID(num):1,1})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)

Then I changed in the trunk settings to start with this context.

It ended up with me calling asterisk and my number was something like 0171…
So what I expected was: 0049171…
But I got: 00496210171…

So apparently it uses the very first entry.
But _ZX. shouldn’t match 0171.

Any hints highly appreciated.
Mic

Logs, always logs are useful

If it was me, I’d start with the code example “from-trunk-e164-us” in the /etc/asterisk/extensions.conf file.

The first three or four lines show you how to manipulate the DID, the next four (I think) show you how to manipulate the Caller ID.

You’re not far off, but the e164 example is actually pretty good. Create your [from0trunk-international] in /etc/asterisk/extensions_custom.conf. If you want to post your code before you try it, go for it.

Try:

[from-trunk-international]
exten => _./_ZX.,1,Set(CALLERID(num)=0049621${CALLERID(num)})
exten => _./_0ZX.,1,Set(CALLERID(num)=0049${CALLERID(num):1})
exten => _./_X.,n,Goto(from-trunk,${EXTEN},1)
exten => _.,1,Goto(from-trunk,${EXTEN},1)

Edit: Changed the last line to a catch-all, so both international numbers and anonymous, etc. are passed unchanged.

I’m curious why you are doing this. Are you outside of Germany but also have a Mannheim number?

1 Like

Thanks for looking into it.

@Stewart1
Now the telephone doesn’t ring at all.

To satisfy your curiosity :wink:
I want to connect Bitrix (CRM) and the numbers there need to be international to do all the other stuff, like sending SMS.
And if the numbers don’t match, they are not attached to a customer’s file.

I’m curious, what _./ should do.

@cynjut
Tried first Stewart’s answer, as this seems to be faster. Now I’m digging into your info. Thanks.

@dicko
Will post them, after I’ve worked thru cynjut’s material.

Mic

Talking about logs …
… in which logs could I see the changes of the number?

The console, set to verbose 9, shows the wrongly manipulated number in the first lines (number changed for privacy).

raspbx*CLI> core set verbose 9
Console verbose was OFF and is now 9.
  == Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
-- Executing [620@from-trunk-international:1] Set("SIP/outUnity-00000002", "CALLERID(num)=+49621015251234567") in new stack
-- Executing [620@from-trunk-international:2] Goto("SIP/outUnity-00000002", "from-trunk,620,1") in new stack
-- Goto (from-trunk,620,1)
-- Executing [620@from-trunk:1] NoOp("SIP/outUnity-00000002", "Catch-All DID Match - Found 620 - You probably want a DID for this.") in new stack
-- Executing [620@from-trunk:2] Log("SIP/outUnity-00000002", "WARNING,Friendly Scanner from 192.168.20.1") in new stack
[2019-04-06 08:26:45] WARNING[10347][C-00000001]: Ext. 620:2 @ from-trunk: Friendly Scanner from 192.168.20.1
-- Executing [620@from-trunk:3] Set("SIP/outUnity-00000002", "__FROM_DID=620") in new stack
-- Executing [620@from-trunk:4] Goto("SIP/outUnity-00000002", "ext-did,s,1") in new stack
-- Goto (ext-did,s,1)
-- Executing [s@ext-did:1] Set("SIP/outUnity-00000002", "__DIRECTION=INBOUND") in new stack
-- Executing [s@ext-did:2] Gosub("SIP/outUnity-00000002", "sub-record-check,s,1(in,s,dontcare)") in new stack
-- Executing [s@sub-record-check:1] GotoIf("SIP/outUnity-00000002", "0?initialized") in new stack
-- Executing [s@sub-record-check:2] Set("SIP/outUnity-00000002", "__REC_STATUS=INITIALIZED") in new stack
-- Executing [s@sub-record-check:3] Set("SIP/outUnity-00000002", "NOW=1554539205") in new stack
-- Executing [s@sub-record-check:4] Set("SIP/outUnity-00000002", "__DAY=06") in new stack
-- Executing [s@sub-record-check:5] Set("SIP/outUnity-00000002", "__MONTH=04") in new stack
-- Executing [s@sub-record-check:6] Set("SIP/outUnity-00000002", "__YEAR=2019") in new stack
-- Executing [s@sub-record-check:7] Set("SIP/outUnity-00000002", "__TIMESTR=20190406-082645") in new stack
-- Executing [s@sub-record-check:8] Set("SIP/outUnity-00000002", "__FROMEXTEN=unknown") in new stack
-- Executing [s@sub-record-check:9] Set("SIP/outUnity-00000002", "__MON_FMT=wav") in new stack
-- Executing [s@sub-record-check:10] NoOp("SIP/outUnity-00000002", "Recordings initialized") in new stack
-- Executing [s@sub-record-check:11] ExecIf("SIP/outUnity-00000002", "0?Set(ARG3=dontcare)") in new stack
-- Executing [s@sub-record-check:12] Set("SIP/outUnity-00000002", "REC_POLICY_MODE_SAVE=") in new stack
-- Executing [s@sub-record-check:13] ExecIf("SIP/outUnity-00000002", "0?Set(REC_STATUS=NO)") in new stack
-- Executing [s@sub-record-check:14] GotoIf("SIP/outUnity-00000002", "2?checkaction") in new stack
-- Goto (sub-record-check,s,17)

It works!
This is how:

[from-trunk-international]
exten => _Z./_ZX.,1,Set(CALLERID(num)=+49621${CALLERID(num)})
exten => _[0-9]./_[0]X.,1,Set(CALLERID(num)=+49${CALLERID(num):1})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)

I’m puzzled why, but it seems to be something with the 0, that has to be put in brackets [0].
Which doesn’t make any sense, imho, as this is only one digit.

Anyway, I’m glad it works, and you helped me a lot.

Thanks!
Mic

Thanks for the update and I’m glad you have it working.

However, test with an anonymous (blocked) caller ID and also one from outside of Germany. I suspect that those calls will fail. If so, try adding a catch-all line at the end of your context. (Although such numbers won’t match a record in your CRM, I assume that you still want them to ring your phones.)

Another question: Changing an incoming caller ID from e.g. 86074502 to +4962186074502 is common for applications such as yours. But changing 86074502 to 004962186074502 (what you apparently asked for in your first post) would be very unusual, which is why I asked about your application. The first post didn’t have a + sign at all.

You are right.
A failover line would be helpful :wink:

“+” and 00 is, by my definition, synonym. :slight_smile:
My CRM can handle both.

One additional question concerning failover:

Are those rules basesd on the number “,1” and hence been checked in parallel?
So failover should be then 2?

Your initial ruleset rang no telephone at all.
And now no phone rings when an anaonymous call is coming in.
Whereas the caller thinks it is ringing, though.

After your existing 3 lines of code, try adding:
exten => _X.,1,Goto(from-trunk,${EXTEN},1)
and test both normal and anonymous calls.

I’m pretty sure that this last line will only get executed when neither of the first two lines matches.

You’re saying that if you do this with just _[0-9]./_0X.,1 it doesn’t match but _[0-9]./_[0]X.,1 does? I’m just curious because in all posts before this line had _[0-9]./_0ZX.,1 which means it was looking for 0 then 1-9 then 0-9 then anything, no limit. The other line no matter how you do it still just matches 0 then 0-9 then anything, no limit.

Sorry I was wrong!
It works with both 0 and [0].

But I’m puzzled anyway:
What effect does “_[0-9]./” have?

When checking with “dialplan show 0123456”, with the working set it shows 2 matches.
But it’s working correctly.

Using just “_ZX.” is shows the correct match in the console, but is not working in real life.

Here is what I mean:
raspbx*CLI> dialplan show 012345678@from-trunk-international

[ Context 'from-trunk-international' created by 'pbx_config' ]`
'_[0-9].' (CID match '_0ZX.') =>  1. Set(CALLERID(num)=+49${CALLERID(num):1})`   [pbx_config]
  '_[0-9].' (CID match '_ZX.') =>  1. Set(CALLERID(num)=+49621${CALLERID(num)})  [pbx_config]
  '_X.' =>          2. Goto(from-trunk,${EXTEN},1)                [pbx_config]

-= 3 extensions (3 priorities) in 1 context. =-

raspbx*CLI> dialplan show 012345678@from-trunk-international
[ Context 'from-trunk-international' created by 'pbx_config' ]
  '_0ZX.' =>        1. Set(CALLERID(num)=+49${CALLERID(num):1})   [pbx_config]
  '_X.' =>          2. Goto(from-trunk,${EXTEN},1)                [pbx_config]

-= 2 extensions (2 priorities) in 1 context. =-

Edit:
This is my final working set:
[from-trunk-international]
exten => _X./_ZX.,1,Set(CALLERID(num)=+49621${CALLERID(num)})
exten => _X./_0ZX.,1,Set(CALLERID(num)=+49${CALLERID(num):1})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)
exten => _X.,1,Goto(from-trunk,${EXTEN},1)

Still not know, what the Code is, that is before the slash.

_ = this is a pattern match
X = single digit 0-9
. = wildcard match any anything of any length

So, it is a pattern match starting with any digit 0-9 of any length. Basically all possible calls.

You first two lines, after the slash, use a Z which is 1-9. So between those two lines you are matching everything except numbers starting with 00.

Sorry for being unclear.

I mean the parts before the slash.
What are they for? Why are they needed?

Basically _X. is all numbers.
So it’s something like:
all Calls … wait but only those starting with 0 and
all Calls … wait but only those starting with two 0.

The bit before the / is the DID the bit, after the CID

Ah, I see, thanks for the clarification.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.