/// <inheritdoc /> /// <summary> /// Disconnect from the bot server /// </summary> /// <returns>Async task</returns> public Task DisconnectAsync() { if (_client.IsConnected) { _client.CloseSocket(); } IsConnected = false; return(Task.CompletedTask); }
public void Stop() { Log.Debug(nameof(Stop)); _timer.Elapsed -= RefreshChannelsTimer_Elapsed; _timer.Stop(); _reconnectTimer.Elapsed -= ReconnectTimer_Elapsed; _reconnectTimer.Stop(); _client.CloseSocket(); }
public void Disconnect() { Messages = null; connectionStatusTimer.Elapsed -= ConnectionStatusTimer_Elapsed; connectionStatusTimer.Dispose(); channelNameLookup = null; client?.CloseSocket(); Console.WriteLine("Disconnected from {0}.", serverConfig.ServerId); }
/// <summary> /// Try close the slack streaming connection /// </summary> private void TryCloseConnection() { try { SlackSocketClient.CloseSocket(); } catch (Exception exception) { Console.WriteLine(exception); } }
/// <summary> /// Used to connect task mail bot and to capture task mail /// </summary> /// <param name="container"></param> public static void Main(IComponentContext container) { _logger = container.Resolve <ILogger>(); _stringConstant = container.Resolve <IStringConstantRepository>(); try { _taskMailRepository = container.Resolve <ITaskMailRepository>(); _slackUserDetails = container.Resolve <ISlackUserRepository>(); _environmentVariableRepository = container.Resolve <IEnvironmentVariableRepository>(); // assigning bot token on Slack Socket Client string botToken = _environmentVariableRepository.TaskmailAccessToken; SlackSocketClient client = new SlackSocketClient(botToken); // Creating a Action<MessageReceived> for Slack Socket Client to get connect. No use in task mail bot MessageReceived messageReceive = new MessageReceived(); messageReceive.ok = true; Action <MessageReceived> showMethod = (MessageReceived messageReceived) => new MessageReceived(); // Telling Slack Socket Client to the bot whose access token was given early client.Connect((connected) => { }); try { // Method will hit when someone send some text in task mail bot client.OnMessageReceived += (message) => { var user = _slackUserDetails.GetById(message.user); string replyText = ""; var text = message.text; if (text.ToLower() == _stringConstant.TaskMailSubject.ToLower()) { replyText = _taskMailRepository.StartTaskMail(user.Name).Result; } else { replyText = _taskMailRepository.QuestionAndAnswer(user.Name, text).Result; } // Method to send back response to task mail bot client.SendMessage(showMethod, message.channel, replyText); }; } catch (Exception) { client.CloseSocket(); } } catch (Exception ex) { _logger.Error(_stringConstant.LoggerErrorMessageTaskMailBot + " " + ex.Message + "\n" + ex.StackTrace); throw ex; } }
/// <summary> /// Used for Scrum meeting bot connection and to conduct scrum meeting /// </summary> /// <param name="container"></param> public static void ScrumMain(IComponentContext container) { _logger = container.Resolve <ILogger>(); _stringConstant = container.Resolve <IStringConstantRepository>(); try { _environmentVariableRepository = container.Resolve <IEnvironmentVariableRepository>(); string botToken = _environmentVariableRepository.ScrumBotToken; SlackSocketClient client = new SlackSocketClient(botToken);//scrumBot _scrumBotRepository = container.Resolve <IScrumBotRepository>(); // Creating a Action<MessageReceived> for Slack Socket Client to get connected. MessageReceived messageReceive = new MessageReceived(); messageReceive.ok = true; Action <MessageReceived> showMethod = (MessageReceived messageReceived) => new MessageReceived(); //Connecting the bot of the given token client.Connect((connected) => { }); // Method will be called when someone sends message client.OnMessageReceived += (message) => { _logger.Info("Scrum bot got message :" + message); try { _logger.Info("Scrum bot got message, inside try"); string replyText = _scrumBotRepository.ProcessMessages(message.user, message.channel, message.text).Result; if (!String.IsNullOrEmpty(replyText)) { _logger.Info("Scrum bot got reply"); client.SendMessage(showMethod, message.channel, replyText); } } catch (Exception ex) { _logger.Error("\n" + _stringConstant.LoggerScrumBot + " " + ex.Message + "\n" + ex.StackTrace); client.CloseSocket(); throw ex; } }; //ChannelCreated channel = new ChannelCreated(); //client.HandleChannelCreated(channel); } catch (Exception ex) { _logger.Error("\n" + _stringConstant.LoggerScrumBot + " " + ex.Message + "\n" + ex.StackTrace); throw ex; } }
internal List <AwsDotnetCsharp.Models.Channel> GetChannels(List <string> channelIds) { var token = Environment.GetEnvironmentVariable("SLACK_ACCESS_TOKEN"); if (token == null) { throw new Exception("Error getting slack token from ssm"); } ManualResetEventSlim clientReady = new ManualResetEventSlim(false); SlackSocketClient client = new SlackSocketClient(token); client.Connect((connected) => { // This is called once the client has emitted the RTM start command clientReady.Set(); }, () => { // This is called once the RTM client has connected to the end point }); // client.OnMessageReceived += (message) => // { // // Handle each message as you receive them // }; clientReady.Wait(); client.GetChannelList((ulr) => { Console.WriteLine("got channels"); }); var channelList = new List <AwsDotnetCsharp.Models.Channel>(); foreach (var u in channelIds) { var slackChannels = client.Channels.Find(x => x.id.Equals(u)); channelList.Add(new Models.Channel { id = slackChannels.id, name = slackChannels.name }); } // Release the socket. client.CloseSocket(); return(channelList); }
public void Close() { PongCancellationTokenSource.Cancel(); SlackClient.CloseSocket(); }
public void StopIntegration() { client.CloseSocket(); }
public void Dispose() { slackClient?.CloseSocket(); }
/// <summary> /// Used for Scrum meeting bot connection and to conduct scrum meeting. - JJ /// </summary> public void Scrum() { SlackSocketClient client = new SlackSocketClient(_environmentVariableRepository.ScrumBotToken);//scrumBot // Creating a Action<MessageReceived> for Slack Socket Client to get connected. MessageReceived messageReceive = new MessageReceived(); messageReceive.ok = true; Action <MessageReceived> showMethod = (MessageReceived messageReceived) => new MessageReceived(); //Connecting the bot of the given token client.Connect((connected) => { _scrumBotId = connected.self.id; }); // Method will be called when someone sends message client.OnMessageReceived += (message) => { _scrumlogger.Debug("Scrum bot got message :" + message); try { IScrumBotRepository scrumBotRepository = _component.Resolve <IScrumBotRepository>(); _scrumlogger.Debug("Scrum bot got message : " + message.text + " From user : "******" Of channel : " + message.channel); string replyText = scrumBotRepository.ProcessMessagesAsync(message.user, message.channel, message.text, _scrumBotId).Result; _scrumlogger.Debug("Scrum bot got reply : " + replyText + " To user : "******" Of channel : " + message.channel); if (!String.IsNullOrEmpty(replyText)) { _scrumlogger.Debug("Scrum bot sending reply"); client.SendMessage(showMethod, message.channel, replyText); _scrumlogger.Debug("Scrum bot sent reply"); } } catch (TaskCanceledException ex) { client.SendMessage(showMethod, message.channel, _stringConstant.ErrorMsg); _scrumlogger.Trace(ex.StackTrace); _scrumlogger.Error("\n" + _stringConstant.LoggerScrumBot + " OAuth Server Not Responding " + ex.InnerException); client.CloseSocket(); throw ex; } catch (HttpRequestException ex) { client.SendMessage(showMethod, message.channel, _stringConstant.ErrorMsg); _scrumlogger.Trace(ex.StackTrace); _scrumlogger.Error("\n" + _stringConstant.LoggerScrumBot + " OAuth Server Closed \nInner exception :\n" + ex.InnerException); client.CloseSocket(); throw ex; } catch (Exception ex) { client.SendMessage(showMethod, message.channel, _stringConstant.ErrorMsg); _scrumlogger.Trace(ex.StackTrace); _scrumlogger.Error("\n" + _stringConstant.LoggerScrumBot + " Generic exception \nMessage : \n" + ex.Message + "\nInner exception :\n" + ex.InnerException); client.CloseSocket(); throw ex; } }; }
public override void Disconnect() { socketClient.CloseSocket(); }