Skip to content

Commit

Permalink
Revert "migrated to oxpecker" (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer authored Jan 22, 2024
1 parent df6ace9 commit 2ece977
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
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"]
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.101"
"version": "7.0.402"
}
}
18 changes: 10 additions & 8 deletions src/VahterBanBot/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,7 +50,7 @@ let requiresApiKey = authorizeRequest validateApiKey accessDenied
let builder = WebApplication.CreateBuilder()
%builder.Services
.AddSingleton(botConf)
.AddOxpecker()
.AddGiraffe()
.AddHostedService<CleanupService>()
.AddHttpClient("telegram_bot_client")
.AddTypedClient(fun httpClient sp ->
Expand Down Expand Up @@ -102,24 +102,26 @@ 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<Update> (fun update ctx -> task {
GET >=> text "OK"

POST >=> route botConf.Route >=> requiresApiKey >=> bindJson<Update> (fun update next ctx -> task {
use scope = ctx.RequestServices.CreateScope()
let telegramClient = scope.ServiceProvider.GetRequiredService<ITelegramBotClient>()
let logger = ctx.GetLogger<Root>()
try
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.UseOxpecker webApp
app.UseGiraffe(webApp)
let server = app.RunAsync()

let telegramClient = app.Services.GetRequiredService<ITelegramBotClient>()
Expand Down
4 changes: 2 additions & 2 deletions src/VahterBanBot/VahterBanBot.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

Expand All @@ -19,6 +19,7 @@
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.0.0-beta.7" />
<PackageReference Include="Dapper" Version="2.0.151" />
<PackageReference Include="Dapper.FSharp" Version="4.7.0" />
<PackageReference Include="Giraffe" Version="6.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.11" />
Expand All @@ -30,7 +31,6 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" />
<PackageReference Include="Oxpecker" Version="0.4.0" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>

Expand Down

0 comments on commit 2ece977

Please sign in to comment.