Skype4COM: VoicemailServer.cs

Skype4COM

VoicemailServer.cs

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

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

using System;
using System.Collections.Generic;
using System.Text;
using SKYPE4COMLib;

namespace ConsoleApplication1
{
    class VoicemailServer
    {
        [MTAThread]
        static void Main(string[] args)
        {
            oSkype.CallStatus += Skype_CallStatus;
            oSkype.VoicemailStatus += Skype_VoicemailStatus;
            oSkype.Attach(5, true);
            while (true){
                System.Threading.Thread.Sleep(1000);
            }
        }
        static void Skype_CallStatus(Call call, TCallStatus status)
        {
            Console.WriteLine(">Call " + call.Id + " status: " + oConvert.CallStatusToText(status));
            if (status == TCallStatus.clsRinging && (call.Type == TCallType.cltIncomingP2P || call.Type == TCallType.cltIncomingPSTN)) {
                if (call.PartnerHandle == sMyMobileNumber) {
                    call.Answer();
                    foreach (Voicemail oVoicemail in oSkype.Voicemails) {
                        if (oVoicemail.Status == TVoicemailStatus.vmsUnplayed) {                            
                            oVoicemail.StartPlaybackInCall();
                            while (oVoicemail.Status != TVoicemailStatus.vmsPlayed) {
                                System.Threading.Thread.Sleep(1000);
                            }                                
                            oVoicemail.SetUnplayed();
                        }                        
                    }
                }
                if (call.Status == TCallStatus.clsInProgress) {
                    call.Finish();
                }                    
            }
        }
        static void Skype_VoicemailStatus(Voicemail voicemail, TVoicemailStatus status)
        {
            Console.WriteLine(">Voicemail status: " + oConvert.VoicemailStatusToText(status));
            if (status == TVoicemailStatus.vmsDownloading) {
                Console.WriteLine("Sending SMS to " + sMyMobileNumber);
                SmsMessage oMessage = oSkype.SendSms(sMyMobileNumber, "You have new voicemail from " + voicemail.PartnerDisplayName, "");
            }
        }
        static Skype oSkype = new Skype();
        static Conversion oConvert = new Conversion();
        static String sMyMobileNumber = "+1234567890";
    }
}

Copyright � 2006 Skype Limited. All rights reserved.