mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat: external notification
This commit is contained in:
parent
241fa4adfe
commit
04de1360c2
42 changed files with 3292 additions and 1393 deletions
39
internal/notification/dingding.go
Normal file
39
internal/notification/dingding.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify"
|
||||
"github.com/nikoksr/notify/service/dingding"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
||||
// @external_notifier(DingTalk)
|
||||
type DingTalk struct {
|
||||
AccessToken string `json:"access_token" title:"Access Token"`
|
||||
Secret string `json:"secret" title:"Secret (Optional)"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterExternalNotifier("dingding", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
|
||||
dingTalkConfig := &DingTalk{}
|
||||
err := map2struct.WeakDecode(n.Config, dingTalkConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dingTalkConfig.AccessToken == "" {
|
||||
return ErrInvalidNotifierConfig
|
||||
}
|
||||
|
||||
// Initialize DingTalk service
|
||||
dingTalkService := dingding.New(&dingding.Config{
|
||||
Token: dingTalkConfig.AccessToken,
|
||||
Secret: dingTalkConfig.Secret,
|
||||
})
|
||||
// Use the service
|
||||
externalNotify := notify.New()
|
||||
externalNotify.UseServices(dingTalkService)
|
||||
return externalNotify.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue