lark.go 746 B

123456789101112131415161718192021222324252627282930
  1. package notification
  2. import (
  3. "context"
  4. "github.com/0xJacky/Nginx-UI/model"
  5. "github.com/nikoksr/notify/service/lark"
  6. "github.com/uozi-tech/cosy/map2struct"
  7. )
  8. // @external_notifier(Lark)
  9. type Lark struct {
  10. WebhookURL string `json:"webhook_url" title:"Webhook URL"`
  11. }
  12. func init() {
  13. RegisterExternalNotifier("lark", func(ctx context.Context, n *model.ExternalNotify, msg *ExternalMessage) error {
  14. larkConfig := &Lark{}
  15. err := map2struct.WeakDecode(n.Config, larkConfig)
  16. if err != nil {
  17. return err
  18. }
  19. if larkConfig.WebhookURL == "" {
  20. return ErrInvalidNotifierConfig
  21. }
  22. larkService := lark.NewWebhookService(larkConfig.WebhookURL)
  23. return larkService.Send(ctx, msg.GetTitle(n.Language), msg.GetContent(n.Language))
  24. })
  25. }