notify

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 20 Imported by: 20

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(ctx context.Context, req Request) error
}

Destination defines interface for a given destination service, like telegram, email and so on

type Email added in v1.5.0

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

Email implements notify.Destination for email

func NewEmail added in v1.5.0

func NewEmail(emailParams EmailParams, smtpParams SMTPParams) (*Email, error)

NewEmail makes new Email object, returns error in case of e.MsgTemplate or e.VerificationTemplate parsing error

func (*Email) Send added in v1.5.0

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

Send email about comment reply to Request.Email if it's set, also sends email to site administrator if appropriate option is set. Thread safe

func (*Email) String added in v1.5.0

func (e *Email) String() string

String representation of Email object

type EmailParams added in v1.5.0

type EmailParams struct {
	From                 string // from email address
	MsgTemplate          string // request message template
	VerificationSubject  string // verification message subject
	VerificationTemplate string // verification message 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 added in v1.5.0

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

MockDest is a destination mock

func (*MockDest) Get added in v1.5.0

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

Get mock

func (*MockDest) Send added in v1.5.0

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

Send mock

func (*MockDest) String added in v1.5.0

func (m *MockDest) String() string

type Request added in v1.5.0

type Request struct {
	Comment store.Comment // if set sent notifications about new comment

	Email    string // if set (also) send email
	ForAdmin bool   // if set, message supposed to be sent to administrator

	Verification VerificationMetadata // if set sent verification notification
	// contains filtered or unexported fields
}

Request notification either about comment or about particular user verification

type SMTPParams added in v1.6.0

type SMTPParams struct {
	Host     string        // SMTP host
	Port     int           // SMTP port
	TLS      bool          // TLS auth
	Username string        // user name
	Password string        // password
	TimeOut  time.Duration // TCP connection timeout
}

SMTPParams contain settings for smtp server connection

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

type Store

type Store interface {
	Get(locator store.Locator, id string, user store.User) (store.Comment, error)
	GetUserEmail(siteID string, userID string) (string, error)
}

Store defines the minimal interface accessing stored comments used by notifier

type Telegram

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

Telegram implements notify.Destination for telegram

func NewTelegram

func NewTelegram(token string, channelID string, timeout time.Duration, api string) (*Telegram, error)

NewTelegram makes telegram bot for notifications

func (*Telegram) Send

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

Send to telegram channel

func (*Telegram) String

func (t *Telegram) String() string

type VerificationMetadata added in v1.5.0

type VerificationMetadata struct {
	SiteID string
	User   string
	Token  string
}

VerificationMetadata required to send notify method verification message

Jump to

Keyboard shortcuts

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