https://github.com/obalunenko/notifier
Notifier package allows to send notifications to different sources (telegram, slack, logs)
https://github.com/obalunenko/notifier
Last synced: 6 months ago
JSON representation
Notifier package allows to send notifications to different sources (telegram, slack, logs)
- Host: GitHub
- URL: https://github.com/obalunenko/notifier
- Owner: obalunenko
- License: mit
- Created: 2023-05-04T18:30:46.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-11-12T09:57:24.000Z (8 months ago)
- Last Synced: 2025-11-12T11:31:35.769Z (8 months ago)
- Language: Go
- Size: 438 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README

[](https://godoc.org/github.com/obalunenko/notifier)
[](https://github.com/obalunenko/notifier/releases/latest)
[](https://goreportcard.com/report/github.com/obalunenko/notifier)
[![Go [lint, test]](https://github.com/obalunenko/notifier/actions/workflows/go.yml/badge.svg)](https://github.com/obalunenko/notifier/actions/workflows/go.yml)
[](https://github.com/obalunenko/notifier/actions/workflows/codeql-analysis.yml)

# notifier
Package notifier provides functionality to send notifications.
## Examples
### Notifier
ExampleNotifier shows how to create a new notifier with a list of notifiers and send a message.
```golang
package main
import (
"bytes"
"context"
"fmt"
"os"
"time"
"github.com/obalunenko/notifier"
)
const (
// Test telegram credentials.
testTGTokenEnv = "TEST_TELEGRAM_TOKEN"
testTGChatIDEnv = "TEST_TELEGRAM_CHAT_ID"
)
// ExampleNotifier shows how to create a new notifier with a list of notifiers and send a message.
func main() {
ctx := context.Background()
var buf bytes.Buffer
// Declare list of notifiers.
var notifiers []notifier.Notifier
// Create a new io.Writer notifier to visualize alerts.
wn, err := notifier.NewIOWriterNotifier(&buf)
if err != nil {
// Handle error in your way.
panic(err)
}
notifiers = append(notifiers, wn)
// Create a new telegram notifier if token and chatID env set.
if token, chatID := os.Getenv(testTGTokenEnv), os.Getenv(testTGChatIDEnv); token != "" && chatID != "" {
tgn, err := notifier.NewTelegram(token, chatID)
if err != nil {
// Handle error in your way.
panic(err)
}
notifiers = append(notifiers, tgn)
}
// Add the notifier to the list of notifiers.
n, err := notifier.NewMultiNotifier(notifiers...)
if err != nil {
// Handle error in your way.
panic(err)
}
// Add notifier metadata to context.
ctx = notifier.ContextWithMetadata(ctx, notifier.Metadata{
AppName: "test_app",
InstanceName: "test_instance",
Commit: "test_commit",
BuildDate: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC).Format(time.DateTime),
})
// Send alert.
err = n.Alert(ctx, notifier.SeverityWarning, "[NOTIFIER_TEST]: example message")
if err != nil {
// Handle error in your way.
panic(err)
}
fmt.Println(buf.String())
}
```