From 4e1d1ca35f33ef84f91b52dacc09ae3dd8c254ff Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Thu, 12 Feb 2026 17:39:38 +0300 Subject: [PATCH] explicit telegram enable flag --- cmd/remembos/main.go | 2 +- config.dist.toml | 3 +++ internal/config/config.go | 14 +++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/remembos/main.go b/cmd/remembos/main.go index 77d8c58..d97db85 100644 --- a/cmd/remembos/main.go +++ b/cmd/remembos/main.go @@ -85,7 +85,7 @@ func main() { defer stop() // Telegram bot - if cfg.Telegram.Token != "" { + if cfg.Telegram.Enabled { tgBot, err := telegram.NewBot(cfg.Telegram, memorySvc, client, cfg.Memos.URL, cfg.Memos.PublicURL, loc, logger) if err != nil { logger.Error("failed to create telegram bot", "error", err) diff --git a/config.dist.toml b/config.dist.toml index d09d095..516676b 100644 --- a/config.dist.toml +++ b/config.dist.toml @@ -85,6 +85,9 @@ tier7 = 8 # ============================================================================= [telegram] +# Включить Telegram-бот для ежедневной отправки воспоминаний. +enabled = false + # Токен бота, полученный от @BotFather. token = "" diff --git a/internal/config/config.go b/internal/config/config.go index b4b3ebe..44f41f5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -57,9 +57,10 @@ func (tw TierWeights) AsSlice() [7]int { } type TelegramConfig struct { - Token string `toml:"token"` - ChatID int64 `toml:"chat_id"` - SendAt string `toml:"send_at"` + Enabled bool `toml:"enabled"` + Token string `toml:"token"` + ChatID int64 `toml:"chat_id"` + SendAt string `toml:"send_at"` } type WebConfig struct { @@ -137,9 +138,12 @@ func validate(cfg *Config) error { if sum := cfg.Search.TierWeights.Sum(); sum != 100 { return fmt.Errorf("search.tier_weights must sum to 100, got %d", sum) } - if cfg.Telegram.Token != "" { + if cfg.Telegram.Enabled { + if cfg.Telegram.Token == "" { + return fmt.Errorf("telegram.token is required when telegram.enabled = true") + } if cfg.Telegram.ChatID == 0 { - return fmt.Errorf("telegram.chat_id is required when telegram.token is set") + return fmt.Errorf("telegram.chat_id is required when telegram.enabled = true") } if !timeFormatRe.MatchString(cfg.Telegram.SendAt) { return fmt.Errorf("telegram.send_at must be in HH:MM format, got %q", cfg.Telegram.SendAt)