mirror of
https://github.com/nikoksr/notify.git
synced 2024-11-24 08:22:18 +02:00
Merge branch 'main' into feature/sendgrid
This commit is contained in:
commit
39fcea62f6
11
notifier.go
11
notifier.go
@ -1,14 +1,9 @@
|
||||
package notify
|
||||
|
||||
// Notifier defines the behavior for notification services. It implements Send and AddReciever
|
||||
// Notifier defines the behavior for notification services.
|
||||
//
|
||||
// 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 receiving messages
|
||||
// e.g. slack channels, telegram chats, email addresses.
|
||||
// The Send function simply sends a subject and a message string to the internal destination Notifier.
|
||||
// E.g for telegram.Telegram it sends the message to the specified group chat.
|
||||
type Notifier interface {
|
||||
Send(string, string) error
|
||||
AddReceivers(...string)
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ type Notify struct {
|
||||
// ErrSendNotification signals that the notifier failed to send a notification.
|
||||
var ErrSendNotification = errors.New("send notification")
|
||||
|
||||
// New returns a new instance of Notify. Defaulting to being not disabled
|
||||
// New returns a new instance of Notify. Defaulting to being not disabled.
|
||||
func New() *Notify {
|
||||
notifier := &Notify{
|
||||
Disabled: defaultDisabled,
|
||||
|
2
send.go
2
send.go
@ -5,7 +5,7 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// Send calls the underlying notification services to send the given message to their respective endpoints.
|
||||
// Send calls the underlying notification services to send the given subject and message to their respective endpoints.
|
||||
func (n Notify) Send(subject, message string) error {
|
||||
if n.Disabled {
|
||||
return nil
|
||||
|
@ -1,8 +1,6 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -34,13 +32,8 @@ func New(apiToken string) (*Telegram, error) {
|
||||
|
||||
// AddReceivers takes Telegram chat IDs and adds them to the internal chat ID list. The Send method will send
|
||||
// a given message to all those chats.
|
||||
func (t *Telegram) AddReceivers(chatIDs ...string) {
|
||||
for _, v := range chatIDs {
|
||||
chatID, err := strconv.ParseInt(v, 10, 64)
|
||||
if err == nil {
|
||||
t.chatIDs = append(t.chatIDs, chatID)
|
||||
}
|
||||
}
|
||||
func (t *Telegram) AddReceivers(chatIDs ...int64) {
|
||||
t.chatIDs = append(t.chatIDs, chatIDs...)
|
||||
}
|
||||
|
||||
// Send takes a message subject and a message body and sends them to all previously set chats. Message body supports
|
||||
|
9
use.go
9
use.go
@ -1,14 +1,13 @@
|
||||
package notify
|
||||
|
||||
// useService adds a given service to the notifiers services list.
|
||||
// useService adds a given service to the Notifier's services list.
|
||||
func (n *Notify) useService(service Notifier) {
|
||||
if service == nil {
|
||||
return
|
||||
}
|
||||
if service != nil {
|
||||
n.notifiers = append(n.notifiers, service)
|
||||
}
|
||||
}
|
||||
|
||||
// UseServices adds the given service(s) to the notifiers services list.
|
||||
// UseServices adds the given service(s) to the Notifier's services list.
|
||||
func (n *Notify) UseServices(service ...Notifier) {
|
||||
for _, s := range service {
|
||||
n.useService(s)
|
||||
|
Loading…
Reference in New Issue
Block a user