notification

package
v0.0.0-...-e16fa07 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NOTIFICATION_EMAIL    = "email"
	NOTIFICATION_PUSHOVER = "pushover"
	NOTIFICATION_TELEGRAM = "telegram"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

type Email struct {
	// contains filtered or unexported fields
}

func NewEmail

func NewEmail(config EmailConfig) (*Email, error)

func (*Email) SendNotification

func (e *Email) SendNotification(notification *Notification) error

type EmailConfig

type EmailConfig struct {
	// SMTP config of our mailbox for outgoing mail
	SmtpHost        string
	SmtpPort        int
	AllowSelfSigned bool
	FromAddress     string
	FromPassword    string

	RecAddress string // receiver. can be comma-separated list
}

func (*EmailConfig) Address

func (c *EmailConfig) Address() string

Address URI to smtp server.

type Mailer

type Mailer struct {
	// contains filtered or unexported fields
}

func NewMailer

func NewMailer(allowSelfSignedTlsCert bool) *Mailer

func (*Mailer) EncodeRFC2047

func (m *Mailer) EncodeRFC2047(str string) string

Use the mail package RFC 2047 to encode any string

func (*Mailer) SendMail

func (m *Mailer) SendMail(addr string, auth smtp.Auth, from string, to []string, msg []byte) error

Drop-in replacement for official net/smtp.SendMail() with: - a connect-timeout of 10 seconds - using implicit TLS instead of upgrading via STARTTLS

type Notification

type Notification struct {
	Title               string
	Text                string
	RequireConfirmation bool
}

func NewNotification

func NewNotification(title string, text string) *Notification

func (*Notification) GetMessengerText

func (n *Notification) GetMessengerText() string

Return the messenger text message containing title + message text to be used for Telegram, etc...

type NotificationMethod

type NotificationMethod string

type NotificationReceiver

type NotificationReceiver struct {
	Method NotificationMethod `mapstructure:"Method"`

	// Email
	SmtpHost        string `mapstructure:"SmtpHost"`
	SmtpPort        int    `mapstructure:"SmtpPort"`
	AllowSelfSigned bool   `mapstructure:"AllowSelfSigned"`
	FromAddress     string `mapstructure:"FromAddress"`
	FromPassword    string `mapstructure:"FromPassword"`
	RecAddress      string `mapstructure:"RecAddress"`

	// Pushover
	AppToken string `mapstructure:"AppToken"`
	Receiver string `mapstructure:"Receiver"`

	// Telegram
	Token   string `mapstructure:"Token"`
	Channel string `mapstructure:"Channel"`
}

type Notifier

type Notifier interface {
	SendNotification(notification *Notification) error
}

func CreateAndSendNotification

func CreateAndSendNotification(sendData *Notification, notify *NotificationReceiver) (Notifier, error)

type Pushover

type Pushover struct {
	// contains filtered or unexported fields
}

func NewPushover

func NewPushover(config PushoverConfig) (*Pushover, error)

func (*Pushover) SendNotification

func (p *Pushover) SendNotification(notification *Notification) error

type PushoverConfig

type PushoverConfig struct {
	AppToken string
	Receiver string
}

type PusoverResponse

type PusoverResponse struct {
	Status    int    `json:"status"`
	RequestId string `json:"request"` // UUID
}

type Telegram

type Telegram struct {
	// contains filtered or unexported fields
}

func NewTelegram

func NewTelegram(config TelegramConfig) (*Telegram, error)

func (*Telegram) SendNotification

func (t *Telegram) SendNotification(notification *Notification) error

type TelegramConfig

type TelegramConfig struct {
	Token   string // received by talking to @BotFather
	Channel string // channel ID or user ID
}

type TelegramResponse

type TelegramResponse struct {
	Ok          bool   `json:"ok"`
	ErrorCode   int    `json:"error_code"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

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