Add Telegram Notification #63

Open
zottelchin wants to merge 1 commits from feature/telegram into master
  1. 2
      go.mod
  2. 35
      notifiers/telegram.go

2
go.mod

@ -7,12 +7,14 @@ require (
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4
github.com/fsnotify/fsnotify v1.4.7
github.com/gin-gonic/gin v1.5.0
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/hashicorp/hcl/v2 v2.2.0
github.com/keymon/scheduler v0.0.0-20180613200400-c8fecd8965b9
github.com/markbates/pkger v0.14.0
github.com/matcornic/hermes/v2 v2.0.2
github.com/rs/zerolog v1.18.0
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/teris-io/cli v1.0.1
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 // indirect
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect

35
notifiers/telegram.go

@ -0,0 +1,35 @@
package notifiers
import (
"codeberg.org/momar/chihuahua"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/rs/zerolog/log"
)
type TelegramNotifier struct {
Token string `hcl:"token"`
ChatID int64 `hcl:"chat"`
}
func init() {
chihuahua.Notifiers["telegram"] = &TelegramNotifier{}
}
func (c *TelegramNotifier) Notify(cfg *chihuahua.Config, check chihuahua.Check, previous chihuahua.CheckResult) {
bot, err := tgbotapi.NewBotAPI(c.Token)
if err != nil {
log.Error().Err(err).Msg("Failed to connect to Bot API")
return
}
msg := tgbotapi.NewMessage(c.ChatID, Content(cfg, check, previous))
_, err = bot.Send(msg)
if err != nil {
log.Error().Err(err).Msg("Failed to send Message to Chat")
return
}
log.Trace().Msg("Notification send")
}
Loading…
Cancel
Save