https://github.com/sharpvik/alertg
Alert library for Telegram
https://github.com/sharpvik/alertg
Last synced: 3 months ago
JSON representation
Alert library for Telegram
- Host: GitHub
- URL: https://github.com/sharpvik/alertg
- Owner: sharpvik
- License: apache-2.0
- Created: 2025-03-23T12:50:10.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-23T13:53:52.000Z (10 months ago)
- Last Synced: 2025-03-23T14:29:19.954Z (10 months ago)
- Language: Go
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alertg
Go library to issue alerts through [Telegram Messenger](https://telegram.org/).
## 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
```sh
go get github.com/sharpvik/alertg
```
## Setup
### Create the bot
We assume that [you have created a Telegram bot](https://core.telegram.org/bots/tutorial).
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:
```text
https://api.telegram.org/bot/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
```go
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](https://pkg.go.dev/log/slog)).
```go
altg.Debug("message")
altg.Info("message")
altg.Warn("message")
altg.Error("message")
```