Documentation
¶
Overview ¶
Package notifyalert sends the platform's own alerts -- a review queue past its threshold, a connection whose credential was revoked, a scheduled run that failed, a storage or webhook condition -- to the people, personas and notification channels an operator named for each (#1724, #2909).
An alert is authorized as the platform. The operator who named a person, persona or channel in the alert's settings is the authorization: no persona is consulted for the send, and it is charged to no actor. Each channel send passes its own key, so the channel's repeat window applies to an alert that keeps firing. A person is told through the Inbox, and by email as their preference for the alert's category says.
Index ¶
- Constants
- Variables
- func Normalize(names []string) []string
- func Validate(ctx context.Context, store notification.ChannelStore, names []string) error
- func ValidateRouting(ctx context.Context, store notification.ChannelStore, ...) error
- type Personas
- type Reach
- type Sender
- func (s *Sender) Check(ctx context.Context, r notification.Routing) error
- func (s *Sender) People(ctx context.Context, r notification.Routing) []string
- func (s *Sender) Route(ctx context.Context, r notification.Routing, key string, ...) Reach
- func (s *Sender) Send(ctx context.Context, names []string, key string, p notification.Payload) int
- func (s *Sender) Tell(ctx context.Context, r notification.Routing, p notification.Payload) int
Constants ¶
const MaxChannels = notification.MaxRoutingChannels
MaxChannels bounds the channels one alert names, as notification.MaxChannelRecipients bounds an email list.
Variables ¶
var ErrNoChannelStore = errors.New("this deployment has no notification channels to name")
ErrNoChannelStore is returned by Validate for a channel named on a deployment that stores no channels.
var ErrUnknownChannel = errors.New("no notification channel has that name")
ErrUnknownChannel is wrapped by Validate for a name no channel is stored under.
var ErrUnknownPersona = errors.New("no persona has that name")
ErrUnknownPersona is wrapped by ValidateRouting for a name no persona has.
Functions ¶
func Normalize ¶
Normalize trims a submitted channel list, dropping blanks and repeats, so a form's empty last line or a doubled entry is not stored.
func Validate ¶
func Validate(ctx context.Context, store notification.ChannelStore, names []string) error
Validate refuses a channel list an alert cannot send to: too many entries, or a name no channel is stored under. A channel that exists but is disabled is accepted, as it is everywhere else an operator names one: enabling it later should not mean re-entering it here.
func ValidateRouting ¶ added in v1.175.0
func ValidateRouting(ctx context.Context, store notification.ChannelStore, known func(persona string) bool, r notification.Routing) error
ValidateRouting refuses a routing naming a persona known does not report or a channel no channel is stored under. Its bounds and addresses are checked by notification.RoutingInput.Apply. known nil refuses any persona.
Types ¶
type Personas ¶ added in v1.175.0
type Personas struct {
Known func(name string) bool
Members func(ctx context.Context, name string) []string
}
Personas is what an alert needs to know of personas: whether one exists, and the people it reaches when the alert is sent (the confirmed people in the user directory whose recorded roles resolve to it). A nil func knows no persona and reaches nobody.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender sends an alert to people, personas and channels. A nil Sender sends nothing, which is how a deployment with no database is wired.
func New ¶
func New(channels notification.ChannelStore, enqueuer *notification.Enqueuer, personas Personas) *Sender
New builds a Sender, or nil when there is no enqueuer. With no channel store the alert reaches people only.
func (*Sender) Check ¶ added in v1.175.0
Check refuses a routing naming a persona or channel that does not exist. A nil Sender refuses any persona or channel.
func (*Sender) People ¶ added in v1.175.0
People is who r reaches now: its addresses and each member of its personas, deduplicated, in that order. A nil Sender resolves no persona.
func (*Sender) Route ¶ added in v1.175.0
func (s *Sender) Route(ctx context.Context, r notification.Routing, key string, p notification.Payload) Reach
Route tells the people r reaches and posts to its channels under key, and reports how many of each it queued for.
func (*Sender) Send ¶
Send queues the alert's payload for each named channel under key and returns how many channels it was queued for. A channel that is gone, disabled, over its cap or failing is logged and the rest still go out: one bad entry must not silence the alert for every other channel.
func (*Sender) Tell ¶ added in v1.175.0
func (s *Sender) Tell(ctx context.Context, r notification.Routing, p notification.Payload) int
Tell writes the alert to the Inbox of each person r reaches, emailed by their preference for its kind's category, and returns how many it reached. A kind that names no category is filed under Alerts. The platform raised it, so no actor is named.