diff --git a/Dockerfile b/Dockerfile index 90553f9..039349e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0.101-jammy as build-env +FROM mcr.microsoft.com/dotnet/sdk:7.0.402-jammy as build-env WORKDIR /src/VahterBanBot COPY src/VahterBanBot/VahterBanBot.fsproj . RUN dotnet restore @@ -6,7 +6,7 @@ COPY src/VahterBanBot . COPY global.json . RUN dotnet publish -c Release -o /publish -FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime +FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime WORKDIR /publish COPY --from=build-env /publish . ENTRYPOINT ["dotnet", "VahterBanBot.dll"] diff --git a/global.json b/global.json index f2068dc..ad69c0c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "8.0.101" + "version": "7.0.402" } } \ No newline at end of file diff --git a/src/VahterBanBot/Program.fs b/src/VahterBanBot/Program.fs index 7c2dda8..6da9215 100644 --- a/src/VahterBanBot/Program.fs +++ b/src/VahterBanBot/Program.fs @@ -10,7 +10,7 @@ open Newtonsoft.Json open Telegram.Bot open Telegram.Bot.Polling open Telegram.Bot.Types -open Oxpecker +open Giraffe open Microsoft.Extensions.DependencyInjection open Telegram.Bot.Types.Enums open VahterBanBot @@ -50,7 +50,7 @@ let requiresApiKey = authorizeRequest validateApiKey accessDenied let builder = WebApplication.CreateBuilder() %builder.Services .AddSingleton(botConf) - .AddOxpecker() + .AddGiraffe() .AddHostedService() .AddHttpClient("telegram_bot_client") .AddTypedClient(fun httpClient sp -> @@ -102,11 +102,12 @@ getEnvWith "APPLICATIONINSIGHTS_CONNECTION_STRING" (fun appInsightKey -> ) %builder.Logging.AddConsole() - -let webApp = [ + +let webApp = choose [ // need for Azure health checks on any route - GET [ route "{**x}" <| text "OK" ] - POST [ route botConf.Route (requiresApiKey >=> bindJson (fun update ctx -> task { + GET >=> text "OK" + + POST >=> route botConf.Route >=> requiresApiKey >=> bindJson (fun update next ctx -> task { use scope = ctx.RequestServices.CreateScope() let telegramClient = scope.ServiceProvider.GetRequiredService() let logger = ctx.GetLogger() @@ -114,12 +115,13 @@ let webApp = [ do! onUpdate telegramClient botConf (ctx.GetLogger "VahterBanBot.Bot") update.Message with e -> logger.LogError(e, "Unexpected error while processing update") - }))] + return! Successful.OK() next ctx + }) ] let app = builder.Build() -%app.UseRouting().UseOxpecker webApp +app.UseGiraffe(webApp) let server = app.RunAsync() let telegramClient = app.Services.GetRequiredService() diff --git a/src/VahterBanBot/VahterBanBot.fsproj b/src/VahterBanBot/VahterBanBot.fsproj index bc92fbf..0093d98 100644 --- a/src/VahterBanBot/VahterBanBot.fsproj +++ b/src/VahterBanBot/VahterBanBot.fsproj @@ -2,7 +2,7 @@ Exe - net8.0 + net7.0 true @@ -19,6 +19,7 @@ + @@ -30,7 +31,6 @@ -