Go library to issue alerts through Telegram Messenger.
In my personal projects, I found it convenient to receive system alerts through Telegram. I don't have to check monitoring dashboards. Instead, updates are delivered to me directly.
go get github.com/sharpvik/alertg
We assume that you have created a Telegram bot.
You will need its token to initialise telebot
(see next section).
To find your chat ID, send any message to your bot, then open this link in your browser:
https://api.telegram.org/bot<TOKEN>/getUpdates
^^^^^^^
REPLACE THIS WITH YOUR SPECIFIC TELEGRAM BOT TOKEN
The chat ID can be found in the resulting JSON.
We support broadcasting alerts to multiple chats. If you want to do that, you should use the aforementioned method to get chat ID of every person wanting to receive system alerts.
token := "YOUR TELEGRAM BOT TOKEN"
chatID := telebot.ChatID(int64(42)) // YOUR CHAT ID
sender, _ := telebot.NewBot(telebot.Settings{Token: token})
altg := alertg.Use(sender).Notify(chatID) // ONE OR MORE CHAT ID
altg.Info("all systems operational")
Example above omits error handling for brevity but you shouldn't.
We support the following alert levels (inspired by log/slog).
altg.Debug("message")
altg.Info("message")
altg.Warn("message")
altg.Error("message")