Omit telegram if no bot api key is provided
This commit is contained in:
parent
f6ff93c783
commit
803a174ace
|
@ -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.
|
|
||||||
|
|
8
main.go
8
main.go
|
@ -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}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue