Skype4COM: VoicemailServer.vbs

Skype4COM

VoicemailServer.vbs

This script listens for new voicemails, sends SMS message and answers incoming calls.

Copyright � 2004-2006 Skype Limited. Licensed under BSD license.

'// Create Skype object:
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")

'// Connect to Skype API:
oSkype.Attach

'// The mobile number used in this example
Const cMyMobileNumber = "+1234567890"

'// Skype constants
cCallStatusRinging = oSkype.Convert.TextToCallStatus("RINGING")
cCallStatusInprogress = oSkype.Convert.TextToCallStatus("INPROGRESS")
cCallTypeIncomingP2P = oSkype.Convert.TextToCallType("INCOMING_P2P")
cCallTypeIncomingPSTN = oSkype.Convert.TextToCallType("INCOMING_PSTN")
cVoicemailStatusUnplayed = oSkype.Convert.TextToVoicemailStatus("UNPLAYED")
cVoicemailStatusPlayed = oSkype.Convert.TextToVoicemailStatus("PLAYED")
cAttachmentStatus_Available = oSkype.Convert.TextToAttachmentStatus("AVAILABLE")

'// This script runs forever
Do While True 
  WScript.Sleep(30000)
Loop

'// The CallStatus event handler monitors call status and if the status is "ringing" and it is an incoming call, answers the call: 
Public Sub Skype_CallStatus(ByRef aCall, ByVal aStatus)
  WScript.Echo  ">Call " & aCall.Id & " status " & aStatus & " " & oSkype.Convert.CallStatusToText(aStatus)
  If cCallStatusRinging = aStatus And _
    (cCallTypeIncomingP2P = aCall.Type Or cCallTypeIncomingPSTN = aCall.Type) Then 
     
     '// Accept incoming call only from predefined phone number or Skypename:
     If aCall.PartnerHandle = cMyMobileNumber Then            
       aCall.Answer()
       For Each oVoicemail In oSkype.Voicemails
         If oVoicemail.Status = cVoicemailStatusUnplayed Then 
           oVoicemail.StartPlaybackInCall
           Do While oVoicemail.Status <> cVoicemailStatusPlayed
             WScript.Sleep(1000)
           Loop
           '// Change the voicemail status back to "unplayed"
           oVoicemail.SetUnplayed
         End If      
       Next
       If cCallStatusInprogress = aCall.Status Then aCall.Finish() End If       
     End If
  End If
End Sub

'// The VoicemailStatus event handler monitors voicemail status changes:
Public Sub Skype_VoicemailStatus(aVoicemail, aStatus)     
  WScript.Echo ">Voicemail " & aVoicemail.Id & " status " & oSkype.Convert.VoicemailStatusToText(aStatus)
  If cVoicemailStatusDownloading = aStatus Then 
    WScript.Echo "Sending SMS to " & cMyMobileNumber
    Set oSms = oSkype.SendSms(cMyMobileNumber, "You have new voicemail from " & aVoicemail.PartnerDisplayName)
  End If
End Sub

'// The AttachmentStatus event handler monitors attachment status and automatically attempts to reattach to the API following loss of connection:
Public Sub Skype_AttachmentStatus(ByVal aStatus)
  WScript.Echo ">Attachment status " & oSkype.Convert.AttachmentStatusToText(aStatus)
  If aStatus = cAttachmentStatus_Available Then oSkype.Attach() End If
End Sub

Copyright � 2006 Skype Limited. All rights reserved.