CNAM lookup alternative

Catalog of dial plans
Post Reply
uhf
Posts: 26
Joined: Sat Oct 30, 2010 3:05 am

CNAM lookup alternative

Post by uhf » Mon Dec 12, 2011 9:19 pm

Splitting this off from the other thread since I've drug it off the original topic enough already..

User jeffdoubleyou posted the following code for CNAM lookup using the pay service calleridservice.com

Code: Select all

CNAM_User = 'YOUR_USER_NAME'
CNAM_Key = 'YOUR_AUTH_KEY'

sys.Trace = false
sys.Log("Log message from default dialplan.")

if sys.In

   # Get caller ID
   name = req.Header.from.FromURI.User.to_s

   if defined?(CNAM_Key) && name =~ /^1?([2-9]\d\d[2-9]\d{6})$/
      url = "http://cnam.calleridservice.com/query?u=#{CNAM_User}&k=#{CNAM_Key}&t=html&n=#{name}"
      cnam = sys.WebGet(url,4).to_s
      sys.SetFromHeader(cnam || name, nil, nil)
   end
  
   # CONTINUE INBOUND ROUTING HERE

else

  # HANDLE OUTBOUND DIALING HERE

end
It's working for me, but I'm having trouble with trying to add in the CNAM Hash Table feature in the script that Mike Tellis provided. That is an extremely useful feature so I'd like to be to use it. I've tried all sorts of variations of trying to combine the two scripts with no success.

Any help greatly appreciated.

MikeTelis
Posts: 1582
Joined: Wed Jul 30, 2008 6:48 am

Re: CNAM lookup alternative

Post by MikeTelis » Thu Dec 15, 2011 3:45 pm

If you're referring to my Flexible dialplan Ver. 2, try:

Code: Select all

    if !(@cname = keys_to_ENUM(CNAM)[@cid]) && @cid =~ /^1([2-9]\d\d[2-9]\d{6})$/ && defined?(WP_key)
      url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fapi.whitepages.com%2Freverse_phone%2F1.0%2F%3Fphone%3D#{$1}%3Bapi_key%3D#{WP_key}'%20and%20itemPath%3D'wp.listings.listing'&format=json"
      if js = sys.WebGet(url,4).to_s
        @cname, dname, city, state = %w(businessname displayname city state).map {|x| js =~ /"#{x}":"([^"]+)"/; $1}
        if !(@cname ||= dname) && defined?(CNAM_key)
          url = "http://cnam.calleridservice.com/query?u=#{CNAM_User}&k=#{CNAM_Key}&t=html&n=#{@cid[1..-1]}"
          @cname = sys.WebGet(url,4).to_s
        end
        @cname ||= "#{city}, #{state}" if city && state
      end
    end
You'll need to provide WP_key, CNAM_User and CNAM_Key; the dialplan will try White Pages first and, if failed, try CallerIDService. The difference with previous version posted here is in &t=html key in the query (implemented by CallerIDService recently).

uhf
Posts: 26
Joined: Sat Oct 30, 2010 3:05 am

Re: CNAM lookup alternative

Post by uhf » Thu Dec 15, 2011 3:56 pm

Thanks, Mike. I want to leave Whitepages out of the code entirely to make things simpler, and because it returns a lot of false info for numbers on a couple of particular CLECs that call me often. I only want to use the calleridservice provider, and only if the CNAM isn't in the hash table. I can't seem to remove the whitepages stuff without breaking the whole script.

MikeTelis
Posts: 1582
Joined: Wed Jul 30, 2008 6:48 am

Re: CNAM lookup alternative

Post by MikeTelis » Thu Dec 15, 2011 5:25 pm

Code: Select all

    if !(@cname = keys_to_ENUM(CNAM)[@cid]) && @cid =~ /^1([2-9]\d\d[2-9]\d{6})$/ && defined?(CNAM_key)
       url = "http://cnam.calleridservice.com/query?u=#{CNAM_User}&k=#{CNAM_Key}&t=html&n=#{$1}"
       @cname = sys.WebGet(url,4).to_s
    end
Haven't tried it, just a thought ;-)

Post Reply