www.homeseer.com    
 

Go Back   HomeSeer Message Board > Telephone,Text and Email Plug-ins > Telephone,Text and Email Integration Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old November 19th, 2014, 08:54 PM
tenholde tenholde is online now
Super Seer
 
Join Date: Jun 2002
Posts: 1,769
Reverse Web Phone Number Lookup

I'm developing an HS3 interface to a Panasonic PBX, and the unit I have will only pass to me the callerid phone number, without name.

I want to announce in real time via whole house Sonos speakers who the caller is while the phone is ringing, plus logging, etc.

I will access my home contacts information to get a name from a known phone number, but when I get a call from an unknown number, I'd like to do a web call providing the phone number and retrieving the name.

I know there are services with web APIs to do this. I talked to whitepages.com today, but they really do not have a service for such low volume 5-10 calls per day.

I do not mind paying a fee for the information, but it has to be reasonable for a low volume. $20 per month is not reasonable.

Anyone with experience with doing something like this?

tenholde
Reply With Quote
  #2  
Old November 19th, 2014, 09:14 PM
S-F's Avatar
S-F S-F is offline
OverSeer
 
Join Date: Jun 2012
Location: Accident MD 21520
Posts: 3,042
This is a shadow of why I gave up on the home PBX.

I suggest you check out the ObiHai forum. There are a lot of good ideas in the vein of your question posted there.
Reply With Quote
  #3  
Old November 19th, 2014, 10:26 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,724
Great idea Ed.
__________________
Don
Reply With Quote
  #4  
Old November 20th, 2014, 07:01 AM
sacarino's Avatar
sacarino sacarino is offline
Seer Deluxe
 
Join Date: Jun 2002
Location: Atlanta, GA, USA
Posts: 264
Quote:
Originally Posted by tenholde View Post
I know there are services with web APIs to do this. I talked to whitepages.com today, but they really do not have a service for such low volume 5-10 calls per day.

<snip>

Anyone with experience with doing something like this?
Yep. You want OpenCNAM - it's perfect for what you're doing... and it's free for low-volume usage.
Reply With Quote
  #5  
Old November 20th, 2014, 06:24 PM
tenholde tenholde is online now
Super Seer
 
Join Date: Jun 2002
Posts: 1,769
Quote:
Originally Posted by sacarino View Post
Yep. You want OpenCNAM - it's perfect for what you're doing... and it's free for low-volume usage.
Thanks, look like what I need. I'll start playing with it tonight.

tenholde
Reply With Quote
  #6  
Old November 21st, 2014, 04:16 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,724
Ed:

did you have any luck using OpenCNAM? I can't figure out the proper format.


Quote:
Originally Posted by tenholde View Post
Thanks, look like what I need. I'll start playing with it tonight.

tenholde
Reply With Quote
  #7  
Old November 21st, 2014, 08:47 PM
tenholde tenholde is online now
Super Seer
 
Join Date: Jun 2002
Posts: 1,769
This worked for me. I didn't supply userid nor authid, so it retrieved the result from cache.

Let me know how I can help.




Code:
 Public Sub MakeHttpRequest(ByVal Parms As Object)
        Dim BaseUrl As String = " https://api.opencnam.com/v2/phone/"
        Dim ParmArray() As String
        Dim Result As String
        ParmArray = Parms.ToString.Split("|")
        Result = SendOpenCNAM(BaseUrl & "3148425089")
        hs.WriteLog("OpenCNAM Test", Result)
    End Sub
    Function SendOpenCNAM(ByVal sURL As String) As String
        Dim strData As String = ""
        Dim tlRequest As System.Net.HttpWebRequest
        Dim tlResponse As System.Net.HttpWebResponse
        Dim tlStatusCode As Integer
        Try
            tlRequest = CType(System.Net.WebRequest.Create(sURL), System.Net.HttpWebRequest)
            tlRequest.ContentType = "text/html"
            tlRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"
            tlRequest.Method = "GET"
            tlRequest.Timeout = 1000
            tlRequest.AllowAutoRedirect = True
            tlResponse = CType(tlRequest.GetResponse(), System.Net.HttpWebResponse)
            tlStatusCode = tlResponse.StatusCode
            If tlStatusCode = System.Net.HttpStatusCode.OK Then
                strData = New System.IO.StreamReader(tlResponse.GetResponseStream()).ReadToEnd()
            Else
                Return ""
                hs.WriteLog("SendOpenCNAM", "HttpWebRequest Returned: " & tlStatusCode.ToString)
            End If
            tlResponse.Close()
        Catch ex As Exception
            hs.WriteLog("SendOpenCNAM", "HTTP Request Failed: " & ex.ToString)
        End Try
        Return strData
    End Function
Reply With Quote
  #8  
Old November 22nd, 2014, 12:21 AM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,724
Thanks Ed;

I was just trying to put the query in the browser address. I tried your code and got back the familiar


Nov-21 9:41:00 PM Warning VB.Net script exception(0), re-starting: Object reference not set to an instance of an object.
Nov-21 9:41:00 PM Event Running script in background: C:/HomeSeer HS3/scripts/reverselookup.vb

How are you imputting the number you want to look up?
Reply With Quote
  #9  
Old November 22nd, 2014, 09:16 AM
tenholde tenholde is online now
Super Seer
 
Join Date: Jun 2002
Posts: 1,769
Just threw that together to see how the interface works. Hard-coded the phone number into the code.

I have more work to do on handling exceptions and using the authid for deeper searches (if registered).

The code will eventually take a phone number as parameter, and return either a null string or the name associated with the phone number. Any exceptions will be displayed in the HS log.

The phone number will be received from my Panasonic PBX.

Are you by any chance using tenScripting? If so, where is the script failing?

tenholde
Reply With Quote
  #10  
Old November 22nd, 2014, 10:37 PM
tenholde tenholde is online now
Super Seer
 
Join Date: Jun 2002
Posts: 1,769
Here is a more complete Script called: GetCallerId

Here is the code:

Code:
Public Sub Main(ByVal Parms As Object)
        ''
        '' Script to test OpenCNAM processing
        ''
        ''  Specify the 10-digit phone number as the parameter 
        ''
        Dim ParmArray() As String
        '' Get test script parameter  (Phone Number)
        ParmArray = Parms.ToString.Split("|")
        '' Get Name from OpenCNAM and write to HS Log
        hs.WriteLog("CallerId Test", "P=" & ParmArray(0).ToString & "  N=" & GetFromOpenCNAM(ParmArray(0)))
    End Sub
    Public Function GetFromOpenCNAM(PhoneNumber As String)
        ''
        '' GetFromOpenCNAM     
        ''
        ''   Input:  10 Digit Phone Number (string)
        ''   Returns: Associated Name  (or blank, if no data or request fails)
        ''
        ''      First, a request is made to OpenCNAM without authorization codes   (no charge)
        ''      If no data retrieved, a second request is made using authorization codes   ($0.004 per request)
        ''
        Dim Result As String
        '' Validate parm is 10 digits (more error checking needed here)
        If PhoneNumber.Length <> 10 Then
            hs.WriteLog("GetFromOpenCNAM", "Supplied parameter not 10 digits exactly: " & PhoneNumber.ToString)
            Return ""
        End If
        '' Try without authorization codes
        Result = SendOpenCNAM(PhoneNumber, False)
        '' If failed, try with authorization codes
        If Result = "" Then Result = SendOpenCNAM(PhoneNumber, True)
        Return Result
    End Function
    Function SendOpenCNAM(ByVal sPhoneNumber As String, UseAuthentication As Boolean) As String
        ''
        '' SendOpenCNAM
        ''
        ''      Input:  Phone Number
        ''              Boolean to specify if authorization is to be used
        ''
        ''      Returns:  Associated Name (or blank if not fournd)
        ''
        Dim strData As String = ""
        Dim tlRequest As System.Net.HttpWebRequest
        Dim tlResponse As System.Net.HttpWebResponse
        Dim tlStatusCode As Integer
        Dim BaseUrl As String = " https://api.opencnam.com/v2/phone/"
        Dim AuthParms As String = "?account_sid=xxxxxxx&auth_token=xxxxxxxxxx"
        Dim sUrl As String
        sUrl = BaseUrl & sPhoneNumber
        If UseAuthentication Then
            sUrl = sUrl & AuthParms
        End If
        Try
            tlRequest = CType(System.Net.WebRequest.Create(sUrl), System.Net.HttpWebRequest)
            tlRequest.ContentType = "text/html"
            tlRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"
            tlRequest.Method = "GET"
            tlRequest.Timeout = 1000
            tlRequest.AllowAutoRedirect = True
            tlResponse = CType(tlRequest.GetResponse(), System.Net.HttpWebResponse)
            tlStatusCode = tlResponse.StatusCode
            If tlStatusCode = System.Net.HttpStatusCode.OK Then
                strData = New System.IO.StreamReader(tlResponse.GetResponseStream()).ReadToEnd()
            Else
                Return ""
                hs.WriteLog("SendOpenCNAM", "HttpWebRequest Returned: " & tlStatusCode.ToString)
            End If
            tlResponse.Close()
        Catch ex As System.Net.WebException
            If ex.Message.Contains("(404)") Then
                '' 404   No Data for Phone Number, return blank
                Return ""
            End If
            If ex.Message.Contains("(401)") Then
                '' 401   Not Authorized, account codes invalid
                hs.WriteLog("SendOpenCNAM", "Authorization Failed, URL: " & sUrl)
                Return ""
            End If
            If ex.Message.Contains("(400)") Then
                '' 400   Phone Number Provided is Invalid
                hs.WriteLog("SendOpenCNAM", "Invalid Phone Number, URL: " & sUrl)
                Return ""
            End If
            If ex.Message.Contains("(403)") Then
                '' 403   Exceeded Daily Request Count
                hs.WriteLog("SendOpenCNAM", "Exceeded Request Limit, URL: " & sUrl)
                Return ""
            End If
            If ex.Message.Contains("(402)") Then
                '' 402  Deliquent Account
                hs.WriteLog("SendOpenCNAM", "Account is Deliquent, URL: " & sUrl)
                Return ""
            End If
            '' ELSE
            hs.WriteLog("SendOpenCNAM", "HTTP Request Failed: " & ex.ToString)
            Return ""
        End Try
        Return strData
    End Function
Here is HS3 event defined to call the script entry point Main, with a phone number as a parameter:





Here is the log entries created when I ran the event:



Let me know if I can explain any of the code.

While I developed this under HS3, I do not think there is any reason it would not run as is under HS2.

Note that you have to supply your own authorization codes, or eliminate the second call that uses the auth codes. I've place xxxxxx for auth codes.

tenholde

Last edited by tenholde; November 22nd, 2014 at 11:12 PM.
Reply With Quote
  #11  
Old November 22nd, 2014, 11:04 PM
donstephens's Avatar
donstephens donstephens is offline
OverSeer
 
Join Date: Dec 2001
Location: Hamilton, MT
Posts: 2,724
Great! thanks. I'll play with it a bit.

Don
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse cell phone lookups Rupp HS2 / HSPRO 15 July 28th, 2007 04:06 AM
Phone number format MalcolmS HomeSeer General Discussion Area 7 February 5th, 2006 06:45 PM
Announce Phone Number itanic WAF NetCallerID (3P) 2 January 10th, 2006 11:16 AM


All times are GMT -4. The time now is 07:04 AM.


Copyright HomeSeer Technologies, LLC