Announcement

Collapse
No announcement yet.

[VBScript] Check for voicemail new & old

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

    [VBScript] Check for voicemail new & old

    This is probably just another way to skin the cat...
    But i didn't see what i wanted... so i made one and thought i'd share..

    Script requires Two(2) Virtual Devices
    One for Pending Unread Voice Mail
    One for messages that have already been heard. (Old Messages)

    Script sets Device(s) ON if there are messages
    Script sets Device Value(s) to number of messages
    Script Sets Device String(s) to Text "# Message(s)"

    That way.. you can key on status change, or value change, and also have a preformated string to indicate the number of messages in VR.

    I run this every 10 minutes, and also whenever my answering machine asp page is run.

    Check_Messages.txt
    Code:
    ' Routine to Check new messages in voicemail and set flag(s)
    '
    ' Script requires Two Virtual Devices
    ' One for Pending Unread Voice Mail
    ' One for messages that have already been heard.
    '
    ' Script sets Device ON if there are messages
    ' Script sets Device Value to number of messages
    ' Script Sets Device String to Text "# Message(s)"
    '
    Const PENDING_VMAIL = "V82"
    Const OLD_VMAIL = "v83"
    '
    Const SET_VIRT = 2
    Const RESET_VIRT = 3
    '
    sub main()
    '
    ' Declare Variables
    '
     dim MsgWaiting
     dim unread_Count
     dim old_count
     dim ReadMessages
     dim unread_Text
     dim old_text
    '
    ' Initialize Variables
    '
     unread_count = 0
     old_count = 0
     MsgWaiting = RESET_VIRT
     ReadMessages = RESET_VIRT
     old_text = "No Messages"
            unread_text = "No Messages"
    '
    ' Check All MailBoxes
    '
     intMailBoxCount = hsp.MBCount
     For i = 1 To intMailBoxCount
      hsp.MBSort
      Set intMailBox = hsp.MBGet(i)
    '
    '  Check to see if  there are Unread messages 
    '
      If intMailBox.unread_messages > 0 Then
       MsgWaiting = SET_VIRT
      end if
    '
    ' Count messages for this mailbox
    '
      unread_count = unread_count + intMailBox.Unread_messages
      old_count = old_count + (intMailBox.total_messages - intMailBox.unread_messages)
      if old_count > 0 Then
       ReadMessages = SET_VIRT
      end if
     Next
    '
    ' Set Devices
    '
     if unread_count > 1 Then
      unread_text = unread_count & " Messages"
     elseif unread_count > 0 then
      unread_text = unread_count & " Message"
     end if
     if old_count > 1 Then
      old_text = old_count & " Messages"
     elseif old_count > 0 then
      old_text = old_count & " Message"
     end if
     
     hs.SetDeviceStatus PENDING_VMAIL,MsgWaiting
     hs.SetDeviceStatus OLD_VMAIL,ReadMessages
     
     hs.SetDeviceString PENDING_VMAIL, unread_text
     hs.SetDeviceString OLD_VMAIL, old_text
     
     hs.SetDeviceValue PENDING_VMAIL, unread_count
     hs.SetDeviceValue OLD_VMAIL, old_count
     
    end sub
    Andrew
    Regards,

    Andrew B.
Working...
X