feat: add bark push notification

This commit is contained in:
Simon Ding
2024-07-29 18:06:32 +08:00
parent eed72c5eb9
commit e08c126af2
4 changed files with 153 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ package notifier
import (
"encoding/json"
"github.com/nikoksr/notify/service/bark"
"github.com/nikoksr/notify/service/dingding"
po "github.com/nikoksr/notify/service/pushover"
"github.com/nikoksr/notify/service/telegram"
@@ -68,3 +69,22 @@ func NewTelegramClient(s string) (NotificationClient, error) {
svc.AddReceivers(cfg.ChatID)
return &Notifier{service: svc}, nil
}
type BarkConfig struct {
DeviceKey string `json:"device_key"`
URL string `json:"url"`
}
func NewbarkClient(s string) (NotificationClient, error) {
var cfg BarkConfig
if err := json.Unmarshal([]byte(s), &cfg); err != nil {
return nil, errors.Wrap(err, "json")
}
url := cfg.URL
if url == "" {
url = bark.DefaultServerURL
}
b := bark.NewWithServers(cfg.DeviceKey, url)
return &Notifier{service: b}, nil
}

View File

@@ -20,7 +20,7 @@ type Notifier struct {
func (s *Notifier) SendMsg(msg string) error {
notifier := notify.New()
notifier.UseServices(s.service)
return notifier.Send(context.TODO(), "polaris", msg)
return notifier.Send(context.TODO(), "Polaris", msg)
}
var handler = utils.Map[string, HandlerFunc]{}
@@ -29,6 +29,7 @@ func init() {
handler.Store("pushover", NewPushoverClient)
handler.Store("dingtalk", NewDingTalkClient)
handler.Store("telegram", NewTelegramClient)
handler.Store("bark", NewbarkClient)
}
func Gethandler(name string) (HandlerFunc, bool) {