bark.go 846 B

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