feat: add Lark and Lark Custom notification support

This commit is contained in:
Jacky 2025-04-09 13:13:41 +00:00
parent e364353cd1
commit 7a0972495f
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
17 changed files with 174 additions and 38 deletions

View file

@ -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))
})
}

View file

@ -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))
})
}

View 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))
})
}

View 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))
})
}

View file

@ -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))
})
}