Announcement

Collapse
No announcement yet.

[VB.NET Script] Play Phone Messages

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

    [VB.NET Script] Play Phone Messages

    Edit (add discussion link)
    Discussion here: http://board.homeseer.com/showthread...509#post787509

    I took one of the scripts floating around to play "unread" voice mail and modified it a little:

    Run script from any trigger (x10 palmpad, web button, etc)

    Script reads through voice mail. (In Default Mailbox)
    Script looks up Caller ID info for announcing "Who" left the message.
    Script leaves messages "unread" in mail box.
    After last message is played , script asks if you want to mark messages "read" and waits 5 seconds for response.
    If the script is run Again during that 5 second window.. the messages are marked as read.

    Messages are Interruptable during playback..
    To interrupt messages, execute a one line script (triggered from web page, palmpad etc) with the following code


    &hs.urlaction "http://localhost/hspw/?no_page_gen=1&doaction=stopspkr","GET","",""

    </pre>


    Script is a vb.net script Copy and paste to PlyPhoneMsg.vb

    Code:
        Sub Main(ByVal parms As Object)
            Dim mb As Scheduler.clsMailbox
            Const PHLASTCALL As String = "V44"
            Dim MFileName As String
            Dim I As Integer
            Dim TotalVM, NewVM As Integer
            Dim Path As String
            Dim namcheck As String 
            Dim scallername As String
            Dim IsRunning As String
    
    
    
            Dim retval As String
    
            IsRunning = hs.CreateVar("LRPlayMsgActive")
    
    
            If IsRunning = "" Then
    
                IsRunning = hs.SaveVar("LRPlayMsgActive", True)
    
    
                hsp.MBSort()                ' Updates mailbox status & sorts VM by date. Call before MBGet...
                mb = hsp.MBGetDefault       ' Selects the default mailbox
    
                TotalVM = mb.total_messages
                NewVM = mb.unread_messages
    
    
                Select Case NewVM
                    Case 0
                        hs.Speak("You have no new messages.")
                        hs.Speak("The last Incoming call was from " & hs.DeviceString(PHLASTCALL))
                        hs.SaveVar("LRPlayMsgActive", False)
                        hs.DeleteVar("LRPlayMsgActive")
                        Exit Sub
                    Case 1
                        hs.Speak("You have one new message.")
                    Case Else
                        hs.Speak("You have " & NewVM & " new messages.")
                End Select
                If NewVM >= 1 Then
                    For I = 1 To NewVM
                        If I = 1 Then
                            MFileName = hsp.MBFirstUnreadMessage(1, CType(mb, Object))
                        Else
                            MFileName = hsp.MBNextUnreadMessage(1, CType(mb, Object))
                        End If
                        namcheck = hsp.MBMessageFrom(MFileName)
                        scallername = get_address_name(namcheck)
                        'namcheck = hsp.MBMessageFrom(MFileName)
                        If scallername = "" Then
                            scallername = hsp.MBMessageName(MFileName)
                        End If
                        Path = hsp.GetAppPath & "\messages\" & MFileName
                        hs.Speak("Message Number " & I & " Recorded on " & hsp.MBMessageDate(MFileName) & " at " & hsp.MBMessageTime(MFileName) & ", From " & scallername, True)
    
    
                        retval = hs.URLAction("http://localhost/hspw/?no_page_gen=1&doaction=playspkr&playfile=" & MFileName, "GET", "", "")
    
                        hsp.MBMarkUnRead(MFileName)
                    Next
                End If
                hs.Speak("End of new messages")
    
                hs.Speak("If you would like to mark these messages as Red, Please pres the On Button Again in the next 5 seconds", true)
    
                If hs.CreateVar("LRPlay_Waiting") <> "" Then
                    hs.WriteLog("PlayMsg", "LrPlayWaiting already exists This really shouldn't be the case")
                End If
                hs.SaveVar("LRPlay_Waiting", True)
    
                hs.WaitSecs(5)
                hs.SaveVar("LRPlay_Waiting", False)
                hs.DeleteVar("LRPlay_Waiting")
    
                hs.SaveVar("LRPlayMsgActive", False)
    
                hs.DeleteVar("LRPlayMsgActive")
    
            Else
                If CType(hs.GetVar("LRPlay_Waiting"), Boolean) = True Then
    
                    ' Mark messages as read
    
                    hsp.MBSort()                ' Updates mailbox status & sorts VM by date. Call before MBGet...
                    mb = hsp.MBGetDefault       ' Selects the default mailbox
    
                    NewVM = mb.unread_messages
    
                    If NewVM = 0 Then
                        Exit Sub
                    End If
    
                    For I = 1 To NewVM
    
                        If I = 1 Then
                            MFileName = hsp.MBFirstUnreadMessage(1, CType(mb, Object))
                        Else
                            MFileName = hsp.MBNextUnreadMessage(1, CType(mb, Object))
                        End If
                        hsp.MBMarkRead(MFileName)
                    Next
                    hs.Speak("A total of " & NewVM & "Messages have been marked as read.")
                Else
                    Exit Sub
                End If
    
    
            End If
    
    
        End Sub
        Function get_address_name(ByVal phone_number As String) As String
    
            Dim i_AdrCount As Integer
            Dim i As Integer
            Dim strlen As Integer
            Dim strlen2 As Integer
            Dim objContact As Scheduler.clsContact
            Dim s_caller_name As String
            Dim NamInsteadOfPhNum As String
            Dim TestCIDName As String
    
            NamInsteadOfPhNum = phone_number
            phone_number = strip_non_numerics1(phone_number)
    
            i_AdrCount = hsp.ADRCount            ' number of address book entries
    
            For i = 1 To i_AdrCount          ' look thru address book for number
    
                objContact = hsp.ADRGet(i) ' get the reference to the addrbk entry
    
    
                TestCIDName = objContact.cid_name
                If TestCIDName.Length >= 10 Then
                    strlen = 10
                Else
                    strlen = TestCIDName.Length
                End If
                If NamInsteadOfPhNum.Length >= 10 Then
                    strlen2 = 10
                Else
                    strlen2 = NamInsteadOfPhNum.Length
                End If
    
                If (Trim(TestCIDName.ToUpper().Substring(0, strlen)) = Trim(NamInsteadOfPhNum.ToUpper().Substring(0, strlen2)) Or strip_non_numerics(objContact.home_phone_2) = phone_number Or strip_non_numerics(objContact.home_phone) = phone_number Or strip_non_numerics(objContact.business_phone_2) = phone_number Or strip_non_numerics(objContact.business_phone) = phone_number Or strip_non_numerics(objContact.cell_phone) = phone_number Or strip_non_numerics(objContact.cell_phone_2) = phone_number Or strip_non_numerics(objContact.fax_home) = phone_number Or strip_non_numerics(objContact.fax_work) = phone_number Or strip_non_numerics(objContact.pager_phone) = phone_number) Then
    
                    If objContact.First = "" And objContact.Last = "" Then
                        If objContact.company_name = "" Then
                            Return ""
                        Else
                            s_caller_name = objContact.company_name
                            Return s_caller_name
                        End If
    
                    Else
                        s_caller_name = objContact.First & " " & objContact.Last
                        Return s_caller_name
                    End If
                    Exit Function
                End If
            Next
    
            Return ""
    
        End Function
        Function strip_non_numerics(ByVal what_phone_number As String) As String
    
            Dim i As Integer
            Dim s_char As String
            Dim s_new_num As String
    
            s_new_num = ""
    
            For i = 1 To what_phone_number.Length
    
                s_char = Mid(what_phone_number, i, 1)
                If IsNumeric(s_char) Then
                    s_new_num = s_new_num & s_char
                End If
    
            Next
    
            If s_new_num.Length = 0 Then
                s_new_num = "*"
            End If
            Return s_new_num
    
        End Function
        Function strip_non_numerics1(ByVal what_phone_number As String) As String
    
            Dim i As Integer
            Dim s_char As String
            Dim s_new_num As String
    
            s_new_num = ""
    
            For i = 1 To what_phone_number.Length
    
                s_char = Mid(what_phone_number, i, 1)
                If IsNumeric(s_char) Then
                    s_new_num = s_new_num & s_char
                End If
    
            Next
    
            If s_new_num.Length = 0 Then
                s_new_num = "^"
            End If
            Return s_new_num
    
        End Function
    Last edited by ArbWare; September 22, 2007, 09:03 PM.
    Regards,

    Andrew B.
Working...
X