mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
feat: external notification
This commit is contained in:
parent
241fa4adfe
commit
04de1360c2
42 changed files with 3292 additions and 1393 deletions
33
internal/notification/bark.go
Normal file
33
internal/notification/bark.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify"
|
||||
"github.com/nikoksr/notify/service/bark"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
||||
// @external_notifier(Bark)
|
||||
type Bark struct {
|
||||
DeviceKey string `json:"device_key" title:"Device Key"`
|
||||
ServerURL string `json:"server_url" title:"Server URL"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterExternalNotifier("bark", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
|
||||
barkConfig := &Bark{}
|
||||
err := map2struct.WeakDecode(n.Config, barkConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if barkConfig.DeviceKey == "" && barkConfig.ServerURL == "" {
|
||||
return ErrInvalidNotifierConfig
|
||||
}
|
||||
barkService := bark.NewWithServers(barkConfig.DeviceKey, barkConfig.ServerURL)
|
||||
externalNotify := notify.New()
|
||||
externalNotify.UseServices(barkService)
|
||||
return externalNotify.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue