Announcement

Collapse
No announcement yet.

Get AddressBook Name rather than CID name?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get AddressBook Name rather than CID name?

    I am working on my first script to speak my phone messages - actually it is a mod of dwoolridge's script. It uses MBMessageName to get the name to speak for the person who left the message.

    However, the name from MBMessageName apparently comes from the CID info. In many cases, the CID name is not very complete or even speakable via TTS, for example, for most cell callers CID name is only a city name like "New Haven CT". I would rather speak the Address Book name, when available.

    Is there a way to either:
    1) (in the message script) retrieve and speak the Address Book name rather than CID name for the current message, maybe by looking for a match of CID number?
    or
    2) Create an event or something such that when a new call is received, it will set the CID name in the message file (i.e., the return from MBMessageName) to a matching Address Book name so it reads the way I want it to when I run the message script, perhaps using LINESetCIDName?
    or
    3) some other way?

    I'm sure someone has done this.

    Thanks for any help,
    Mark
    Mark

    Hometroller S6 w/ HS3Pro, Way2Call
    BLAB8SS, BL Backup, Easy Trigger, HSTouch, Open Sprinkler, SONOS, Ultra1Wire3, UltraM1G, WeatherXML, Z-Wave

    #2
    You are correct there are several that have written scripts to manage the CID names. My first was MessageCentral from the Script Library. It is still available there. There is another common one that has name like "Who Called While I was Out" that should have another example. The following segments below are from the mcsAudrey plugin. During startup the first part is called and all the names in the HS Phone phonebook are added to a local dictionary. The second part is executed when the CID event occurs. It does a lookup in the dictionary to get a speakable name. In this case the result is sent via UDP, but it could be spoken instead.

    Note that is is VB and it contains the On Error GoTo label and the data typing that straight VBScript does not support, but otherwise the logic is the same.

    <pre class="ip-ubbcode-code-pre">

    Public Sub BuildHSPPhonebook()
    On Error GoTo Error_Exit

    Dim iaddr As String
    Dim j As Integer
    Dim adr As Object

    If InitHSP Then
    iaddr = hsp.ADRCount()
    For j = 1 To iaddr
    Set adr = hsp.ADRGet(j)
    With adr
    If .home_phone &lt;&gt; "" Then AddHSP adr, .home_phone, "home"
    If .cell_phone &lt;&gt; "" Then AddHSP adr, .cell_phone, "cell"
    If .business_phone &lt;&gt; "" Then AddHSP adr, .business_phone, "work"
    End With
    Next
    End If

    Normal_Exit:
    Set adr = Nothing
    Exit Sub
    Error_Exit:
    hsWritelog PluginName, "BuildHSPPhonebook "
    Resume Normal_Exit
    End Sub

    Private Sub AddHSP(adr As Object, sPhoneNumber As String, sLocation As String)
    On Error GoTo Error_Exit

    Dim pb As Phonebook
    Dim sKey As String

    sKey = Replace(Replace(Replace(Replace(sPhoneNumber, "-", ""), "(", ""), ")", ""), " ", "")
    If PhoneDictionary.Exists(sKey) Then
    Set pb = PhoneDictionary(sKey)
    'same phone number so edit the name string to add the multiples
    With pb
    If adr.Last = .LastName Then
    .FirstName = .FirstName & " or " & adr.First
    .Name = .FirstName & " " & .LastName
    Else
    .Name = .Name & " or " & adr.First & " " & adr.Last
    End If
    End With
    Else
    'New name, add it to dictionary
    Set pb = New Phonebook
    With pb
    .FirstName = adr.First
    .LastName = adr.Last
    .Name = adr.First & " " & adr.Last
    If bExcludeHSPLocation Then
    .Location = ""
    Else
    .Location = sLocation
    End If
    .PhoneNumber = sPhoneNumber
    .Wav = adr.announce_local_wav
    .Icon = ""
    End With
    PhoneDictionary.Add sKey, pb
    End If

    Normal_Exit:
    Set pb = Nothing
    Exit Sub
    Error_Exit:
    hsWritelog PluginName, "AddHSP "
    Resume Normal_Exit

    End Sub


    =================================
    The following is called when the CID event occurs. It uses the name from the HSP phonebook if available or the TELCO name
    ========================================


    Public Function MessageCIDEvent(bSendToACID As Boolean, sIP As String) As String
    Dim y As Variant
    Dim x As String
    Dim bHspAvailable As Boolean

    bHspAvailable = InitHSP
    'x = HSPAddressBookLookup("123-456-7890", "Test Message")
    If bHspAvailable Then
    x = HSPAddressBookLookup(hsp.CIDNumber(iCIDLineNumber), hsp.CIDName(iCIDLineNumber))
    Else
    x = HSPAddressBookLookup("1234567890", "HSP Not Available")
    End If
    If bSendToACID Then
    y = Split(x, " : ")
    UDPSendCID Replace(CStr(y(1)), " from ", "/", 1, -1, vbTextCompare), CStr(y(0)), sIP
    End If
    MessageCIDEvent = x
    End Function
    Public Function HSPAddressBookLookup(sPhoneNumber As String, sName As String) As String
    On Error GoTo Error_Exit

    Dim messageText As String
    Dim PhoneNumber As String

    'hsWritelog "Phonebook", sPhoneNumber
    PhoneNumber = Replace(Replace(Replace(Replace(sPhoneNumber, "-", ""), "(", ""), ")", ""), " ", "")
    sAssociatedWav = ""
    If PhoneDictionary.Exists(PhoneNumber) Then
    With PhoneDictionary(PhoneNumber)
    If .Location = "" Then
    messageText = .Name
    Else
    messageText = .Name & " at " & .Location
    End If
    sAssociatedWav = .Wav
    End With
    Else
    messageText = sName
    If messageText = "O" Or messageText = "" Then
    messageText = "Unknown"
    End If
    End If

    HSPAddressBookLookup = formatPhone(PhoneNumber) & " : " & messageText

    If DebugLog Then
    hsWritelog PluginDebug, "Phonebook Entry Exists=" & CStr(PhoneDictionary.Exists(PhoneNumber)) & ", Number=" & PhoneNumber & ", Default Name=" & sName & ", Lookup=" & formatPhone(PhoneNumber) & " : " & messageText
    End If

    Normal_Exit:
    Exit Function
    Error_Exit:
    hsWritelog PluginName, "HSPAddressBookLookup "
    Resume Normal_Exit
    End Function


    </pre>

    Comment

    Working...
    X