Documentation ¶
Overview ¶
Package notify provides notification functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NopService = &Service{}
NopService is do-nothing notifier, without destinations
Functions ¶
This section is empty.
Types ¶
type Destination ¶
type Destination interface { fmt.Stringer Send(context.Context, Request) error SendVerification(context.Context, VerificationRequest) error }
Destination defines interface for a given destination service, like telegram, email and so on
type Email ¶
type Email struct { *ntf.Email EmailParams // contains filtered or unexported fields }
Email implements notify.Destination for email
func NewEmail ¶
func NewEmail(emailParams EmailParams, smtpParams ntf.SMTPParams) (*Email, error)
NewEmail makes new Email object, returns error in case of e.MsgTemplate or e.VerificationTemplate parsing error
func (*Email) Send ¶
Send email about comment reply to Request.Emails and Email.AdminEmails if they're set. Thread safe
func (*Email) SendVerification ¶
func (e *Email) SendVerification(ctx context.Context, req VerificationRequest) error
SendVerification email verification VerificationRequest.Email if it's set. Thread safe
type EmailParams ¶
type EmailParams struct { From string // from email address AdminEmails []string // administrator emails to send copy of comment notification to MsgTemplatePath string // path to request message template VerificationSubject string // verification message sub VerificationTemplatePath string // path to verification template SubscribeURL string // full subscribe handler URL UnsubscribeURL string // full unsubscribe handler URL TokenGenFn func(userID, email, site string) (string, error) // Unsubscribe token generation function }
EmailParams contain settings for email notifications
type MockDest ¶
type MockDest struct {
// contains filtered or unexported fields
}
MockDest is a destination mock
func (*MockDest) SendVerification ¶
func (m *MockDest) SendVerification(ctx context.Context, v VerificationRequest) error
SendVerification mock
type Request ¶
type Request struct { Comment store.Comment Emails []string Telegrams []string // contains filtered or unexported fields }
Request notification for a Comment
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service delivers notifications to multiple destinations
func NewService ¶
func NewService(dataService Store, size int, destinations ...Destination) *Service
NewService makes notification service routing comments to all destinations.
func (*Service) SubmitVerification ¶
func (s *Service) SubmitVerification(req VerificationRequest)
SubmitVerification to internal channel if not busy, drop if can't send
type Slack ¶ added in v1.8.1
Slack implements notify.Destination for Slack
func (*Slack) SendVerification ¶ added in v1.8.1
func (s *Slack) SendVerification(_ context.Context, _ VerificationRequest) error
SendVerification is not implemented for Slack
type Store ¶
type Store interface { Get(locator store.Locator, id string, user store.User) (store.Comment, error) GetUserEmail(siteID, userID string) (string, error) GetUserTelegram(siteID, userID string) (string, error) }
Store defines the minimal interface accessing stored comments used by notifier
type Telegram ¶
type Telegram struct { *ntf.Telegram AdminChannelID string // unique identifier for the target chat or username of the target channel (in the format @channelusername) UserNotifications bool // flag which enables user notifications }
Telegram implements notify.Destination for telegram
func NewTelegram ¶
func NewTelegram(params TelegramParams) (*Telegram, error)
NewTelegram makes telegram bot for notifications
func (*Telegram) SendVerification ¶
func (t *Telegram) SendVerification(_ context.Context, _ VerificationRequest) error
SendVerification is not needed for telegram
type TelegramParams ¶ added in v1.9.0
type TelegramParams struct { AdminChannelID string // unique identifier for the target chat or username of the target channel (in the format @channelusername) Token string // token for telegram bot API interactions Timeout time.Duration // http client timeout UserNotifications bool // flag which enables user notifications ErrorMsg, SuccessMsg string // messages for successful and unsuccessful subscription requests to bot }
TelegramParams contain settings for telegram notifications
type VerificationRequest ¶
type VerificationRequest struct { SiteID string User string Email string // if set, send email only Token string }
VerificationRequest notification for user
type Webhook ¶ added in v1.9.0
Webhook implements notify.Destination for Webhook notifications
func NewWebhook ¶ added in v1.9.0
func NewWebhook(params WebhookParams) (*Webhook, error)
NewWebhook makes Webhook
func (*Webhook) SendVerification ¶ added in v1.9.0
func (w *Webhook) SendVerification(_ context.Context, _ VerificationRequest) error
SendVerification is not implemented for Webhook