notify

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package notify provides notification functionality.

Index

Constants

This section is empty.

Variables

View Source
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

func (e *Email) Send(ctx context.Context, req Request) error

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) Get

func (m *MockDest) Get() []Request

Get mock

func (*MockDest) GetVerify

func (m *MockDest) GetVerify() []VerificationRequest

GetVerify mock

func (*MockDest) Send

func (m *MockDest) Send(ctx context.Context, r Request) error

Send mock

func (*MockDest) SendVerification

func (m *MockDest) SendVerification(ctx context.Context, v VerificationRequest) error

SendVerification mock

func (*MockDest) String

func (m *MockDest) String() string

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) Close

func (s *Service) Close()

Close queue channel and wait for completion

func (*Service) Submit

func (s *Service) Submit(req Request)

Submit Request to internal channel if not busy, drop if can't send

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

type Slack struct {
	*ntf.Slack
	// contains filtered or unexported fields
}

Slack implements notify.Destination for Slack

func NewSlack added in v1.8.1

func NewSlack(token, channelName string) *Slack

NewSlack makes Slack bot for notifications

func (*Slack) Send added in v1.8.1

func (s *Slack) Send(ctx context.Context, req Request) error

Send to Slack channel

func (*Slack) SendVerification added in v1.8.1

func (s *Slack) SendVerification(_ context.Context, _ VerificationRequest) error

SendVerification is not implemented for Slack

func (*Slack) String added in v1.8.1

func (s *Slack) String() string

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) Send

func (t *Telegram) Send(ctx context.Context, req Request) error

Send to telegram recipients

func (*Telegram) SendVerification

func (t *Telegram) SendVerification(_ context.Context, _ VerificationRequest) error

SendVerification is not needed for telegram

func (*Telegram) String

func (t *Telegram) String() string

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

type Webhook struct {
	*ntf.Webhook
	// contains filtered or unexported fields
}

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) Send added in v1.9.0

func (w *Webhook) Send(ctx context.Context, req Request) error

Send sends Webhook notification

func (*Webhook) SendVerification added in v1.9.0

func (w *Webhook) SendVerification(_ context.Context, _ VerificationRequest) error

SendVerification is not implemented for Webhook

func (*Webhook) String added in v1.9.0

func (w *Webhook) String() string

String describes the webhook instance

type WebhookParams added in v1.9.0

type WebhookParams struct {
	URL      string
	Template string
	Headers  []string
	Timeout  time.Duration
}

WebhookParams contain settings for webhook notifications

Jump to

Keyboard shortcuts

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