Exemplo n.º 1
0
        public async Task MessageReceived(SlackMessage message)
        {
            Console.WriteLine("[[[Message started]]]");

            IMiddleware pipeline        = _pipelineFactory.GetPipeline();
            var         incomingMessage = new IncomingMessage
            {
                RawText        = message.Text,
                FullText       = message.Text,
                UserId         = message.User.Id,
                Username       = GetUsername(message),
                Channel        = message.ChatHub.Id,
                ChannelType    = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel,
                UserChannel    = await GetUserChannel(message),
                BotName        = _connection.Self.Name,
                BotId          = _connection.Self.Id,
                BotIsMentioned = message.MentionsBot
            };

            incomingMessage.TargetedText = incomingMessage.GetTargetedText();

            try
            {
                foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage))
                {
                    await SendMessage(responseMessage);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR WHILE PROCESSING MESSAGE: {0}", ex);
            }

            Console.WriteLine("[[[Message ended]]]");
        }
Exemplo n.º 2
0
        public async Task MessageReceived(SlackMessage message)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            _logger.LogInformation($"[Message found from '{message.User.Name}']");

            IMiddleware pipeline        = _container.GetMiddlewarePipeline();
            var         incomingMessage = new IncomingMessage
            {
                RawText        = message.Text,
                FullText       = message.Text,
                UserId         = message.User.Id,
                Username       = GetUsername(message),
                UserEmail      = message.User.Email,
                Channel        = message.ChatHub.Id,
                ChannelType    = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel,
                UserChannel    = await GetUserChannel(message),
                BotName        = _connection.Self.Name,
                BotId          = _connection.Self.Id,
                BotIsMentioned = message.MentionsBot
            };

            DataAccess dataAccess = new DataAccess("Server=(localdb)\\mssqllocaldb; Database=Reczept");
            User       user       = new User()
            {
                MemberId = incomingMessage.UserId,
                Name     = incomingMessage.Username
            };

            dataAccess.CheckIfExistingUser(user);
            _logger.LogInformation($"[User Created]");
            incomingMessage.TargetedText = incomingMessage.GetTargetedText();

            try
            {
                foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage))
                {
                    await SendMessage(responseMessage);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"ERROR WHILE PROCESSING MESSAGE: {ex}");
            }

            stopwatch.Stop();

            _logger.LogInformation($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]");
            _averageResponse.Log(stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 3
0
        public async Task MessageReceived(SlackMessage message)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            _log.Log($"[Message found from '{message.User.Name}']");

            IMiddleware pipeline        = _container.GetMiddlewarePipeline();
            var         incomingMessage = new IncomingMessage
            {
                RawText        = message.Text,
                FullText       = message.Text,
                UserId         = message.User.Id,
                Username       = GetUsername(message),
                Channel        = message.ChatHub.Id,
                ChannelType    = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel,
                UserChannel    = await GetUserChannel(message),
                BotName        = _connection.Self.Name,
                BotId          = _connection.Self.Id,
                BotIsMentioned = message.MentionsBot
            };

            incomingMessage.TargetedText = incomingMessage.GetTargetedText();

            try
            {
                foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage))
                {
                    await SendMessage(responseMessage);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    await SendMessage(incomingMessage.ReplyToChannel($"@{incomingMessage.Username} Uh Oh! Something went on fire!"));
                }
                catch
                {
                    _log.Log("Unable to send error code to chat");
                }
                _log.Log($"ERROR WHILE PROCESSING MESSAGE: {ex}");
            }

            stopwatch.Stop();

            _log.Log($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]");
            _averageResponse.Log(stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public async Task MessageReceived(SlackMessage message)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            this._logger.LogInformation($"[Message found from '{message.User.Name}']");

            IMiddleware pipeline        = this._container.GetMiddlewarePipeline();
            var         incomingMessage = new IncomingMessage
            {
                RawText     = message.Text,
                FullText    = message.Text,
                UserId      = message.User.Id,
                Username    = this.GetUsername(message),
                UserEmail   = message.User.Email,
                Channel     = message.ChatHub.Id,
                ChannelType = message.ChatHub.Type == SlackChatHubType.DM
                    ? ResponseType.DirectMessage
                    : ResponseType.Channel,
                UserChannel    = await this.GetUserChannel(message),
                BotName        = this._connection.Self.Name,
                BotId          = this._connection.Self.Id,
                BotIsMentioned = message.MentionsBot
            };

            incomingMessage.TargetedText = incomingMessage.GetTargetedText();

            try
            {
                foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage))
                {
                    await this.SendMessage(responseMessage);
                }
            }
            catch (Exception ex)
            {
                this._logger.LogError($"ERROR WHILE PROCESSING MESSAGE: {ex}");
            }

            stopwatch.Stop();

            this._logger.LogInformation($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]");
            this._averageResponse.Log(stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 5
0
        public async Task MessageReceived(SlackMessage message)
        {
            using (_metrics.Measure.Timer.Time(ResponseOptions))
            {
                _logger.LogInformation($"[Message found from '{message.User.Name}']");

                IMiddleware pipeline        = null;//_container.GetMiddlewarePipeline();
                var         incomingMessage = new IncomingMessage
                {
                    RawText        = message.Text,
                    FullText       = message.Text,
                    UserId         = message.User.Id,
                    Username       = GetUsername(message),
                    UserEmail      = message.User.Email,
                    Channel        = message.ChatHub.Id,
                    ChannelType    = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel,
                    UserChannel    = await GetUserChannel(message),
                    BotName        = _connection.Self.Name,
                    BotId          = _connection.Self.Id,
                    BotIsMentioned = message.MentionsBot
                };

                incomingMessage.TargetedText = incomingMessage.GetTargetedText();

                try
                {
                    foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage))
                    {
                        await SendMessage(responseMessage);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"ERROR WHILE PROCESSING MESSAGE: {ex}");
                }
            }
        }