mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat: add Lark and Lark Custom notification support
This commit is contained in:
parent
e364353cd1
commit
7a0972495f
17 changed files with 174 additions and 38 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify"
|
||||
"github.com/nikoksr/notify/service/bark"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
@ -26,8 +25,6 @@ func init() {
|
|||
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))
|
||||
return barkService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify"
|
||||
"github.com/nikoksr/notify/service/dingding"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
@ -31,9 +30,6 @@ func init() {
|
|||
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))
|
||||
return dingTalkService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
||||
|
|
30
internal/notification/lark.go
Normal file
30
internal/notification/lark.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify/service/lark"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
||||
// @external_notifier(Lark)
|
||||
type Lark struct {
|
||||
WebhookURL string `json:"webhook_url" title:"Webhook URL"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterExternalNotifier("lark", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
|
||||
larkConfig := &Lark{}
|
||||
err := map2struct.WeakDecode(n.Config, larkConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if larkConfig.WebhookURL == "" {
|
||||
return ErrInvalidNotifierConfig
|
||||
}
|
||||
|
||||
larkService := lark.NewWebhookService(larkConfig.WebhookURL)
|
||||
return larkService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
43
internal/notification/lark_custom.go
Normal file
43
internal/notification/lark_custom.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify/service/lark"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
||||
// @external_notifier(Lark Custom)
|
||||
type LarkCustom struct {
|
||||
AppID string `json:"app_id" title:"App ID"`
|
||||
AppSecret string `json:"app_secret" title:"App Secret"`
|
||||
OpenID string `json:"open_id" title:"Open ID"`
|
||||
UserID string `json:"user_id" title:"User ID"`
|
||||
UnionID string `json:"union_id" title:"Union ID"`
|
||||
Email string `json:"email" title:"Email"`
|
||||
ChatID string `json:"chat_id" title:"Chat ID"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterExternalNotifier("lark_custom", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
|
||||
larkCustomConfig := &LarkCustom{}
|
||||
err := map2struct.WeakDecode(n.Config, larkCustomConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if larkCustomConfig.AppID == "" || larkCustomConfig.AppSecret == "" {
|
||||
return ErrInvalidNotifierConfig
|
||||
}
|
||||
|
||||
larkCustomAppService := lark.NewCustomAppService(larkCustomConfig.AppID, larkCustomConfig.AppSecret)
|
||||
larkCustomAppService.AddReceivers(
|
||||
lark.OpenID(larkCustomConfig.OpenID),
|
||||
lark.UserID(larkCustomConfig.UserID),
|
||||
lark.UnionID(larkCustomConfig.UnionID),
|
||||
lark.Email(larkCustomConfig.Email),
|
||||
lark.ChatID(larkCustomConfig.ChatID),
|
||||
)
|
||||
return larkCustomAppService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/nikoksr/notify"
|
||||
"github.com/nikoksr/notify/service/telegram"
|
||||
"github.com/uozi-tech/cosy/map2struct"
|
||||
)
|
||||
|
@ -46,9 +45,7 @@ func init() {
|
|||
}
|
||||
|
||||
telegramService.AddReceivers(chatIDInt)
|
||||
|
||||
externalNotify := notify.New()
|
||||
externalNotify.UseServices(telegramService)
|
||||
return externalNotify.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
|
||||
return telegramService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue