notify

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRecipient = errors.New("no recipient")

Errors.

Functions

func Send added in v0.0.4

func Send(publicKey, privateKey, sender string, recipients []string, subject, msg string) error

Send sends an email message using the Mailjet API.

Types

type HTMLEmailer added in v0.0.4

type HTMLEmailer interface {
	// SendHTMLEmail sends a formatted HTML email.
	SendHTMLEmail(ctx context.Context, subject string, templatePath string) error
}

HTMLEmailer is an interface for types which are able to send formatted emails using HTML.

type Kind added in v0.0.4

type Kind string

Kind represents a kind of notification.

type Lookup added in v0.0.4

type Lookup func(int64, Kind) ([]string, time.Duration, error)

Lookup is a function that returns the recipients and their corresponding notification period for a given site and notification kind. It is used with WithRecipientLookup.

type MailjetNotifier added in v0.0.4

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

Notifier represents a notifier that uses the Mailjet API to send email.

func NewMailjetNotifier added in v0.0.4

func NewMailjetNotifier(options ...Option) (*MailjetNotifier, error)

NewMailjetNotifier initializes a MailjetNotifier with the supplied options. See WithSender, WithRecipient, WithFilter, WithStore and WithSecrets for a description of the various options. Secrets are required to send actual emails using the Mailjet API, but can be omitted during testing.

func (*MailjetNotifier) Recipients added in v0.0.4

func (n *MailjetNotifier) Recipients(skey int64, kind Kind) ([]string, time.Duration, error)

Recipients returns a list of recipients and their corresponding minimum notification period for the given site and notification kind. It uses the WithRecipientLookup function if supplied, else defaults to the recipients supplied by either WithRecipient or WithRecipients and the period supplied by WithPeriod. ErrNoRecipient is returned if there are no recipients.

func (*MailjetNotifier) Send added in v0.0.4

func (n *MailjetNotifier) Send(ctx context.Context, skey int64, kind Kind, msg string) error

Send sends an email message, depending on what options are present. With filters, then all filters must match in order to send. With persistence, then the message is sent only if it was not sent to the same recipient recently.

func (*MailjetNotifier) SendHTMLEmail added in v0.0.4

func (n *MailjetNotifier) SendHTMLEmail(ctx context.Context, subject string, templatePath string, data interface{}) error

SendHTMLEmail sends a formatted HTML email using the MailJet API.

type Notifier

type Notifier interface {
	Send(context.Context, int64, Kind, string) error
	Recipients(int64, Kind) ([]string, time.Duration, error)
}

type Option added in v0.0.4

type Option func(*MailjetNotifier) error

Option is a functional option supplied to Init.

func WithFilter added in v0.0.4

func WithFilter(filter string) Option

WithFilter applies a filter string. If multiple WithFilter options are applied, they form a compound conjunctive filter. Specifiying an empty filter string clears the filter.

func WithPeriod added in v0.0.4

func WithPeriod(period time.Duration) Option

WithPeriod sets the minimum notification period, which is used in conjunction with a TimeStore.

func WithRecipient added in v0.0.4

func WithRecipient(recipient string) Option

WithRecipient sets a single recipient email address.

func WithRecipientLookup added in v0.0.4

func WithRecipientLookup(lookup Lookup) Option

WithRecipientLookup sets a function to look up multiple recipients and their corresponding notification period given a site key and a notification kind.

func WithRecipients added in v0.0.4

func WithRecipients(recipients []string) Option

WithRecipients sets multiple recipient email addresses.

func WithSecrets added in v0.0.4

func WithSecrets(secrets map[string]string) Option

WithSecrets applies the secrets necessary for sending email, notably the public and private mail API keys. This is always required, unless testing.

func WithSender added in v0.0.4

func WithSender(sender string) Option

WithSender sets the sender email address.

func WithStore added in v0.0.4

func WithStore(store TimeStore) Option

WithStore applies a TimeStore for notification persistence. Combine with WithPeriod to enforce a minimum notification period. See also TimeStore.

type TimeStore

type TimeStore interface {
	Sendable(context.Context, int64, time.Duration, string) (bool, error) // Returns true if a message is sendable.
	Sent(context.Context, int64, string) error                            // Records the time a message was sent.
}

TimeStore is an interface for notification persistence.

func NewStore added in v0.0.4

func NewStore(store datastore.Store) TimeStore

NewStore returns a TimeStore that uses a datastore for notification persistence.

Jump to

Keyboard shortcuts

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