Skype4COMLib Skype API Auto Response in C#
Submitted by Yorkiebar on Thursday, August 28, 2014 - 07:53.
Introduction:
This tutorial is on how to use the Skype4ComLib Libaries in C# .NET to access our Skype program on our computer.SKYPE4COMLib:
To use the Skype libaries you need to first obtain them via .NET Framework installation of 4.0 or later. I am using 4.5 for this tutorial, then you want to create a new Console/Form application in Visual Studio for a C# application. Right click on your application in the 'Solution/Package Explorer', click on 'Add', then 'Reference', select 'COM' from the side tabs, and choose 'SKYPE4COMLib Libary'. Click apply & ok.Skype Objects:
We are going to be creating an auto response in this tutorial so we need to go over a few Skype4ComLib object types; Skype - the application used. IUser - a Skype user. IChatMessage - a message sent within a Skype chat conversion. Not SMS or voice calling.Using:
Now that we are using the required libaries, we also need to 'using'/import them at the top of our file class, like so...- using SKYPE4COMLib;
Skype:
First we want to create a Skype object, like so;- sky.Attach();
Missed Messages Loop:
Next we are going to write a simple infinite loop to constantly check for new messages on the user's PC. If there are any found, the application will automatically extract the required information.- while (true)
- {
- foreach (IChatMessage msg in sky.MissedMessages)
- {
- }
- }
- string handle = msg.Sender.Handle;
- string message = "This is an auto response message.";
- sky.SendMessage(handle, message);
Thread Sleeping:
If we constantly run this loop, our CPU would burn, so we need to stop it for a few seconds every loop, we use the sleep method for this. It takes the argument for amount of time in milliseconds, so we write '2000' for 2000ms which is 2seconds...- System.Threading.Thread.Sleep(2000);
Finished!
Full source code...- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using SKYPE4COMLib;
- namespace JayPabsSkypeComLibTutorial
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- sky.Attach();
- while (true)
- {
- foreach (IChatMessage msg in sky.MissedMessages)
- {
- string handle = msg.Sender.Handle;
- string message = "This is an auto response message.";
- sky.SendMessage(handle, message);
- }
- System.Threading.Thread.Sleep(2000);
- }
- }
- }
- }
Add new comment
- 345 views