Documentation
¶
Overview ¶
Package alerts is the alert domain (plan pipeline step 11): an app posts an alert under a dedupe key; repeats update one message instead of flooding the channel, escalations and overdue renotifications are marked as such for the notification dispatcher, members acknowledge and resolve, and a key that was resolved opens a new alert the next time.
Alerts are chat messages (kind alert) plus an alerts row, written through internal/chat in one transaction with their events: message.created for a new alert, message.updated and alert.updated for a repeat, alert.updated for an acknowledgement or resolution.
Index ¶
- Constants
- func Render(title, text string, fields []protocol.AlertField, link string) string
- type ListParams
- type Options
- type PostOptions
- type PostResult
- type Service
- func (s *Service) Ack(ctx context.Context, actor chat.Actor, aud audit.Actor, messageID string) (protocol.Message, error)
- func (s *Service) List(ctx context.Context, actor chat.Actor, p ListParams) (protocol.AlertPage, error)
- func (s *Service) Post(ctx context.Context, actor chat.Actor, in protocol.AlertInput) (PostResult, error)
- func (s *Service) PostWith(ctx context.Context, actor chat.Actor, in protocol.AlertInput, o PostOptions) (PostResult, error)
- func (s *Service) Resolve(ctx context.Context, actor chat.Actor, aud audit.Actor, messageID, text string) (protocol.Message, error)
- func (s *Service) ResolveByKey(ctx context.Context, actor chat.Actor, aud audit.Actor, key, text string) (protocol.Message, error)
Constants ¶
const ( ActionAck = "alert.ack" ActionResolve = "alert.resolve" )
Audit actions written by this package.
const ( MinRenotifyS = 10 MaxRenotifyS = 86400 )
Renotify bounds (seconds) for a per-alert override; 0 turns it off.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
func Render(title, text string, fields []protocol.AlertField, link string) string
Render builds the Markdown body of an alert message: the title in bold, the text, a two-column table of the fields and a link. The body is plain Markdown the clients render with raw HTML disabled; nothing here emits HTML. It never exceeds chat.MaxBodyChars: when the parts are too long, trailing fields are dropped first, then the text is cut.
Types ¶
type ListParams ¶
type ListParams struct {
// State filters by open, acked or resolved; empty means any.
State string
// ChannelID restricts the list to one channel.
ChannelID string
// Cursor is the next_cursor of the previous page.
Cursor string
// Limit is the page size (default 50, at most 100).
Limit int
}
ListParams select a page of alerts.
type PostOptions ¶
type PostOptions struct {
// DisableMentions keeps the alert message free of mentions, whatever its
// text says. Webhooks set it: their text comes from outside.
DisableMentions bool
}
PostOptions tune PostWith.
type PostResult ¶
type PostResult struct {
Message protocol.Message
// Transition is created for a new alert, else escalated, renotify_due or
// updated_other.
Transition string
}
PostResult is what a post did.
func (PostResult) Created ¶
func (r PostResult) Created() bool
Created reports whether the post opened a new alert.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the alerts domain service.
func (*Service) Ack ¶
func (s *Service) Ack(ctx context.Context, actor chat.Actor, aud audit.Actor, messageID string) (protocol.Message, error)
Ack acknowledges an open alert for the actor, a member of its channel. The alert stops renotifying. Acknowledging an acknowledged alert does nothing; a resolved one is ErrConflict. Apps are refused (see rejectAppByID).
func (*Service) List ¶
func (s *Service) List(ctx context.Context, actor chat.Actor, p ListParams) (protocol.AlertPage, error)
List returns alert messages, newest first, from the channels the actor is a member of (for an app also inside its token's allowlist). The page carries message bodies, so an app needs messages:read, whatever else it holds.
func (*Service) Post ¶
func (s *Service) Post(ctx context.Context, actor chat.Actor, in protocol.AlertInput) (PostResult, error)
Post ingests an alert from an app. See the package comment for the rules. The caller must be an app whose token carries alerts:write; the app must be a member of the target channel (and the token's channel allowlist must admit it), else the channel is ErrNotFound.
func (*Service) PostWith ¶
func (s *Service) PostWith(ctx context.Context, actor chat.Actor, in protocol.AlertInput, o PostOptions) (PostResult, error)
PostWith is Post with options.
func (*Service) Resolve ¶
func (s *Service) Resolve(ctx context.Context, actor chat.Actor, aud audit.Actor, messageID, text string) (protocol.Message, error)
Resolve resolves the alert of a message for the actor, a member of its channel, and posts "Resolved by <name>: <text>" in the alert's thread. Resolving a resolved alert returns it unchanged.
func (*Service) ResolveByKey ¶
func (s *Service) ResolveByKey(ctx context.Context, actor chat.Actor, aud audit.Actor, key, text string) (protocol.Message, error)
ResolveByKey resolves the app's alert for dedupe key. It is idempotent: a key whose latest alert is already resolved answers that alert; a key the app never posted is ErrNotFound.