Add Telegram bot integration and enhance user management features
- Introduced Telegram.Bot package for bot functionality. - Updated user management to include Telegram linking and blocking features. - Enhanced activation request handling with notifications via Telegram. - Added new database entities for Telegram link tokens and login requests. - Implemented traffic synchronization for client stats in the XuiPanelGateway. - Updated application structure to support new test projects and improved dependency injection for Telegram services.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using PnvPanel.Infrastructure.Telegram;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace PnvPanel.Api.Telegram;
|
||||
|
||||
/// <summary>
|
||||
/// Бот — presentation-адаптер, хостится в процессе Api (long polling). Если BotToken не задан,
|
||||
/// не стартует — панель работает без бота. Апдейты обрабатывает PnvBotUpdateHandler, который
|
||||
/// вызывает те же CQRS-команды, что и веб, через собственный ISender.
|
||||
/// </summary>
|
||||
public sealed class TelegramBotHostedService(
|
||||
ITelegramBotClient botClient, PnvBotUpdateHandler updateHandler, IOptions<TelegramOptions> options,
|
||||
ILogger<TelegramBotHostedService> logger)
|
||||
: BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(options.Value.BotToken))
|
||||
{
|
||||
logger.LogWarning("Telegram__BotToken не задан — бот не стартует.");
|
||||
return;
|
||||
}
|
||||
|
||||
var receiverOptions = new ReceiverOptions
|
||||
{
|
||||
AllowedUpdates = [UpdateType.Message, UpdateType.CallbackQuery],
|
||||
DropPendingUpdates = true,
|
||||
};
|
||||
|
||||
logger.LogInformation("Telegram-бот запускается (long polling)...");
|
||||
|
||||
try
|
||||
{
|
||||
await botClient.ReceiveAsync(updateHandler, receiverOptions, stoppingToken);
|
||||
}
|
||||
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
// Штатная остановка вместе с приложением.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user