mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat(external-notify): add gotify #1018
This commit is contained in:
parent
7482be9c7a
commit
c5274a7a64
21 changed files with 865 additions and 786 deletions
33
internal/notification/gotify.go
Normal file
33
internal/notification/gotify.go
Normal 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))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue