Skype bot detects when receiving message

Asked

Viewed 210 times

-1

Here’s the thing I’ve been looking for how I can make a bot that responds when I receive a message from someone, I found a tutorial but I couldn’t get the bot to respond despite the bot responding in the tutorial.
This is the code I have for the bot to answer.

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 he starts oSkype.MessageStatus += new SKYPE4COMLib._ISkypeEvents_MessageStatusEventHandler(MsgStatus);

  • What is the tutorial link? The operating system and skype version of the tutorial are the same as yours?

  • @rubStackOverflow yes but I had to convert the entire code from Vb to c# https://www.youtube.com/watch?v=ahkuYT7-wdU

  • After much research I found this website that explains well and works I hope it helps you.

  • Hello, welcome to SOPT. This site is not a forum. If you haven’t done it yet, do the [tour] and read [Ask]. So your question would need to have a clear and objective problem. You say the Bot does not answer, but does it run? Have you debugged the code? Is there an error message? Without these details, hardly anyone will be able to help you.

  • @Luizvieira has been there for weeks you think I remember. is not the best time to ask this

1 answer

3


After much research I found this website which explains well and works I hope it helps you. In case the link is offline do the following:

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 don’t know where to find) and add the following line
using SKYPE4COMLib;

Then declare Skype Constructor

private Skype MySkype = new Skype();

Then you have to Attach to skype using

MySkype.Attach(5, false);

This code can be used on buttons or when the form loads depending on what you want, I do not hesitate to connect as soon as the form loads because if skype is closed the program can also give crash aconçeho inside a Try because if it fails will 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 you will do is check if the message starts with @ or start will not do anything if it goes to the switch and if it is for example @help the message you received it will run

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

What you’re gonna do is you’re gonna tell whoever got a message saying The Commands are: blablah... Any more questions or things you don’t understand Just ask.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.