From 584c9afe74c397fc1061555f56ef363b7b018764 Mon Sep 17 00:00:00 2001 From: Akulij Date: Tue, 25 Mar 2025 11:55:43 +0800 Subject: [PATCH] feature: add admin error notification function --- cmd/app/main.go | 15 +++++++++++++++ config/config.go | 1 + 2 files changed, 16 insertions(+) diff --git a/cmd/app/main.go b/cmd/app/main.go index 7a1f81b..c61ea67 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -35,6 +35,7 @@ func GetBotController() BotController { cfg := config.GetConfig() fmt.Printf("Token value: '%v'\n", cfg.BotToken) fmt.Printf("Admin password: '%v'\n", cfg.AdminPass) + fmt.Printf("Admin ID: '%v'\n", cfg.AdminID) bot, err := tgbotapi.NewBotAPI(cfg.BotToken) if err != nil { @@ -387,3 +388,17 @@ func DownloadFile(filepath string, url string) error { _, err = io.Copy(out, resp.Body) return err } + +func notifyAdminAboutError(bc BotController, errorMessage string) { + // Check if AdminID is set in the config + adminID := *bc.cfg.AdminID + if adminID != 0 { + msg := tgbotapi.NewMessage( + adminID, + fmt.Sprintf("Error occurred: %s", errorMessage), + ) + bc.bot.Send(msg) + } else { + log.Println("AdminID is not set in the configuration.") + } +} diff --git a/config/config.go b/config/config.go index b3ea3fc..019d65c 100644 --- a/config/config.go +++ b/config/config.go @@ -10,6 +10,7 @@ import ( type Config struct { BotToken string `env:"BOTTOKEN, required"` AdminPass string `env:"ADMINPASSWORD, required"` // to activate admin privileges in bot type command: /secret `AdminPass` + AdminID *int64 `env:"ADMINID"` // optional admin ID for notifications } func GetConfig() Config {