Skype4COMLib Skype API Auto Response in C#

Submitted by: 
Visitors have accessed this post 3991 times.


This tutorial is on how to use the Skype4ComLib Libaries in C# .NET to access our Skype program on our computer.


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.


Now that we are using the required libaries, we also need to 'using'/import them at the top of our file class, like so...

  1. using SKYPE4COMLib;


First we want to create a Skype object, like so;

  1. Skype sky = new Skype();

This will allow us to access the skype objects and functions. We also need to attach it to the currently running version of 'Skype' on the user's PC...

  1. 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.

  1. while (true)
  2. {
  3. foreach (IChatMessage msg in sky.MissedMessages)
  4. {
  5. }
  6. }

To extract the username of the sender, we get their handle...

  1. string handle = msg.Sender.Handle;

We are also going to set a message to send to the users to send the client a message...

  1. string message = "This is an auto response message.";

Now we want to send the message. It takes two arguments; user handle to send the message to, and the message as a string, so we write it like so...

  1. 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...

  1. System.Threading.Thread.Sleep(2000);


Full source code...

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using SKYPE4COMLib;
  12. namespace JayPabsSkypeComLibTutorial
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. Skype sky = new Skype();
  24. sky.Attach();
  25. while (true)
  26. {
  27. foreach (IChatMessage msg in sky.MissedMessages)
  28. {
  29. string handle = msg.Sender.Handle;
  30. string message = "This is an auto response message.";
  31. sky.SendMessage(handle, message);
  32. }
  33. System.Threading.Thread.Sleep(2000);
  34. }
  35. }
  36. }
  37. }

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.