• We just launched and are currently in beta. Join us as we build and grow the community.

Skype4COMLib Skype API Auto Response in C#

kaisimmer17

Slice-of-Life Specialist
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
45
Likes
78
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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...

  1. using

    SKYPE4COMLib

    ;

Skype:

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

    )

    ;

Finished!

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

    ;

  11. namespace

    JayPabsSkypeComLibTutorial
  12. {
  13. public

    partial

    class

    Form1 :

    Form
  14. {
  15. public

    Form1(

    )
  16. {
  17. InitializeComponent(

    )

    ;
  18. }

  19. private

    void

    Form1_Load(

    object

    sender, EventArgs e)
  20. {
  21. Skype sky =

    new

    Skype(

    )

    ;
  22. sky.

    Attach

    (

    )

    ;
  23. while

    (

    true

    )
  24. {
  25. foreach

    (

    IChatMessage msg in

    sky.

    MissedMessages

    )
  26. {
  27. string

    handle =

    msg.

    Sender

    .

    Handle

    ;
  28. string

    message =

    "This is an auto response message."

    ;
  29. sky.

    SendMessage

    (

    handle, message)

    ;
  30. }
  31. System.Threading

    .

    Thread

    .

    Sleep

    (

    2000

    )

    ;
  32. }
  33. }
  34. }
  35. }


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

324,125

324,133

Top