feat(external-notify): add gotify #1018

This commit is contained in:
Jacky 2025-05-07 17:06:05 +08:00
parent 7482be9c7a
commit c5274a7a64
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
21 changed files with 865 additions and 786 deletions

View file

@ -0,0 +1,33 @@
package notification
import (
"context"
"github.com/0xJacky/Nginx-UI/model"
"github.com/nikoksr/notify/service/gotify"
"github.com/uozi-tech/cosy/map2struct"
)
// @external_notifier(Gotify)
type Gotify struct {
URL string `json:"url" title:"URL"`
Token string `json:"token" title:"Token"`
Priority int `json:"priority" title:"Priority"`
}
func init() {
RegisterExternalNotifier("gotify", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
gotifyConfig := &Gotify{}
err := map2struct.WeakDecode(n.Config, gotifyConfig)
if err != nil {
return err
}
if gotifyConfig.URL == "" || gotifyConfig.Token == "" {
return ErrInvalidNotifierConfig
}
gotifyService := gotify.NewWithPriority(gotifyConfig.Token, gotifyConfig.URL, gotifyConfig.Priority)
return gotifyService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
})
}