Notify creator on bot startup and enhance config

Added a startup notification to the creator with the current bot version. Refactored ADMIN_IDS to a List, introduced CREATOR_ID and SOURCE_VERSION constants in Config, and improved environment variable handling.
This commit is contained in:
2025-11-07 21:04:02 +07:00
parent b67aa4f77f
commit cced06fda9
2 changed files with 17 additions and 3 deletions
@@ -1,6 +1,10 @@
package com.miti99.storescraperbot;
import static com.miti99.storescraperbot.config.Config.CREATOR_ID;
import static com.miti99.storescraperbot.config.Config.SOURCE_VERSION;
import com.miti99.storescraperbot.bot.StoreScrapeBot;
import com.miti99.storescraperbot.bot.StoreScrapeBotTelegramClient;
import com.miti99.storescraperbot.config.Config;
import com.miti99.storescraperbot.repository.AdminRepository;
import lombok.extern.log4j.Log4j2;
@@ -15,6 +19,8 @@ public class Main {
try (var botsApplication = new TelegramBotsLongPollingApplication()) {
botsApplication.registerBot(Config.TELEGRAM_BOT_TOKEN, StoreScrapeBot.INSTANCE);
log.info("StoreScrapeBot successfully started!");
StoreScrapeBotTelegramClient.INSTANCE.sendMessage(
CREATOR_ID, "Bot started! Version <code>%s</code>".formatted(SOURCE_VERSION));
Thread.currentThread().join();
} catch (Exception e) {
log.error("Error while running bot", e);
@@ -1,8 +1,10 @@
package com.miti99.storescraperbot.config;
import com.google.common.base.Strings;
import com.miti99.storescraperbot.type.Env;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -18,7 +20,7 @@ public class Config {
public static final String TELEGRAM_BOT_USERNAME = System.getenv("TELEGRAM_BOT_USERNAME");
public static final Env ENV = Env.valueOf(System.getenv("ENV"));
public static final Set<Long> ADMIN_IDS =
public static final List<Long> ADMIN_IDS =
Optional.ofNullable(System.getenv("ADMIN_IDS"))
.map(
v ->
@@ -26,6 +28,12 @@ public class Config {
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Long::parseLong)
.collect(Collectors.toSet()))
.orElse(Collections.emptySet());
.collect(Collectors.toList()))
.orElse(Collections.emptyList());
public static final long CREATOR_ID = ADMIN_IDS.getFirst();
public static final String SOURCE_VERSION =
Strings.isNullOrEmpty(System.getenv("SOURCE_VERSION"))
? "unknown"
: System.getenv("SOURCE_VERSION");
}