Documentation
¶
Overview ¶
Package notifyrules decides whether one message or alert event should notify one recipient (plan pipeline step 6). It is a pure function over plain data: the server (Web Push), the tray app and the web app (a mirror in web/src/lib/notify/rules.ts) all evaluate it on the same vectors in testdata/notify-rules.json. The package uses the standard library only.
Index ¶
Constants ¶
const ( KindText = "text" KindAlert = "alert" KindSystem = "system" )
Message kinds (protocol.Message.Kind).
const ( ChannelPublic = "public" ChannelPrivate = "private" ChannelDM = "dm" ChannelGroupDM = "group_dm" )
Channel kinds.
const ( LevelAll = "all" LevelMentions = "mentions" LevelNone = "none" )
Notification levels of a membership.
const ( SeverityInfo = "info" SeverityWarning = "warning" SeverityCritical = "critical" )
Alert severities.
const ( // TransitionCreated: the alert was opened. TransitionCreated = "created" // TransitionEscalated: a duplicate raised the alert's severity. TransitionEscalated = "escalated" // TransitionRenotifyDue: the renotify interval elapsed while the alert is // open and un-acked. TransitionRenotifyDue = "renotify_due" // TransitionUpdatedOther: a duplicate that changed nothing worth a // notification (occurrence count, last seen, re-rendered body). TransitionUpdatedOther = "updated_other" // TransitionAcked: a member acknowledged the alert. TransitionAcked = "acked" // TransitionResolved: the alert was resolved. TransitionResolved = "resolved" )
Alert transitions: what an alert event did to its alert. A new alert message (message.created, kind alert) is "created"; alert.updated events carry one of the others.
const ( ReasonSystemMessage = "system_message" ReasonUnknownKind = "unknown_message_kind" ReasonOwnMessage = "own_message" ReasonMuted = "muted" ReasonAlertTransition = "alert_transition" ReasonAlertSeverity = "alert_severity_invalid" ReasonBelowMinSeverity = "below_alert_min_severity" ReasonDirect = "direct_message" ReasonLevelAll = "level_all" ReasonMentioned = "mentioned" ReasonChannelMention = "channel_mention" ReasonHereMention = "here_mention" ReasonCriticalAlert = "critical_alert" ReasonNotMentioned = "not_mentioned" ReasonLevelNone = "level_none" ReasonUnknownLevel = "unknown_notify_level" ReasonUnknownMinSeverity = "alert_min_severity_invalid" )
Reasons of a Decision. They are for logs and test failures, not for users.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decision ¶
Decision is the verdict of Decide. Reason names the rule that decided.
func Decide ¶
Decide applies the notification rules in this order, the first to match decides:
- system messages never notify;
- never notify the author;
- a muted membership (Now < MutedUntil) gets nothing, not even critical alerts;
- an alert message notifies only on creation, escalation or renotify due (acked, resolved and other updates do not) and only if its severity is at least the member's alert_min_severity;
- direct messages and group DMs notify;
- notify_level all notifies;
- notify_level mentions notifies when the recipient is mentioned by id, @channel is used, @here is used and the recipient is online, or the message is a critical alert (which passes the mentions level but never a mute);
- notify_level none, and anything unrecognised, does not notify.
type Input ¶
type Input struct {
// RecipientID and AuthorID are the user ids of the person who would be
// notified and of the message's author. A recipient is never notified
// about their own message.
RecipientID string `json:"recipient_id"`
AuthorID string `json:"author_id"`
// ChannelKind is public, private, dm or group_dm.
ChannelKind string `json:"channel_kind"`
// NotifyLevel (all, mentions, none), AlertMinSeverity (info, warning,
// critical) and MutedUntil (nil: not muted) are the recipient's
// membership settings for the channel.
NotifyLevel string `json:"notify_level"`
AlertMinSeverity string `json:"alert_min_severity"`
MutedUntil *int64 `json:"muted_until"`
// Now is the evaluation time. A mute lasts while Now < MutedUntil.
Now int64 `json:"now"`
// Mentions are the message's mentions.
Mentions Mentions `json:"mentions"`
// RecipientOnline is whether the recipient is online (active), which
// decides whether @here reaches them.
RecipientOnline bool `json:"recipient_online"`
// MessageKind is text, alert or system.
MessageKind string `json:"message_kind"`
// AlertTransition and AlertSeverity describe an alert message
// (MessageKind alert); they are ignored for other kinds.
AlertTransition string `json:"alert_transition"`
AlertSeverity string `json:"alert_severity"`
}
Input is everything Decide looks at. Times are unix milliseconds.