{"record":{"id":"476daf1e82b93f2d","repo":"babalae/better-genshin-impact","slug":"telegram-bot-token-is-not-set","errorCode":null,"errorMessage":"Telegram bot token is not set","messagePattern":"Telegram bot token is not set","errorType":"validation","errorClass":"NotifierException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs","lineNumber":114,"sourceCode":"                    // 抛出异常以通知调用者配置错误\n                    throw new NotifierException($\"Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}\");\n                }\n\n            _httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };\n            _ownsHttpClient = true;\n        }\n\n        TelegramApiBaseUrl = FormatApiBaseUrl(telegramApiBaseUrl);\n    }\n\n    public void Dispose()\n    {\n        if (_ownsHttpClient) _httpClient.Dispose();\n    }\n\n    public async Task SendAsync(BaseNotificationData content)\n    {\n        if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException(\"Telegram bot token is not set\");\n        if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException(\"Telegram chat ID is not set\");\n        if (string.IsNullOrEmpty(content.Message)) throw new NotifierException(\"No message content to send\");\n\n        try\n        {\n            if (content.Screenshot != null)\n            {\n                await SendImageMessageAsync(content.Screenshot, content.Message.Length < 1024 ? content.Message : null);\n                if (content.Message.Length < 1024) return;\n            }\n\n            await SendTextMessageAsync(content.Message);\n        }\n        catch (HttpRequestException ex)\n        {\n            throw new NotifierException(\"Network error sending Telegram notification: \" + ex.Message);\n        }\n        catch (TaskCanceledException)","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs#L96-L132","documentation":"TelegramNotifier.SendAsync fails fast when TelegramBotToken is null/empty. The token (from BotFather, format <botid>:<hash>) is required to build the API URL {baseUrl}{token}/send*.","triggerScenarios":"TelegramBotToken property empty at SendAsync time (default constructor arg was \"\"); line-114 IsNullOrEmpty guard fires.","commonSituations":"User enabled Telegram channel without pasting a bot token; token field cleared; new install with no token configured.","solutions":["Create a bot via @BotFather on Telegram and paste the token into settings.","Block enabling the Telegram channel in the UI until a token is provided.","Validate token shape (contains a colon) before construction."],"exampleFix":"// before\nvar n = new TelegramNotifier(null, token, chatId);\n\n// after\nif (!Regex.IsMatch(token ?? \"\", @\"^\\d+:.+$\"))\n    throw new InvalidOperationException(\"Telegram bot token looks invalid (expected <numericBotId>:<hash>).\");\nvar n = new TelegramNotifier(null, token, chatId);","handlingStrategy":"validation","validationCode":"if (!Regex.IsMatch(token ?? \"\", @\"^\\d{6,}:[A-Za-z0-9_-]{30,}$\"))\n    throw new InvalidOperationException(\"Telegram bot token is missing or malformed (expected <botId>:<hash>).\");","typeGuard":"static bool LooksLikeTelegramBotToken(string token)\n    => !string.IsNullOrEmpty(token) && token.Contains(':') && token.Split(':')[0].All(char.IsDigit);","tryCatchPattern":"try { await telegramNotifier.SendAsync(data); }\ncatch (NotifierException ex) when (ex.Message.Contains(\"bot token is not set\"))\n{ /* prompt user to create a bot via BotFather and paste token, no retry */ }","preventionTips":["Create the bot with @BotFather and paste the token at settings time.","Block enabling the Telegram channel until a token is entered.","Validate token shape before allowing the user to save."],"tags":["telegram","config","validation","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}