Skype bot detects when you receive message [closed]

-1

This is what I have been looking for as I can do a bot that responds when I receive a message from someone, I found a tutorial but I could not get the bot to respond even though the bot answered in the tutorial.
This is the code I have for the bot to respond.

public void MsgStatus(ChatMessage pMessage, TChatMessageStatus Status)
    {

        if (Status == TChatMessageStatus.cmsReceived || Status == TChatMessageStatus.cmsSent)
        {

            string msg = pMessage.Body;
            Chat c = pMessage.Chat;

            if (msg.StartsWith(Trigger))
            {
                ListBox.Items.Add(DateTime.Now.ToLongTimeString() + ":" + "command" + "'" + msg + "'" + "from" + pMessage.Sender.Handle);
                msg = msg.Remove(0, 1).ToLower();
            }
            if (msg == Trigger + "help")
            {
                c.SendMessage("working");
            }
            else if (msg == "hello")
            {
                c.SendMessage("hello");
            }
            else if (msg == "oi" || msg == "ola" || msg == "olá")
            {
                c.SendMessage("Oi");
            }

        }

    }

That's how it starts oSkype.MessageStatus += new SKYPE4COMLib._ISkypeEvents_MessageStatusEventHandler(MsgStatus);

    
asked by anonymous 27.08.2016 / 22:52

1 answer

3

After much research I found this site that explains well and works hope that helps you. In case the link is offline, the following is done:

use the following dll

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;

Then download SKYPE4COMLib Dll (I do not know where to find it) and add the following line using SKYPE4COMLib;

Then declare Skype Constructor

private Skype MySkype = new Skype();

Then you have to do Attach to skype using

MySkype.Attach(5, false);

This code can be used on buttons or when the form does load depending on what you want, I do not think to connect so the form does load because if skype is closed the program can crash inside of a try because if it does not it is going to give error.

Then you use the following code

void MySkype_MessageStatus(ChatMessage pMessage, TChatMessageStatus Status)
        {
            if (pMessage.Body[0].ToString() == "@") // Check if it is a command, @ can be anything that you want.
            {
                string Command = pMessage.Body.Substring(1, pMessage.Body.Length - 1); // Basicaly remove @ from it.
                if (pMessage.Sender.Handle != MySkype.CurrentUserHandle) // Check if the sender is not yourself.
                    MySkype.SendMessage(pMessage.Sender.Handle, ProcessCommand(Command)); // Send the message back.
                else
                    MessageBox.Show("Messagesent.");
            }
        }

        private string ProcessCommand(string cmd)
        {
            switch (cmd)
            {
                case "help":
                    return "The commands are: blablabla...";
                case "LOL":
                    return "(chuckle)";
                default:
                    return "This is not a command.\nSend '@help' for help.";
            }
        }

What will do is check if the message starts with @ if not start will not do anything if start goes to the switch and if for example @help the message that received it will execute

case "help":
                    return "The commands are: blablabla...";

What you will do is tell the person who received a message to say The commands are: blablabla ... Any more questions or things you did not realize just ask.

    
28.08.2016 / 00:53