notify

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 2 Imported by: 42

README

notify logo

GitHub tag (latest SemVer) Go Report Card Codacy Badge Maintainability FOSSA Status go.dev reference

A dead simple Go library for sending notifications to various messaging services.

About

Notify arose from my own need for one of my api server running in production to be able to notify me when, for example, an error occurred. The library is kept as simple as possible to allow a quick integration and easy usage.

Disclaimer

Any misuse of this library is your own liability and responsibility and cannot be attributed to the authors of this library. See license for more.

Spamming through the use of this library may get you permanently banned on most supported platforms.

Install

go get -u github.com/nikoksr/notify

Example usage

// The notifier we're gonna send our messages to
notifier := notify.New()

// Create a telegram service. Ignoring error for demo simplicity
telegramService, _ := telegram.New("your_telegram_api_token")

// Passing a telegram chat id as receiver for our messages.
// Basically where should our message be sent to?
telegramService.AddReceivers("-1234567890")

// Tell our notifier to use the telegram service. You can repeat the above process
// for as many services as you like and just tell the notifier to use them.
// Its kinda like using middlewares for api servers.
notifier.UseService(telegramService)

// Send a test message
_ = notifier.Send(
	"Message Subject/Title",
	"The actual message. Hello, you awesome gophers! :)",
)

Supported services

  • Discord
  • Email
  • Microsoft Teams
  • Slack
  • Telegram
  • Pushbullet

Roadmap

  • Add tests (see #1)
  • Add more notification services

Credits

Author

Niko Köser

Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

License

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSendNotification = errors.New("send notification")

ErrSendNotification signals that the notifier failed to send a notification.

Functions

This section is empty.

Types

type Notifier

type Notifier interface {
	Send(string, string) error
	AddReceivers(...string)
}

Notifier defines the behavior for notification services. It implements Send and AddReciever

The Send command simply sends a message string to the internal destination Notifier.

E.g for telegram it sends the message to the specified group chat.

The AddReceivers takes one or many strings and adds these to the list of destinations for recieving messages e.g. slack channels, telegram chats, email addresses.

type Notify

type Notify struct {
	Disabled bool
	// contains filtered or unexported fields
}

Notify is the central struct for managing notification services and sending messages to them.

func New

func New() *Notify

New returns a new instance of Notify. Defaulting to being not disabled

func (Notify) Send

func (n Notify) Send(subject, message string) error

Send calls the underlying notification services to send the given message to their respective endpoints.

func (*Notify) UseService

func (n *Notify) UseService(service Notifier)

UseService adds a given service to the notifiers services list.

Directories

Path Synopsis
service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL