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
|
||||
|
||||
```
|
||||
|
||||
## Debugging
|
||||
|
||||
Set the `OMIT_TG` environment variable to, well, omit sending anything over to Telegram and just see the logs instead.
|
||||
|
|
14
main.go
14
main.go
|
@ -61,11 +61,17 @@ func main() {
|
|||
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
|
||||
logger.Printf("Connected to Satel: %s", config.SatelAddr)
|
||||
|
||||
bot, err := tgbotapi.NewBotAPI(config.TelegramApiKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
var bot TelegramBotSender = nil
|
||||
if len(config.TelegramApiKey) != 0 {
|
||||
b, err := tgbotapi.NewBotAPI(config.TelegramApiKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logger.Print("Created Telegram Bot API client")
|
||||
bot = b
|
||||
} else {
|
||||
bot = EmptySender{}
|
||||
}
|
||||
logger.Print("Created Telegram Bot API client")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
type EmptySender struct{}
|
||||
|
||||
func (self EmptySender) Send(_ tgbotapi.Chattable) (tgbotapi.Message, error) {
|
||||
return tgbotapi.Message{}, nil
|
||||
}
|
||||
|
||||
type TgSender struct {
|
||||
bot TelegramBotSender
|
||||
s SatelNameGetter
|
||||
|
|
Loading…
Reference in New Issue