Skip to content

sharpvik/alertg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alertg

Go library to issue alerts through Telegram Messenger.

Why

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.

Get

go get github.com/sharpvik/alertg

Setup

Create the bot

We assume that you have created a Telegram bot. You will need its token to initialise telebot (see next section).

Find chat ID

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.

Use

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.

Interface

We support the following alert levels (inspired by log/slog).

altg.Debug("message")
altg.Info("message")
altg.Warn("message")
altg.Error("message")

About

Alert library for Telegram

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages