diff --git a/src/main/java/se/urmo/electricityalert/notifier/StartupNotifier.java b/src/main/java/se/urmo/electricityalert/notifier/StartupNotifier.java new file mode 100644 index 0000000..6667183 --- /dev/null +++ b/src/main/java/se/urmo/electricityalert/notifier/StartupNotifier.java @@ -0,0 +1,29 @@ +package se.urmo.electricityalert.notifier; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +public class StartupNotifier { + private static final Logger log = LoggerFactory.getLogger(StartupNotifier.class); + + private final TelegramNotifier telegramNotifier; + + public StartupNotifier(TelegramNotifier telegramNotifier) { + this.telegramNotifier = telegramNotifier; + } + + @EventListener(ApplicationReadyEvent.class) + public void notifyStartup() { + String msg = "🔄 Electricity Alert Service has restarted and is running."; + try { + telegramNotifier.send(msg); + log.info("Sent startup notification: {}", msg); + } catch (Exception e) { + log.warn("Failed to send startup notification", e); + } + } +}