mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-07 18:48:00 +08:00
feat: add bark push notification
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user