diff --git a/main.go b/main.go index ae1c527..4c95f26 100644 --- a/main.go +++ b/main.go @@ -114,9 +114,9 @@ func (web *Web) initNotifiers() { web.notifiers = make(map[string]notifiers.Notifier, 5) if viper.IsSet("telegram") { telegramBot := notifiers.TelegramNotifier{} - telegramBot.Open() - web.notifiers["Telegram"] = telegramBot - + if telegramBot.Open() { + web.notifiers["Telegram"] = &telegramBot + } } } @@ -124,6 +124,7 @@ func (web *Web) notify(notifierKey string, message string) { notifier, exists := web.notifiers[notifierKey] if !exists { log.Println("Could not find notifier with key:", notifierKey) + return } notifier.Message(message) } diff --git a/notifiers/telegram.go b/notifiers/telegram.go index 5117b94..1ad161b 100644 --- a/notifiers/telegram.go +++ b/notifiers/telegram.go @@ -13,7 +13,7 @@ type TelegramNotifier struct { Debug bool } -func (telegram TelegramNotifier) Open() bool { +func (telegram *TelegramNotifier) Open() bool { bot, err := tgbotapi.NewBotAPI(viper.GetString("telegram.token")) if err != nil { log.Println("Could not start Telegram notifier:\n", err) @@ -25,8 +25,12 @@ func (telegram TelegramNotifier) Open() bool { return true } -func (telegram TelegramNotifier) Message(message string) bool { +func (telegram *TelegramNotifier) Message(message string) bool { + log.Println(telegram) + log.Println(message) msg := tgbotapi.NewMessage(viper.GetInt64("telegram.chat"), message) + log.Println(msg) + log.Println(telegram.Bot) _, err := telegram.Bot.Send(msg) if err != nil { log.Println("Could not send Telegram message:\n", err) @@ -35,6 +39,6 @@ func (telegram TelegramNotifier) Message(message string) bool { return true } -func (telegram TelegramNotifier) Close() bool { +func (telegram *TelegramNotifier) Close() bool { return true } diff --git a/scraping.go b/scraping.go index f0e5b4e..99eb5f1 100644 --- a/scraping.go +++ b/scraping.go @@ -779,7 +779,7 @@ func notifyFilter(filters []Filter, filter *Filter, watch *Watch, web *Web, debu if debug { log.Println(buffer.String()) } else { - web.notify("telegram", buffer.String()) + web.notify("Telegram", buffer.String()) } }