buttons

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 8 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 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.

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 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 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.

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

The subjects of action ids.

Jump to

Keyboard shortcuts

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