Need some help changing incoming caller ID

Mezz
Posts: 27
Member Since:
2009-01-21

Hi,

For some reason my telecoms provider has been messing around with the caller ids that we are receiving (no idea why I certainly didn't ask them to). Short story is they won't/can't change it back.

Some calls that I receive seem to drop the leading zero on international calls for no apparent reason. For example:

0091123456789

is received as:

091123456789

Fortunately I can work around it. What I need to do is check to see if the incoming caller id starts with "09" and append "0" to the front if this is true. I've looked around and pieced together some code based on the following URL: http://www.freepbx.org/support/documentation/howtos/how-to-change...

I'm using Trixbox 2.6.2.1, according to the URL (if I understand it correctly) I need to find out what context I'm using in zapata.conf which is:

context=from-pstn

Then change this to:

context=from-pstn-custom

Then in the extensions_custom.conf I add the following:

[from-pstn-custom]
exten => _X!,1,GotoIf($["${CALLERID(num):0:2}" != "09"]?numberok)
exten => _X!,n,NoOp(Changing Caller ID number from ${CALLERID(num)} to 0${CALLERID(num)})
exten => _X!,n,Set(CALLERID(num)=0${CALLERID(num)})
exten => _X!,n(numberok),Goto(from-pstn,${EXTEN},1)

My understanding is CALLERID(num):0:2 is a substring starting from char 0 - 2? If its not true it goes to the last line (numberok). Otherwise a print some 'useful' stuff to the screen to notify nobody in particular as I don't watch the terminal all day. Then I set the caller id to 0 + whatever the caller ID was. Finally the last line sends me back to the original from-pstn context?

The problem is when I do this all my call routing dies. Calls come in on the zap lines but won't ring anything. If you're a caller phoning in, all you get is silence. I know this must be something simple but I don't understand enough of asterisk to work this out myself.

Can anyone point me in the right direction?

Wayne Merricks



SkykingOH
Posts: 9541
Member Since:
2007-12-17
Wow, this is my code I wrote

Wow, this is my code I wrote several years ago. Where did you find this?

Everything is on the Internet.

0:2 is the first two characters of the string. This code checks for the 0 and adds if it is not.

so you could change the "09" to quote "00" and then code should add the extra 0 for you.

--

Scott

aka "Skyking"



Mezz
Posts: 27
Member Since:
2009-01-21
Can't use 00

Thanks for the quick reply. I can't use a simple 00 check as UK national numbers all start with a 0. However to my knowledge none start 09 that I will be interested in (theres bound to be some premium rate lines or call centres with 09 I guess).

Most of our calls come from India and Pakistan which are country codes 0091 and 0092 respectively.

I think the code is correct (I've triple checked for stupid { instead of ( errors). What I can't figure out is why it kills Trix call routing when I implement it.

Am I correct that the context I need is from-pstn?
Am I also correct that I need to change from-pstn in the zapata.conf to from-pstn-custom?
If thats true do I then need to add the code above at the end of extensions_custom.conf?

If that is all correct then I'm clueless (give me Java/C/PHP and a myriad of others any day). :\



SkykingOH
Posts: 9541
Member Since:
2007-12-17
Where did you put it in

Where did you put it in extensions_custom?

It should not effect anything in trixbox. For it to work the trunk has to be in the from-pstn-custom context.

--

Scott

aka "Skyking"



Mezz
Posts: 27
Member Since:
2009-01-21
Managed to fix this...

Apologies for the delay with replying. I wanted to spend enough time to try and figure this out instead of just firing off questions. I believe I have this working now.

For the record, having a trunk context of from-pstn is a bad idea with the default trix setup. Inside extensions.conf it already has some setup for from-pstn and will automatically try and load from-pstn-custom if it exists. In this case it then seems to get trapped in a loop which is obviously not good.

So after spending a few hours cleaning out the crap in zapata.conf (and figuring out what all the commands did) the changes to extensions_custom.conf worked fine. I did however later realise that sometimes the Caller ID was dropping both leading 0's for some calls which meant I had to add a bit more to the code from above. I apologise if this could have been done in a much easier way but it works for me:

[from-zaptel-custom]
exten => _X!,1,GotoIf($["${CALLERID(num):0:2}" != "09"]?checknozerozero)
exten => _X!,n,NoOp(Changing Caller ID number from ${CALLERID(num)} to 0${CALLERID(num)})
exten => _X!,n,Set(CALLERID(num)=0${CALLERID(num)})
exten => _X!,n,Goto(numberok)
exten => _X!,n(checkzerozero),GotoIf($[LEN("${CALLLERID(num)}") != 12)]?numberok)
exten => _X!,n,NoOp(Changing Caller ID from ${CALLERID(num)} to 00${CALLERID(num)})
exten => _X!,n,Set(CALLERID(num)=00${CALLERID(num)})
exten => _X!,n(numberok),Goto(from-zaptel,${EXTEN},1)

I have checked for typos but knowing my luck some will still be in that lot. As a quick explanation of what I'm doing here:
1. If the first two characters = 09 goto checknozeronozero
2. Display to terminal
3. Add a leading 0 to the caller id
4. Goto numberok
5. checknozeronozero: if the length of the caller id is not 12 goto numberok (12 just happens to be the normal length of international caller ids without 0s)
6. Display to terminal
7. Add two leading 0s to the caller id
8. numberok: Carry on with the rest of the dial plan

As an aside my Zapata.conf is correctly set for nationalprefix=0 and internationalprefix=00 but for some reason this doesn't always apply.

Thanks for the pointers



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.