Giter VIP home page Giter VIP logo

slackconnector's Introduction

Noobot / Noobot.Core

Noobot is a SlackBot for C# built on the intention of extensibility; building a bot should be fun.

Build statusNuget.org

Noobot

Install-Package Noobot.Core

About

I wanted to build a bot host/framework that was easy to work with, but also has the potential of being super powerful.

Noobot supports DI out of the box for all custom elements to ensure all elements could be easily tested and predictable.

Noobot is available as a Nuget package or standalone Console/Windows Service app.

Features

  • Available as a Nuget package to integrate into your apps (See examples)
  • Is super extensible
  • DI support out of the box
  • Automatically builds up help text with all supported commands
  • Middleware can send multiple messages for each message received
  • Supports long running processes (async)
  • Typing Indicator - indicate to the end user that the bot has received the message and is processing the request

Examples

You can find some examples of how to use the Nuget package in different scenarios at Noobot.Examples

Download & setup

We have compilled releases ready for you to use, all you need to do is fill out the Configuration/config.json file found in the zip file. Run over to releases section to download the latest build.

Setup for development

Please note that you will need to create a config.json file with your bot's api key. This should live under: src/Noobot.Runner/Configuration

Read how to get Noobot up and running quickly on the wiki.

How to customise

To customise Noobot please have a look at our wiki: https://github.com/noobot/noobot/wiki

Toolbox

You can find the ToolBox nuget package here which contains lots of handy middleware ready to be plumbed into your bot such as Flickr support, jokes, schedules and more.

slackconnector's People

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slackconnector's Issues

SlackConnector and Noobot

As Iโ€™m trying to figure out the scale and scope of this project and library for Slack I felt it was time to reach out to you lol.

Noobot works with The SlackConnector correct? Or are the entire 2 project separate? I plan to contribute some improvements I have made as I finalize them but just want to make sure my understand is up to speed on the layout.

SubType on SlackMessage

It would be very helpful if SlackMessage exposed the SubType property of the underlying message.

Accessing user name instead of user

Hi,

Was wondering is there a way to access the username that is set by the user. At the moment the Username is always set to whatever the email address is minus the @ + domain.

As you can see, i digged into GetMessageUser and this is what the UserCache Contains

image

Attachments

Appreciating this library. Initially found three potential issues:

  • I can not get attachments to work. The message text goes through though, no exception thrown
  • The NuGet package does not install completely under Mono due to framework restrictions
  • Logging interface or option to disable logging to console

Add support for .Net Core

  • TODO:
  • Upgrade to .Net 4.6.1
  • Replace RestSharp with Flurl
  • Replace WebSocketSharp with SocketLite.PCL
  • Replace SpecsFor library
  • Upgrade project to output Core into nuget package

Missing file comment in incoming SlackFile

Additional to issue #9

When SlackConnector deserializing file data it loses file comment. Slack response has file comment in json field: file.initial_comment.comment.
It is major metadata for the file message.

Example of file message with comment:
slack_file_comment

As result, is not possible to get file comment from incoming SlackFile.

ChatHub always null?

When sending a message from slack using SlackConnector then ChatHub always returns null so my bot cant reply to the message.

I have another bot where ChatHub works. But on my new bot I just created ChatHub returns null.

For some reason it works for a while just after I created the bot but then suddenly stops working and null appears.. Not sure if slack is to blame or SlackConnector

MissingMethodException on version 3.1.176.0

Furl v: 2.3
SlackConnector v: 3.1.176.0

I init my connection like so:

ISlackConnector connector = new SlackConnector.SlackConnector();
_connection = connector.Connect( $"{someValidApiKey}" ).Result;

Line 2 fails with a:

System.AggregateException: 'One or more errors occurred.'
Inner Exception:
MissingMethodException: Method not found: 'Flurl.Url Flurl.Url.SetQueryParam(System.String, System.Object)'.

It would appear this is a fault with Furl and not with SlackConnector. For now, I'll try reverting to previous versions of SlackConnector until I find one that lines up to a Furl version that still works.

Channel Creation Event

Am curious if this plugin will allow for the detection of channel_created events from Slack? This way we can invite the bot the created channel if it matches what we need?

Ergo, we want our bot in any channel that's created for our live chat channels, so we would ideally:

  • Listen for the channel_created event
  • Invite the bot to the new channel using an invite token from one of our admins
  • Bot would join room, and be ready to listen to commands.

Just curious if this would be possible with SlackConenctor?

Cannot get SlackConnector to work with Slack TLS 1.2

I am using .net version 4.6.1, and I have verified that TLS 1.2 is available and enabled on the server, Windows Server 2012 R2.

I have tried adding this line of code to the startup section of the program.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

This is the code I use to connect to slack, but the connection fails because I suspect that TLS encryption is failing.

var connector = new SlackConnector.SlackConnector();
            _connection = await connector.Connect(slackKey);
            _connection.OnMessageReceived += MessageReceived;
            _connection.OnDisconnect += OnDisconnect;
            _connection.OnReconnecting += OnReconnecting;
            _connection.OnReconnect += OnReconnect; 

This is the exception we get when initially trying to connect to the Slack server.

02:00:03.3613 ERROR [5] - Bot: Start - Error connecting to Slack: System.AggregateException: One or more errors occurred. ---> WebSocketSharp.WebSocketException: An error has occurred during a TLS handshake. ---> System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The function requested is not supported
--- End of inner exception stack trace ---
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at WebSocketSharp.WebSocket.setClientStream()
--- End of inner exception stack trace ---
at WebSocketSharp.WebSocket.setClientStream()
at WebSocketSharp.WebSocket.doHandshake()
at WebSocketSharp.WebSocket.connect()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.SlackConnector.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.SlackConnector.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Welton.SlackbotApi.WBotCore.d__7.MoveNext() in C:\BuildAgent1\work\ebdb82161931e455\Company.SlackbotApi\WBotCore.cs:line 47
--- End of inner exception stack trace ---

The program tries to reconnect to slack multiple times in a loop an we eventually get this timeout which is because we are flooding the server with reconnect messages that fail.

---> (Inner Exception #0) SlackConnector.Exceptions.CommunicationException: Error occured while sending message '429'
at SlackConnector.Connections.Clients.ResponseVerifier.VerifyResponse[T](IRestResponse response)
at SlackConnector.Connections.Clients.RequestExecutor.d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.Connections.Clients.Handshake.HandshakeClient.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.SlackConnector.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Any tips would be helpful. Not sure if this is an issue with the package itself or I am just using it incorrectly.

Thanks!

PingPongMonitor alive even after closing connection

In SlackConnection.Close the _pingPongMonitor is not stopped. Therefore the Timer in the ping-pong monitor keeps a reference and holds the connection alive (no GC) + it tries to ping-pong every 5 s although I closed the corresponding SlackConnection.

I suggest adding a method StopMonitor to IPingPongMonitor which disables the timer:

        public void StopMonitor()
        {
            _timer?.Dispose();
            _timer = null;
        }

Any objections?

Best regards,
D.R.

Creating channels

I noticed none of the channel creation stuff is public. Could there be something exposed to create a channel?

Constant stream of errors in console

I have a console app that's logging to Slack, and within the last update or so I have started seeing this steady stream of errors:

Unable to parse message:
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at SlackConnector.Connections.Sockets.Messages.Inbound.MessageInterpreter.ParseMessageType(String json)
   at SlackConnector.Connections.Sockets.Messages.Inbound.MessageInterpreter.InterpretMessage(String json)

I am debugging, and I have breakpoints everywhere that SlackConnector is used--but nothing is triggering. I'm set to break on all exceptions of any kind, but I'm not catching this one.

Communication to/from slack appears to be unaffected, but the noise level is now very high in the console. This seems to be the code that logs the error

message received

Hello i am new to making slack bots, now is my question do you get the messages from slack and where is this saved?

i can already send messages but just sending is useless when you didn't know what you got.

Execution stops abruptly during handshake

Hi, and thanks for the great work! I'm trying to get this working in a console app, but I'm having a problem. Execution stops abruptly in RequestExecutor.Execute, on this line:

IRestResponse response = await client.ExecutePostTaskAsync(request);

There's no exception that I can detect... I think the await is just never returning - but it doesn't hang, it exits.

I know this is a restsharp call. The key is correct (works in Margibot). Any idea what to try here?

SlackConnector doesn't seem to respect proxy settings. Connection through NTLM proxy fails.

I'm trying to run Noobot "out of the box" but I cannot get a connection to go through our proxy server.
I have configured

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
      <proxy usesystemdefault="True"/>
    </defaultProxy>
  </system.net>

in App.config in Noobot but I still get a connection error.
Running Fiddler I can see that there is a request to https://slack.com/api/rtm.start which returns a json object, so that works fine. However initiating the WebSocket connection afterwards fails because it doesn't try to connect through the configured proxy. The request never shows up in Fiddler, and I get the well-known "No connection could be made because the target machine actively refused it".

ChatHub Null on New DM

I'm getting crashes when a user messages the "bot" for the first time and a ChatHub is created. It's a key not found in dictionary exception, created in the HandleMessage(inboundMessage) method of SlackConnection. Even though the inboundMessage has a Channel string provided, it is not present in the _connectedHubs dictionary. Perhaps it just needs to sleep for a while to let the _connectedHubs dictionary to update?

Subsequent messages received from the user don't cause a crash, as the session is present in the ConnectedDMs() ... only happens the first time.

total newbie

Hi,
I got the package from nuGet within VS.
I first used the few lines from your Usage section
looks like connection.OnConnectionStatusChanged does not exists anymore.

Then about the slackKey in
ISlackConnection connection = await connector.Connect(slackKey);

not sure what I should put there. Is that the token generated by slack token generator ?
or ?

Thx

Unable to parse different types of messages

{"type":"im_created","user":"U0DKUTE0L","channel":{"id":"D0EEU58RL","is_im":true,"user":"U0DKUTE0L","created":1447411860,"last_read":"0000000000.000000","latest":null,"unread_count":0,"unread_count_display":0,"is_open":false}}

OnMessageReceived not triggered by Webhook

Hi, my current setup is as followed. I have 2 projects, one console app for the bot purposes (onmessagereceived, onuserjoined, ondisconnected, onreconnect) and a asp.net mvc app to capture post request sent when an interactive messages are clicked. I send a basic response back to the chat but it seems the bot doesn't trigger onmessagereceived when that happens.

Missing Message Type causing exception when connecting

I am using Noobot nuget package 3.1.35 and Slack Connector nuget package 4.1.16

When my client connects I am receiving an exception "'Requested value 'hello' was not found.'"

The message received is here: https://api.slack.com/events/hello

The MessageInterpreter is erroneously assuming any message that it receives that is not in the enum is a chat message and tries to deserialize it as such. That feels like a pretty big point of fragility, especially given that the chat message has a well defined type.

Is there a "mrkdwn" or "mrkdwnin" field available?

For attachments, there is a property that can be used to control what gets formatted. I may just be thick headed and missing it, can you let me know if there is something existing that controls this?

// "mrkdwn_in": ["text", "pretext", "fields"],

TLS 1.2

On February 19, 2020, Slack will end support for TLS versions 1.0 and 1.1. We've identified that one or more of your Slack apps are impacted by this change. If you don't upgrade your app to TLS 1.2, requests sent to any Slack endpoint will fail.
You must update your Slack app before February 21, 2020. Please verify which of your Slack apps are affected: https://api.slack.com/unsafe-tls-deprecation

In code i just use

      var client = new SlackConnector.SlackConnector();
      connect = await client.Connect(token);

have u apps in https://api.slack.com/unsafe-tls-deprecation or its only my problem?

Doesn't connect with proxy

Hi, I can't connect with proxy:
p.s. The error seems to be with the nuget library is WebsocketClientLite.PCL
System.InvalidOperationException
HResult=0x80131509
Message=The operation is not allowed on non-connected sockets.
Source=System
StackTrace:
at System.Net.Sockets.TcpClient.GetStream()
at SocketLite.Services.TcpSocketClient.d__19.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at WebsocketClientLite.PCL.MessageWebSocketRx.d__15.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.Connections.Sockets.WebSocketClientLite.d__7.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.Connections.ConnectionFactory.d__0.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SlackConnector.SlackConnector.d__5.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TopShelf2.SlackConnect.d__4.MoveNext() in C:\mygit\TopShelf2\TopShelf2\Program.cs:line 40

LinkButton Support

First, thanks for the great project!
We need support for LinkButtons which requires the SlackAttachmentAction to pass url field in the json.

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.