From a975a9e914cc32703829f0451e68a53e08878ff7 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Tue, 25 Nov 2025 17:04:53 +0000 Subject: [PATCH] fix: Allow UpdateBotTokenAsync to start bot when not previously running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When TeleBot starts without a token configured, the TelegramBotService returns early from StartAsync without creating a bot client. Previously, UpdateBotTokenAsync only worked when _botClient was already initialized. This fix changes the condition to also start the bot if _botClient is null, enabling remote configuration via the discovery API to properly start Telegram polling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- TeleBot/TeleBot/TelegramBotService.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/TeleBot/TeleBot/TelegramBotService.cs b/TeleBot/TeleBot/TelegramBotService.cs index 9363a36..482ea36 100644 --- a/TeleBot/TeleBot/TelegramBotService.cs +++ b/TeleBot/TeleBot/TelegramBotService.cs @@ -229,12 +229,16 @@ namespace TeleBot public async Task UpdateBotTokenAsync(string newToken) { - if (_botClient != null && _currentBotToken != newToken) + // If bot wasn't started or token changed, start/restart + if (_currentBotToken != newToken || _botClient == null) { - _logger.LogInformation("Updating bot token and restarting bot..."); + _logger.LogInformation("Starting/updating bot with new token..."); - // Stop current bot - _cancellationTokenSource?.Cancel(); + // Stop current bot if running + if (_botClient != null) + { + _cancellationTokenSource?.Cancel(); + } // Create new bot client with new token and TOR support _currentBotToken = newToken;