fix: Allow UpdateBotTokenAsync to start bot when not previously running
All checks were successful
Build and Deploy LittleShop / Deploy to Production VPS (Manual Only) (push) Has been skipped
Build and Deploy LittleShop / Deploy to Pre-Production (CT109) (push) Successful in 59s

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 <noreply@anthropic.com>
This commit is contained in:
SysAdmin 2025-11-25 17:04:53 +00:00
parent f367a98c53
commit a975a9e914

View File

@ -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;