Documentation
¶
Overview ¶
Package notify provides notification functionality.
Index ¶
- func EscapeTelegramText(text string) string
- func Send(ctx context.Context, notifiers []Notifier, destination, text string) error
- func TelegramSupportedHTML(htmlText string) string
- type Email
- type Notifier
- type SMTPParams
- type Slack
- type Telegram
- func (t *Telegram) AddToken(token, user, site string, expires time.Time)
- func (t *Telegram) CheckToken(token, user string) (telegram, site string, err error)
- func (t *Telegram) GetBotUsername() string
- func (t *Telegram) ProcessUpdate(ctx context.Context, textUpdate string) error
- func (t *Telegram) Request(ctx context.Context, method string, b []byte, data any) error
- func (t *Telegram) Run(ctx context.Context)
- func (t *Telegram) Schema() string
- func (t *Telegram) Send(ctx context.Context, destination, text string) error
- func (t *Telegram) String() string
- type TelegramBotInfo
- type TelegramParams
- type TelegramUpdate
- type Webhook
- type WebhookParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeTelegramText ¶
EscapeTelegramText returns text sanitized of symbols not allowed inside other HTML tags in Telegram HTML message payload
func Send ¶
Send sends message to provided destination, picking the right one based on destination schema
func TelegramSupportedHTML ¶
TelegramSupportedHTML returns HTML with only tags allowed in Telegram HTML message payload, also trims ending newlines
https://core.telegram.org/bots/api#html-style, https://core.telegram.org/api/entities#allowed-entities
Types ¶
type Email ¶
type Email struct {
SMTPParams
// contains filtered or unexported fields
}
Email notifications client
func (*Email) Send ¶
Send sends the message over Email, with "from", "subject" and "unsubscribeLink" parsed from destination field with "mailto:" schema. "unsubscribeLink" passed as a header, https://support.google.com/mail/answer/81126 -> "Use one-click unsubscribe"
Example:
- mailto:"John Wayne"<john@example.org>?subject=test-subj&from="Notifier"<notify@example.org> - mailto:addr1@example.org,addr2@example.org?subject=test-subj&from=notify@example.org&unsubscribeLink=http://example.org/unsubscribe
type Notifier ¶
type Notifier interface {
fmt.Stringer
Schema() string // returns schema prefix supported by this client
Send(ctx context.Context, destination, text string) error // sends message to provided destination
}
Notifier defines common interface among all notifiers
type SMTPParams ¶
type SMTPParams struct {
Host string // SMTP host
Port int // SMTP port
TLS bool // TLS auth
StartTLS bool // StartTLS auth
InsecureSkipVerify bool // skip certificate verification
ContentType string // Content type
Charset string // Character set
LoginAuth bool // LOGIN auth method instead of default PLAIN, needed for Office 365 and outlook.com
Username string // username
Password string // password
TimeOut time.Duration // TCP connection timeout
}
SMTPParams contain settings for smtp server connection
type Slack ¶
type Slack struct {
// contains filtered or unexported fields
}
Slack notifications client
func (*Slack) Send ¶
Send sends the message over Slack, with "title", "titleLink" and "attachmentText" parsed from destination field with "slack:" schema same way "mailto:" schema is constructed.
Example:
- slack:channelName - slack:channelID - slack:userID - slack:channel?title=title&attachmentText=test%20text&titleLink=https://example.org
type Telegram ¶
type Telegram struct {
TelegramParams
// contains filtered or unexported fields
}
Telegram notifications client
func NewTelegram ¶
func NewTelegram(params TelegramParams) (*Telegram, error)
NewTelegram makes telegram bot for notifications
func (*Telegram) CheckToken ¶
CheckToken verifies incoming token, returns the user address if it's confirmed and empty string otherwise
func (*Telegram) GetBotUsername ¶
GetBotUsername returns bot username
func (*Telegram) ProcessUpdate ¶
ProcessUpdate is alternative to Run, it processes provided plain text update from Telegram so that caller could get updates and send it not only there but to multiple sources
func (*Telegram) Run ¶
Run starts processing login requests sent in Telegram, required for user notifications to work Blocks caller
func (*Telegram) Send ¶
Send sends provided message to Telegram chat, with `parseMode` parsed from destination field (Markdown by default) with "telegram:" schema same way "mailto:" schema is constructed.
Example:
- telegram:channel - telegram:chatID // chatID is a number, like `-1001480738202` - telegram:channel?parseMode=HTML
type TelegramBotInfo ¶
type TelegramBotInfo struct {
Username string `json:"username"`
}
TelegramBotInfo structure contains information about telegram bot, which is used from whole telegram API response
type TelegramParams ¶
type TelegramParams struct {
Token string // token for telegram bot API interactions
Timeout time.Duration // http client timeout
ErrorMsg, SuccessMsg string // messages for successful and unsuccessful subscription requests to bot
// contains filtered or unexported fields
}
TelegramParams contain settings for telegram notifications
type TelegramUpdate ¶
type TelegramUpdate struct {
Result []struct {
UpdateID int `json:"update_id"`
Message struct {
Chat struct {
ID int `json:"id"`
Name string `json:"first_name"`
Type string `json:"type"`
} `json:"chat"`
Text string `json:"text"`
} `json:"message"`
} `json:"result"`
}
TelegramUpdate contains update information, which is used from whole telegram API response
type Webhook ¶
type Webhook struct {
WebhookParams
// contains filtered or unexported fields
}
Webhook notifications client
type WebhookParams ¶
type WebhookParams struct {
Timeout time.Duration
Headers []string // headers in format "header:value"
}
WebhookParams contain settings for webhook notifications