ntfy

package module
v2.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConfig = errors.New("no notify config")

Functions

func Notify

func Notify(ctx context.Context, text string) (err error)

func R

func R() *resty.Request

Types

type Config

type Config struct {
	Timeout time.Duration `json:"ntfy.timeout" yaml:"ntfy.timeout"`
	Proxy   string        `json:"ntfy.proxy"   yaml:"ntfy.proxy"`
	Retry   int           `json:"ntfy.retry"   yaml:"ntfy.retry"`

	DingtalkConfig   `yaml:",squash"`
	TelegramConfig   `yaml:",squash"`
	WeixinWorkConfig `yaml:",squash"`

	WebhookConfig `yaml:",squash"`
}

func C

func C() Config

type DingtalkConfig

type DingtalkConfig struct {
	Token  *string `json:"ntfy.dingtalk.token"  yaml:"ntfy.dingtalk.token"`
	Secret string  `json:"ntfy.dingtalk.secret" yaml:"ntfy.dingtalk.secret"`
}

func (DingtalkConfig) Name

func (DingtalkConfig) Name() string

func (DingtalkConfig) Notify

func (c DingtalkConfig) Notify(_ context.Context, text string) error

func (DingtalkConfig) Sign

func (c DingtalkConfig) Sign() (string, string)

type Interface

type Interface interface {
	Name() string
	Notify(ctx context.Context, text string) error
}

type TelegramConfig

type TelegramConfig struct {
	Token  *string `json:"ntfy.telegram.token"   yaml:"ntfy.telegram.token"`
	ChatId string  `json:"ntfy.telegram.chat_id" yaml:"ntfy.telegram.chat_id"`
}

func (TelegramConfig) Name

func (TelegramConfig) Name() string

func (TelegramConfig) Notify

func (c TelegramConfig) Notify(_ context.Context, text string) error

type WebhookConfig

type WebhookConfig struct {
	URL *string `json:"ntfy.webhook.url" yaml:"ntfy.webhook.url"`
	// optional: GET or POST, default is GET
	Method string `json:"ntfy.webhook.method" yaml:"ntfy.webhook.method"`
	// only available when method is POST
	// optional: JSON or FORM, default is FORM
	//  - FORM is request by `application/x-www-form-urlencoded`
	//  - JSON is request by `application/json`
	Type string `json:"ntfy.webhook.type" yaml:"ntfy.webhook.type"`
	// the key of text in request body or query string
	// default is text
	Key string `json:"ntfy.webhook.key" yaml:"ntfy.webhook.key"`
	// extra values
	Extra map[string]string `json:"ntfy.webhook.extra" yaml:"ntfy.webhook.extra"`
	// headers
	Headers map[string]string `json:"ntfy.webhook.headers" yaml:"ntfy.webhook.headers"`
}

WebhookConfig is the config for webhook.

ServerChan [docs](https://sct.ftqq.com/sendkey)

ntfy:
  webhook:
    url: https://sctapi.ftqq.com/{key}.send
    method: POST
    type: JSON
    key: desp
    extras:
      title: ntfy

ntfy.sh [docs](https://docs.ntfy.sh/publish/#publish-as-json)

ntfy:
 webhook:
   url: https://ntfy.com/
   method: POST
   type: JSON
   key: message
   extra:
     title: ntfy
     topic: default
   headers:
     Authorization: Basic base64(username:password)

func (WebhookConfig) Name

func (c WebhookConfig) Name() string

func (WebhookConfig) Notify

func (c WebhookConfig) Notify(_ context.Context, text string) error

type WeixinWorkConfig added in v2.0.1

type WeixinWorkConfig struct {
	Key *string `json:"ntfy.weixin_work.key" yaml:"ntfy.weixin_work.key"`
}

func (WeixinWorkConfig) Name added in v2.0.1

func (WeixinWorkConfig) Name() string

func (WeixinWorkConfig) Notify added in v2.0.1

func (c WeixinWorkConfig) Notify(_ context.Context, text string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL