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)); }
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)); }
public Task <FilterResult> FilterAsync(FilterAttribute attribute, MiddlewareData data) { var principal = data.Features.RequireOne <AuthenticationFeature>().Principal; if (!principal.IsAuthenticated()) { var message = new BaseOutMessage() { Text = "Unauthorized access" }; var result = FilterResult.BreakExecution(data.AddRenderMessageFeature(message)); return(Task.FromResult(result)); } return(Task.FromResult(FilterResult.NextFilter(data))); }
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))); }