{"record":{"id":"bc115598cde9d714","repo":"babalae/better-genshin-impact","slug":"telegram-api-request-timed-out-check-your-interne","errorCode":null,"errorMessage":"Telegram API request timed out. Check your internet connection.","messagePattern":"Telegram API request timed out\\. Check your internet connection\\.","errorType":"exception","errorClass":"NotifierException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs","lineNumber":134,"sourceCode":"        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)\n        {\n            throw new NotifierException(\"Telegram API request timed out. Check your internet connection.\");\n        }\n        catch (System.Exception ex) when (ex is not NotifierException)\n        {\n            throw new NotifierException(\"Error sending Telegram notification: \" + ex.Message);\n        }\n    }\n\n    private async Task SendImageMessageAsync(Image<Rgb24> image, string? caption)\n    {\n        var endpoint = $\"{TelegramApiBaseUrl}{TelegramBotToken}/sendPhoto\";\n        using var memoryStream = new MemoryStream();\n        await image.SaveAsPngAsync(memoryStream);\n        memoryStream.Position = 0;\n\n        var content = new MultipartFormDataContent\n        {\n            { new StreamContent(memoryStream), \"photo\", \"image.png\" },\n            { new StringContent(TelegramChatId), \"chat_id\" }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs#L116-L152","documentation":"Wraps TaskCanceledException — fires when the HttpClient request exceeds the 30-second timeout configured in the ctor (or the task is explicitly cancelled). Indicates the request was sent but no timely response arrived.","triggerScenarios":"_httpClient.SendAsync does not complete within TimeSpan.FromSeconds(30); the CancellationToken (none passed here) would also surface as TaskCanceledException.","commonSituations":"Slow/blocked network reaching Telegram; large screenshot upload over a throttled proxy; regional blocking causing TCP hangs; the 30s timeout too low for big images on poor links.","solutions":["Confirm connectivity to api.telegram.org (or raise the timeout for large image uploads).","If using a proxy, ensure it has adequate bandwidth and is not stalling.","Consider increasing the 30s timeout for sendPhoto payloads.","Implement one retry on TaskCanceledException before reporting failure."],"exampleFix":"// before\n_httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };\n\n// after — longer timeout for image-capable notifier + retry\n_httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(60) };\n// and in SendAsync:\n// catch (TaskCanceledException) when (!cancellationToken.IsCancellationRequested)\n//     => transient timeout, retry once","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (int attempt = 0; ; attempt++)\ntry { await telegramNotifier.SendAsync(data); break; }\ncatch (NotifierException ex) when (ex.Message.Contains(\"timed out\") && attempt < 1)\n{ await Task.Delay(TimeSpan.FromSeconds(5)); }","preventionTips":["Raise the HttpClient timeout for large image uploads.","Ensure the proxy is not stalling.","Retry once on timeout before surfacing."],"tags":["telegram","timeout","network","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}