using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PepperBot; using PepperBot.Application.Interfaces; using PepperBot.Application.Services; using PepperBot.Infrastructure.Data; using PepperBot.Infrastructure.Health; using PepperBot.Infrastructure.Pepper; using PepperBot.Infrastructure.Telegram; using Telegram.Bot; var builder = WebApplication.CreateBuilder(args); builder.Services.AddLogging(logging => { logging.ClearProviders(); logging.AddConsole(); }); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); // Клиент Telegram-бота для приёма личных сообщений builder.Services.AddSingleton(_ => { var token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN") ?? string.Empty; return new TelegramBotClient(token); }); builder.Services.AddHostedService(); var app = builder.Build(); app.MapGet("/health", (IHealthMonitor healthMonitor) => { var successTtl = TimeSpan.FromMinutes(15); var isHealthy = healthMonitor.IsHealthy(successTtl); if (isHealthy) { return Results.Ok(new { status = "Healthy", lastSuccessfulRequestAt = healthMonitor.LastSuccessfulRequestAt }); } return Results.StatusCode(StatusCodes.Status503ServiceUnavailable); }); await app.RunAsync();