Логирование ошибок отправки оповещений в телеграм.
test / deploy_trader_prod (push) Successful in 3m0s
Details
test / deploy_trader_prod (push) Successful in 3m0s
Details
parent
196e0246d7
commit
dbacad168a
|
@ -1,6 +1,7 @@
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Interfaces;
|
using KLHZ.Trader.Core.Contracts.Messaging.Interfaces;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
@ -15,9 +16,11 @@ namespace KLHZ.Trader.Core.TG.Services
|
||||||
private readonly IUpdateHandler _updateHandler;
|
private readonly IUpdateHandler _updateHandler;
|
||||||
private readonly Channel<IMessage> _messages = Channel.CreateUnbounded<IMessage>();
|
private readonly Channel<IMessage> _messages = Channel.CreateUnbounded<IMessage>();
|
||||||
private readonly ImmutableArray<long> _admins = [];
|
private readonly ImmutableArray<long> _admins = [];
|
||||||
|
private readonly ILogger<BotStarter> _logger;
|
||||||
|
|
||||||
public BotStarter(IOptions<TgBotConfig> cfg, IUpdateHandler updateHandler, IDataBus dataBus, IOptions<TgBotConfig> options)
|
public BotStarter(IOptions<TgBotConfig> cfg, IUpdateHandler updateHandler, IDataBus dataBus, IOptions<TgBotConfig> options, ILogger<BotStarter> logger)
|
||||||
{
|
{
|
||||||
|
_logger = logger;
|
||||||
_botClient = new TelegramBotClient(cfg.Value.Token);
|
_botClient = new TelegramBotClient(cfg.Value.Token);
|
||||||
_updateHandler = updateHandler;
|
_updateHandler = updateHandler;
|
||||||
dataBus.AddChannel(string.Empty, _messages);
|
dataBus.AddChannel(string.Empty, _messages);
|
||||||
|
@ -31,9 +34,17 @@ namespace KLHZ.Trader.Core.TG.Services
|
||||||
{
|
{
|
||||||
var message = await _messages.Reader.ReadAsync();
|
var message = await _messages.Reader.ReadAsync();
|
||||||
foreach (var admin in _admins)
|
foreach (var admin in _admins)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
await _botClient.SendMessage(admin, message.Text);
|
await _botClient.SendMessage(admin, message.Text);
|
||||||
}
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при отправке сообщения в бота.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue