Giter Site home page Giter Site logo

dotnetcore-slackbot's Introduction

.Net Core Slackbot Library

A simple slackbot library built to listen for and respond to messages.

Install

Install-Package Slackbot

Usage

var bot = new Bot("bot-token", "bot-username");

bot.OnMessage += (sender, message) =>
{
    if (message.MentionedUsers.Any(user => user == "bot-username"))
    {
        bot.SendMessage(message.Channel, $"Hi {message.User}, thanks for mentioning my name!");
    }
};

Release Notes

https://github.com/mattcbaker/dotnetcore-slackbot/blob/master/RELEASE-NOTES.md

Nuget

https://www.nuget.org/packages/Slackbot

License

This code is provided under the MIT license

dotnetcore-slackbot's People

Contributors

kunalshetye avatar matt-github-acct avatar mcintyre321 avatar samtwining avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dotnetcore-slackbot's Issues

Have an optional paramter for calling Connect on Bot initialization

This would allow me to create a bot before connecting to the service. I would like to do some configuration and dependency injection in my app before actually starting (Connecting) the bot.

Proposed change

public class Bot 
{
     public Bot(string token, string username, bool connect = true) 
     {
          //existing initialization 
          if(connect)
          {
              Connect();
          }
     }
    public void Start()
    {
        Connect():
    }
}

Example call

var shouldConnectNow = false;
var bot = new Bot(botName, botToken, shouldConnectNow); 
//do other things 
bot.Start(); 

NullReferenceExceptions on background thread?

Hi, I'm running your bot in LinqPad, but am getting an NRE when it hears a message. I think the error is on a background thread, which LinqPad is catching automatically, but it might cause issies on other hosts.

image

The bot still seems to work, but it's maybe only because LinqPad catches the error safely

PS your bot is awesome I've got lots of people at work using it on a hackday :)

Edit message events are suppressed

This library suppresses message events when the event is a message edit. Is this desirable behavior? Should the edit event not be suppressed?

System not supported exception

Hello, i'm getting this exception whenever i launch the program :
System.PlatformNotSupportedException : 'The WebSocket protocol is not supported on this platform.'

It turns out that System.Net.WebSockets is not supported on windows 7. I cannot update windows on my work laptop, is there any chance that you fix this problem soon? I heard that Fleck can solve this trivially : "http://stackoverflow.com/a/15679366"

Problem with OnMessage event

After some seconds, the following exception is throwed:

System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
   at Slackbot.SocketConnection.TryConnect()
   at Slackbot.SocketConnection.Connect()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__7_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.QueueUserWorkItemCallback.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

The current code is the same of the example:

 var bot = new Bot(name, token);

            bot.OnMessage += (sender, message) =>
            {
                if (message.MentionedUsers.Any(m => m == name))
                    bot.SendMessage(message.Channel, $"Hi {message.User}, thanks for mentioning my name!");
            };

I running it on .NET Core 2.1 (04e15494b6), the Slackbot library version is 1.4.1.

Reconnect exception handling throttle

One comment - when the socket gets disconnected it will throw an exception and in the catch block the connect method is called again. Looks like this would cycle very quickly when no internet connection was available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.