1
0
Fork 0

Omit telegram if no bot api key is provided

This commit is contained in:
Michał Rudowicz 2025-01-03 21:47:07 +01:00
parent f6ff93c783
commit 803a174ace
3 changed files with 16 additions and 8 deletions

View File

@ -150,7 +150,3 @@ MemoryMax=50M
WantedBy=multi-user.target WantedBy=multi-user.target
``` ```
## Debugging
Set the `OMIT_TG` environment variable to, well, omit sending anything over to Telegram and just see the logs instead.

View File

@ -61,11 +61,17 @@ func main() {
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration()) s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
logger.Printf("Connected to Satel: %s", config.SatelAddr) logger.Printf("Connected to Satel: %s", config.SatelAddr)
bot, err := tgbotapi.NewBotAPI(config.TelegramApiKey) var bot TelegramBotSender = nil
if len(config.TelegramApiKey) != 0 {
b, err := tgbotapi.NewBotAPI(config.TelegramApiKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }
logger.Print("Created Telegram Bot API client") logger.Print("Created Telegram Bot API client")
bot = b
} else {
bot = EmptySender{}
}
tgSender := TgSender{bot, s, log.New(os.Stderr, "TgFormatter", log.Lmicroseconds), config.ChatIds} tgSender := TgSender{bot, s, log.New(os.Stderr, "TgFormatter", log.Lmicroseconds), config.ChatIds}

View File

@ -11,6 +11,12 @@ type TelegramBotSender interface {
Send(c tgbotapi.Chattable) (tgbotapi.Message, error) Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
} }
type EmptySender struct{}
func (self EmptySender) Send(_ tgbotapi.Chattable) (tgbotapi.Message, error) {
return tgbotapi.Message{}, nil
}
type TgSender struct { type TgSender struct {
bot TelegramBotSender bot TelegramBotSender
s SatelNameGetter s SatelNameGetter