diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TelegramMonitorService.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TelegramMonitorService.java index 4ad2172d..8cc04506 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TelegramMonitorService.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/TelegramMonitorService.java @@ -44,6 +44,11 @@ public class TelegramMonitorService { @PostConstruct public void init() { + if (telegramProperties.getBot() == null || telegramProperties.getBot().getToken() == null) { + log.warn("Telegram 配置未启用,跳过初始化"); + return; + } + String botToken = telegramProperties.getBot().getToken(); List chatIds = telegramProperties.getMonitor().getChatIds(); int alertLimitSeconds = telegramProperties.getMonitor().getAlertLimitSeconds(); @@ -191,7 +196,16 @@ public class TelegramMonitorService { * 发送到所有配置的 chatId */ private void sendToAllChats(String message) { + if (telegramClient == null) { + log.warn("Telegram 未初始化,跳过发送"); + return; + } + List chatIds = telegramProperties.getMonitor().getChatIds(); + if (chatIds == null || chatIds.isEmpty()) { + log.warn("Telegram chatIds 未配置,跳过发送"); + return; + } for (String chatId : chatIds) { sendTextToChat(chatId, message); }