Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dodo1000Bot.Api/Dodo1000Bot.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.29.1</Version>
<Version>1.29.2</Version>
<UserSecretsId>f449de95-800a-40ef-8716-6e80b7f0977d</UserSecretsId>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.*" />
<PackageReference Include="Telegram.Bot" Version="16.*" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ await _client.SendTextMessageAsync(messengerUserId, notification.Payload.Text,
catch (Exception e)
{
_log.LogError(e, "Error while send notification to {MessengerUserId}", messengerUserId);
return pushedNotifications;
continue;
}

var pushedNotification = new PushedNotification
Expand Down
35 changes: 25 additions & 10 deletions Dodo1000Bot.Messengers.Telegram/TelegramStartup.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using Dodo1000Bot.Messengers.Telegram;
using Dodo1000Bot.Models;
using Dodo1000Bot.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Telegram.Bot;

[assembly: HostingStartup(typeof(TelegramStartup))]
namespace Dodo1000Bot.Messengers.Telegram
{
public class TelegramStartup : IHostingStartup
{
private const string TelegramHttpClientName = "telegram-bot";

public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddConfiguration<TelegramConfiguration>("appsettings.Telegram.json", Source.Telegram.ToString());

services.AddHttpClient(TelegramHttpClientName, client =>
{
client.Timeout = TimeSpan.FromMinutes(3);
})
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
{
PooledConnectionLifetime = TimeSpan.FromMinutes(5),
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2),
})
.SetHandlerLifetime(Timeout.InfiniteTimeSpan)
.AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(
retryCount: 3,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt))));

services.AddTransient<ITelegramService, TelegramService>();
services.AddTransient<ITelegramBotClient>(RegisterTelegramClient);
services.AddSingleton<ITelegramBotClient>(RegisterTelegramClient);
services.AddTransient<INotifyService, TelegramNotifyService>();
});
}

private TelegramBotClient RegisterTelegramClient(IServiceProvider provider)
private static TelegramBotClient RegisterTelegramClient(IServiceProvider provider)
{
var configuration = provider.GetService<TelegramConfiguration>();

var telegramClient = new TelegramBotClient(configuration.Token)
{
Timeout = TimeSpan.FromMinutes(3)
};
var configuration = provider.GetRequiredService<TelegramConfiguration>();
var httpClient = provider.GetRequiredService<IHttpClientFactory>().CreateClient(TelegramHttpClientName);

return telegramClient;
return new TelegramBotClient(configuration.Token, httpClient);
}
}
}
2 changes: 1 addition & 1 deletion Dodo1000Bot.Services/Dodo1000Bot.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.*" />
<PackageReference Include="MySql.Data" Version="8.0.33" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="StackExchange.Redis" Version="2.*" />
<PackageReference Include="StackExchange.Redis" Version="2.12.14" />
<PackageReference Include="AutoMapper" Version="10.*" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.*" />
<PackageReference Include="System.ServiceModel.Http" Version="4.*" />
Expand Down
Loading