public override MiddlewareData HandleException(MiddlewareData middlewareData, NoSuchHandlerException exception)
        {
            _logger.LogInformation("Cannot find handler for message");
            var message = new BaseOutMessage()
            {
                Text = "Unknown command"
            };

            return(middlewareData.AddRenderMessageFeature(message));
        }
示例#2
0
        public override MiddlewareData HandleException(MiddlewareData middlewareData, Exception exception)
        {
            _logger.LogError(0, exception, "Unexpected error occurred");
            var message = new BaseOutMessage()
            {
                Text = $"Error occured: [{exception.GetType().Name}] {exception.Message}"
            };

            return(middlewareData.AddRenderMessageFeature(message));
        }
示例#3
0
        public Task <FilterResult> FilterAsync(FilterAttribute attribute, MiddlewareData data)
        {
            var principal = data.Features.RequireOne <AuthenticationFeature>().Principal;

            if (!principal.Is​Authenticated())
            {
                var message = new BaseOutMessage()
                {
                    Text = "Unauthorized access"
                };
                var result = FilterResult.BreakExecution(data.AddRenderMessageFeature(message));
                return(Task.FromResult(result));
            }
            return(Task.FromResult(FilterResult.NextFilter(data)));
        }
示例#4
0
            public Task <MiddlewareData> RenderAsync(MiddlewareData data)
            {
                var messageContent = new MessageContent(Text);

                InlineKeyboardMarkup.Nullable().IfPresent(m => messageContent.ReplyMarkup = m);

                var message = new TelegramOutMessage(messageContent)
                {
                    UpdateMessage = Update,
                    MessageId     = MessageId,
                    ChatId        = ChatId
                };

                return(Task.FromResult(data.AddRenderMessageFeature(message)));
            }