babalae/better-genshin-impact · warning · NotifierException
Telegram chat ID is not set
Error message
Telegram chat ID is not set
What it means
TelegramNotifier.SendAsync fails fast when TelegramChatId is null/empty. The chat_id is required for both sendMessage and sendPhoto; without it Telegram returns 400.
Source
Thrown at BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs:115
throw new NotifierException($"Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}");
}
_httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
_ownsHttpClient = true;
}
TelegramApiBaseUrl = FormatApiBaseUrl(telegramApiBaseUrl);
}
public void Dispose()
{
if (_ownsHttpClient) _httpClient.Dispose();
}
public async Task SendAsync(BaseNotificationData content)
{
if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException("Telegram bot token is not set");
if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException("Telegram chat ID is not set");
if (string.IsNullOrEmpty(content.Message)) throw new NotifierException("No message content to send");
try
{
if (content.Screenshot != null)
{
await SendImageMessageAsync(content.Screenshot, content.Message.Length < 1024 ? content.Message : null);
if (content.Message.Length < 1024) return;
}
await SendTextMessageAsync(content.Message);
}
catch (HttpRequestException ex)
{
throw new NotifierException("Network error sending Telegram notification: " + ex.Message);
}
catch (TaskCanceledException)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Obtain the chat id: message the bot, then query getUpdates, or add the bot to a group and read the negative id.
- Save the chat id in settings; for groups use the negative numeric id.
- Validate the field is non-empty before enabling the channel.
Example fix
// before
var n = new TelegramNotifier(null, token, chatId);
// after
if (string.IsNullOrWhiteSpace(chatId))
throw new InvalidOperationException("Telegram chat id is required (use a positive user id or negative group id).");
var n = new TelegramNotifier(null, token, chatId); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(chatId))
throw new InvalidOperationException("Telegram chat id is required.");
if (!long.TryParse(chatId.TrimStart('-'), out _))
throw new InvalidOperationException("Telegram chat id must be numeric (user id or negative group id)."); Type guard
static bool IsValidTelegramChatId(string chatId)
=> !string.IsNullOrEmpty(chatId) && long.TryParse(chatId, out _); Try / catch
try { await telegramNotifier.SendAsync(data); }
catch (NotifierException ex) when (ex.Message.Contains("chat ID is not set"))
{ /* prompt user for chat id, no retry */ } Prevention
- Obtain the chat id by messaging the bot and calling getUpdates.
- For groups use the negative numeric id.
- Validate the field is set before enabling the channel.
When it happens
Trigger: TelegramChatId property empty at SendAsync time; line-115 IsNullOrEmpty guard fires.
Common situations: User configured the bot token but not the chat id; for groups, the user forgot to add the bot to the group and read the chat id; negative group id vs positive user id confusion not handled (both are strings here).
Related errors
- Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.
- Telegram bot token is not set
- MeoW 昵称为空
- OneBot endpoint is not set
- OneBot requires either a user ID or group ID
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/52149ca827066d1d.
Report an issue: GitHub.