buttons

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package buttons holds the Command buttons of messages (C-12.FR-1, reference.md "Buttons and links by status") and their signed action ids (ADR-0011). An action id is opaque: a version, the kind of its subject, the subject's public_id, the Command and its argument, the first bytes of the id of the key that signed it, and an HMAC-SHA256 with the button-signature sub-key of that key truncated to 128 bits — at most 64 bytes in its compact base64url form, so that Telegram's callback_data holds it. Verification finds the key in the Keyring by its id, which may be any key of the Keyring, and compares the HMAC in constant time. An action id whose key prefix names no key of the Keyring is expired (C-17.FR-6): its key left the Keyring, which a Reminder button, never re-rendered, outlives.

Index

Constants

View Source
const (
	CommandAcknowledge   = "acknowledge"
	CommandUnacknowledge = "unacknowledge"
	CommandResolve       = "resolve"
	CommandSnooze        = "snooze"
	CommandUnsnooze      = "unsnooze"
	CommandStillOnIt     = "still_on_it"
)

The Commands a button carries.

View Source
const (
	ArgumentTomorrow  = 254
	ArgumentWeekStart = 255
)

The arguments of the Snooze buttons of the two Snooze presets (C-10.FR-18), "Until tomorrow {start}" and "Until {day} {start}", in the order of groups.PresetOrder; the arguments below them are the indices of Snooze durations.

View Source
const (
	ItemAcknowledge  = "acknowledge"
	ItemResolve      = "resolve"
	ItemSnooze       = "snooze"
	ItemSnoozePreset = "snooze_preset"
)

The buttons an item of a button set names (ButtonSetItem): Acknowledge, which brings Unacknowledge with it, Resolve, one Snooze duration by its value in seconds, and one Snooze preset.

View Source
const (
	PresetTomorrow  = "tomorrow"
	PresetWeekStart = "week_start"
)

The Snooze presets an item names (SnoozePreset), in the order of the arguments ArgumentTomorrow and ArgumentWeekStart.

View Source
const (
	CodeDuplicate     = "duplicate"
	CodeRequired      = "required"
	CodeOutOfRange    = "out_of_range"
	CodeInvalidFormat = "invalid_format"
)

The codes of an ItemError, from the catalogue of the API (x-problem-codes).

View Source
const MaxLen = 64

MaxLen is the longest action id in its compact form: Telegram's callback_data takes 64 bytes.

View Source
const MaxSnoozeDurations = ArgumentTomorrow

MaxSnoozeDurations is the most Snooze durations a Root message offers as buttons: the indices below the arguments of the Snooze presets.

Variables

View Source
var ErrExpired = errors.New("the action id names a key that is not in the keyring")

ErrExpired is a well-formed action id whose key prefix names no key of the Keyring (C-17.FR-6): it cannot be told from one signed with a key that left the Keyring. Verify returns the Action it reads alongside it, unverified: its Subject and PublicID may only choose an answer and the lookup of what the press is bound to, never run a Command.

View Source
var ErrInvalid = errors.New("the action id is not valid")

ErrInvalid is an action id that is malformed or whose signature does not match.

Functions

func IsPreset

func IsPreset(argument int) bool

IsPreset reports whether the argument of a Snooze button names a Snooze preset rather than the index of a duration.

func LooksSigned

func LooksSigned(s string) bool

LooksSigned reports whether s has the structure of an action id — its length in the compact form, the version, a known subject and Command, and a public_id of the right alphabet — without its signature, which needs the key: the Request log masks every such string, a forged one too (C-23.FR-3).

func Sign

func Sign(k Keys, a Action) (id, keyID string, err error)

Sign is the action id of a, signed with the active key, and the full id of that key, which Mattermost receives as context.key_id and deliveries.desired_button_key_id records.

func Validate

func Validate(in []ItemInput) ([]Item, *ItemError)

Validate reads the items of a request in their order and returns them as a set stores them, each with only the fields its button takes, or the first item that is not valid: a snooze without snooze_seconds (required) or with one below 1 (out_of_range), a snooze_preset without its preset (required), an unknown button or preset (invalid_format), or the same button, duration or preset a second time (duplicate). An item of a duration that no Route has is valid: it is simply never shown.

Types

type Action

type Action struct {
	Subject  Subject
	PublicID string
	Command  string
	Argument int
}

Action is what an action id says.

func Verify

func Verify(k Keys, id, keyID string) (Action, error)

Verify reads an action id and checks its signature with the key of the Keyring its prefix names; keyID, when given, is the full key id Mattermost returns, which must agree with the prefix. A prefix that names no key of the Keyring is ErrExpired, with the unverified Action; anything else is ErrInvalid.

type Button

type Button struct {
	Command  string
	Argument int
}

Button is a button before it is signed: its Command and the argument of a Snooze button, the index of a Snooze duration or the argument of a Snooze preset.

func ForStatus

func ForStatus(status string, snoozeDurations int) []Button

ForStatus are the buttons of a Root message in a status (reference.md): firing — Ack, Resolve, Snooze; acknowledged — Unack, Resolve, Snooze; snoozed — Ack, Unsnooze, Resolve; resolved — none. Snooze is one button per duration of route.snooze_durations, at most MaxSnoozeDurations, then one per Snooze preset when there is at least one duration.

type Item

type Item struct {
	Button        string `json:"button"`
	SnoozeSeconds int64  `json:"snooze_seconds,omitempty"`
	Preset        string `json:"preset,omitempty"`
}

Item is one entry of a button set: a button, the value of a Snooze duration in seconds, or a Snooze preset.

type ItemError

type ItemError struct {
	Index  int
	Code   string
	Detail string
}

ItemError is an item of a set that is not valid: its index, -1 for the list itself, its code and what is wrong.

func (*ItemError) Error

func (e *ItemError) Error() string

func (*ItemError) Pointer

func (e *ItemError) Pointer(set string) string

Pointer is the JSON pointer of the item under the pointer of its set, such as /buttons/items/1, or of the list.

type ItemInput

type ItemInput struct {
	Button        string
	SnoozeSeconds *int64
	Preset        *string
}

ItemInput is an item of a set as a request writes it: snooze_seconds and preset may be missing.

type Keys

type Keys interface {
	Sign(p keyring.Purpose, msg []byte) (mac []byte, keyID string, err error)
	VerifyPrefix(p keyring.Purpose, keyID string, msg, prefix []byte) (bool, error)
	KeyIDs() []string
}

Keys are the keys that sign and verify action ids: the Keyring.

type Own

type Own struct {
	Set   bool
	Items []Item
}

Own is the button set of a Destination (destination.buttons): its own items when Set, otherwise "As in the Organization", which follows the Organization's set.

func ParseOwn

func ParseOwn(raw []byte) (Own, error)

ParseOwn reads a Destination's set as destinations.buttons stores it: an array of items, or null for "As in the Organization".

func (Own) Effective

func (o Own) Effective(org Set) Set

Effective is the set a Destination's Root messages show: its own, else the Organization's org.

func (Own) JSON

func (o Own) JSON() []byte

JSON is the value destinations.buttons stores: the array of items, nil for "As in the Organization".

type Set

type Set struct {
	All   bool   `json:"all"`
	Items []Item `json:"items,omitempty"`
}

Set is a button set (C-28.FR-8): every button, durations a Route gains later included, or the buttons its items list. The zero Set lists none; All is the default of the Organization (organization.buttons).

func All

func All() Set

All is the set of every button.

func ParseSet

func ParseSet(raw []byte) (Set, error)

ParseSet reads the Organization's set as organizations.buttons stores it; an empty value is every button, the default of a row that a replica of 0.1 read before the column existed.

func (Set) Filter

func (s Set) Filter(bs []Button, durations []int64) []Button

Filter are the buttons of bs that the set shows on a Route with the Snooze durations given, in their order, so that the order of ForStatus — reference.md's — stays.

func (Set) Shows

func (s Set) Shows(b Button, durations []int64) bool

Shows reports whether a Root message with the set shows the button b of a Route with the Snooze durations given, in seconds: Acknowledge and Unacknowledge by the item acknowledge, Resolve by resolve, a Snooze duration when its value is an item, a Snooze preset when its preset is; Unsnooze and the buttons of Reminders always, whatever the set. A Snooze button of a duration the Route does not have is not shown.

type Style

type Style string

Style is the style hint of a button, named as the ButtonStyle of the Bridge protocol; each adapter maps it to the closest style of its messenger, neutral being a plain button.

const (
	StyleNeutral Style = "neutral"
	StylePrimary Style = "primary"
	StyleSuccess Style = "success"
)

The style hints Muster uses (D329); the Bridge protocol's danger is not one of them.

func StyleOf

func StyleOf(command string) Style

StyleOf is the style hint of a button of the command: Acknowledge and "Still on it" primary, Resolve success, and every other button, Unacknowledge, Snooze and Unsnooze included, neutral.

type Subject

type Subject string

Subject is what a button is about: the Root message of an Alert Group, a Thread reply of one, or the test message of a Destination; or what the action data of a call through a Notification gateway names, the call (C-30.FR-2).

const (
	SubjectRoot  Subject = "root"
	SubjectReply Subject = "reply"
	SubjectTest  Subject = "test"
	SubjectCall  Subject = "call"
)

The subjects of action ids. A call's public_id stands for every Alert Group the call is about, so that its action data stays within MaxLen however many there are.

Jump to

Keyboard shortcuts

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