Hi Michael,
Good eye. I actually edited the fix_cidnam_plus entry a while back when it wasn’t working correctly for a DID that sends the ‘+’ at the beginning. The edited expression is below the original one in public.xml which is commented out. Now I don’t remember if the original expression was in there by default or if I pasted it in from somewhere due to my lack of experience with FreeSWITCH at the time, but the original regex wasn’t quite right since OpenCNAM does not accept the leading ‘1’. I was only worried about numbers with the leading ‘+’ since the other case is handled by the previous entry.
Your fix is certainly more elegant. When I start to feel like I’m becoming reasonably proficient with regexes, I subsequently wind up not doing anything with them for a long time and then almost forget what little I’ve learned. :)
I’ve been learning a lot about Linux and FreeSWITCH at the same time in the past months, it’s a lot of information for my aging mind to take in all at once. I really wish I could have done this 20 years ago!
Cheers,
- Phil
<extension name="outside_call" continue="true">
<!--make sure the module is loaded, or else loading it will kill our call!-->
<!-- Simple case: name=number or name is empty -->
<!-- and number is a 10digit (excluding optional leading 1), in nanpa nxx-nxx-xxxx form -->
<!-- will skipurl lookup if not a 10digit # (don't lookup INTL), and instead just query the SQL -->
<condition field="${module_exists(mod_cidlookup)}" expression="true"/>
<condition field="caller_id_name" expression="^${caller_id_number}$|^$"/>
<condition field="caller_id_number" expression="^1?([2-9]\d\d[2-9]\d{6})$">
<!-- action application="cidlookup" data="1$1"/> -->
<action application="cidlookup" data="$1"/>
<anti-action application="cidlookup" data="${caller_id_number} skipurl skipcitystate"/>
</condition>
</extension>
<extension name="fix_cidnam_plus" continue="true">
<!-- if the name starts with + followed by digits, strip the
+ and then pass the number -->
<!-- condition field="caller_id_name" expression="^\+(1[2-9]\d\d[2-9]\d{6})$"> -->
<condition field="caller_id_name" expression="^\+1?([2-9]\d\d[2-9]\d{6})$">
<action application="cidlookup" data="$1"/>
</condition>
</extension>
Michael Collins
Tue Jul 31 20:44:00 MSD 2012
Phil,
I have a question about this line from your trace:
Dialplan: sofia/external/4435551212 at 140.239.xx.x Regex (FAIL)
[fix_cidnam_plus] caller_id_name(4435551212) =~
/^\+1?([2-9]\d\d[2-9]\d{6})$/ break=on-false
Are you thinking that "4435551212" should match the regex in extension
"fix_cidnam_plus"? The reason I ask is that I think your regex may have a
small gotcha. It looks to my like you are making the leading "1" optional
by having "1?" in front of the rest of the regex. However, it looks to me
like the "+" is not optional, so unless the phone number is "+4435551212"
it won't match that regex. If the + is meant to be optional then the easy
way to test would be to add a "?" right after the "+":
<condition field="caller_id_name" expression="^\+?1?([2-9]\d\d[2-9]\d{6})$">
Of course, if you were banking on having the + in there then I'm all wet
and you can ignore me...
-MC
_____________________________________________
From: Phil Quesinberry
Sent: Tuesday, July 31, 2012 12:20 PM
To: 'freeswitch-users@lists.freeswitch.org'
Subject: RE: Setting effecting_caller_id_name
Ok, the problem here is that the variable caller_id_name contains the Caller ID number instead of the CNAM that was looked up. Is there a variable to look at and change for the CNAM info? Info shows the CNAM info in Caller-Caller-ID-Name but attempts to match on variations of that have failed. Obviously I’m missing some basic piece of info here but I haven’t been able to find it, even within the FreeSwitch book.
I’ve pasted a small section of the relevant console output below.
I should also mention that I’m doing this check within public.xml since I want it to apply to all incoming calls.
Thanks,
- Phil
2012-07-31 11:33:30.800571 [INFO] mod_dialplan_xml.c:485 Processing 4435551212 <4435551212>->4105551212 in context public
Dialplan: sofia/external/4435551212@140.239.xx.x parsing [public->outside_call] continue=true
Dialplan: sofia/external/4435551212@140.239.xx.x Absolute Condition [outside_call]
Dialplan: sofia/external/4435551212@140.239.xx.x Regex (PASS) [outside_call] ${module_exists(mod_cidlookup)}(true) =~ /true/ break=on-false
Dialplan: sofia/external/4435551212@140.239.xx.x Regex (PASS) [outside_call] caller_id_name(4435551212) =~ /^4435551212$|^$/ break=on-false
Dialplan: sofia/external/4435551212@140.239.xx.x Regex (PASS) [outside_call] caller_id_number(4435551212) =~ /^1?([2-9]\d\d[2-9]\d{6})$/ break=on-false
Dialplan: sofia/external/4435551212@140.239.xx.x Action cidlookup(4435551212)
Dialplan: sofia/external/4435551212@140.239.xx.x parsing [public->fix_cidnam_plus] continue=true
Dialplan: sofia/external/4435551212@140.239.xx.x Regex (FAIL) [fix_cidnam_plus] caller_id_name(4435551212) =~ /^\+1?([2-9]\d\d[2-9]\d{6})$/ break=on-false
Dialplan: sofia/external/4435551212@140.239.xx.x parsing [public->currently_running] continue=true
Dialplan: sofia/external/4435551212@140.239.xx.x Absolute Condition [currently_running]
Dialplan: sofia/external/4435551212@140.239.xx.x Action info()
Dialplan: sofia/external/4435551212@140.239.xx.x Regex (FAIL) [currently_running] caller_id_name(4435551212) =~ /^Currently running a lookup/ break=on-false
Caller-Direction: [inbound]
Caller-Username: [4435551212]
Caller-Dialplan: [XML]
Caller-Caller-ID-Name: [SMITH,JOHN]
Caller-Caller-ID-Number: [4435551212]
Caller-Network-Addr: [140.239.xx.x]
Caller-ANI: [4435551212]
Caller-Destination-Number: [4105551212]
_____________________________________________
From: Phil Quesinberry
Sent: Thursday, July 26, 2012 10:29 PM
To: 'freeswitch-users@lists.freeswitch.org'
Subject: RE: Setting effecting_caller_id_name
The reply is different each time, depending upon the number being looked up. So, I just want to look at the first part of the string. If FS can’t do a regex match without the trailing $, I’m guessing there’s a way to just do it in XML.
I’ll try and see what I can find after the storm passes unless you have a better idea, I need to shut this computer down right now.
Thanks,
- Phil
You can just not use a regex.
Do you need to escape the spaces?
Brian Foster
Endigo Computer LLC
_____________________________________________
From: Phil Quesinberry
Sent: Thursday, July 26, 2012 5:46 PM
To: 'freeswitch-users@lists.freeswitch.org'
Subject: RE: Setting effecting_caller_id_name
If you put the $ at the end then it will try to match the entire string instead of just the beginning of it, which won’t work in this case. Is there a way to match just the beginning of the string in FS?
Thanks,
- Phil
You need a $ after 'lookup' for it to be a regex.
Brian Foster
Endigo Computer LLC
_____________________________________________
From: Phil Quesinberry
Sent: Thursday, July 26, 2012 3:59 PM
To: 'freeswitch-users@lists.freeswitch.org'
Subject: Setting effecting_caller_id_name
And while I’m asking dumb questions…
When doing CNAM dips from opencnam.com, often you get a result of “Currently running a lookup for phone ‘xxxxxxxxxx’… on incoming calls, typically for wireless or other unknown name callers and I wanted to change that to “Wireless/Unknown” Since caller_id_name is apparently read-only, I am attempting to set effective_caller_id_name. I put the following in public.xml right below the “fix_cidnam_plus” entry, in other words after a CNAM lookup has been performed.
<extension name="fix_currently_running" continue="true">
<condition field="caller_id_name" expression="^Currently running a lookup">
<action application="set" data="effective_caller_id_name=Wireless/Unknown"/>
</condition>
</extension>
If I crafted my regex properly, then it should be matching on the first part of the string and setting the variable appropriately. Is ‘effective_caller_id_name’ the variable I should be setting?
Many thanks,
Phil Quesinberry
Q Systems Engineering, Inc.
Electronic Controls and Embedded Systems Development
(410) 969-8002
http://www.qsystemsengineering.com