feature: add admin error notification function
This commit is contained in:
parent
973a85061c
commit
584c9afe74
@ -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.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user