notify

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package notify delivers completed investigations to chat (Slack, Matrix).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(inv providers.Investigation) string

Format renders an Investigation as a concise markdown-ish message used by all notifiers.

func FormatProgress added in v0.3.0

func FormatProgress(up providers.ProgressUpdate) string

FormatProgress renders an interim progress update as a concise plain-text status line, shared by notifiers (Slack fallback; Matrix/webhook later). The fields are untrusted (title + model interim text), so a mrkdwn-parsing notifier escapes the composed output before sending.

func Register added in v0.2.0

func Register(d Descriptor)

Register adds a notifier descriptor to the registry. Panics on duplicate names.

Types

type Deps added in v0.2.0

type Deps struct {
	Cfg *config.Config
	Log *slog.Logger
}

Deps holds the shared dependencies passed to every notifier builder.

type Descriptor added in v0.2.0

type Descriptor struct {
	Name  string
	Build func(Deps) (providers.Notifier, error) // returns nil when unconfigured (disabled)
}

Descriptor describes a self-registering notifier.

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix delivers via the Matrix client-server send API.

func NewMatrix

func NewMatrix(homeserver, roomID, token string) *Matrix

NewMatrix builds a Matrix notifier. homeserver is the base URL (e.g. https://matrix.org); roomID is like "!abc:hs"; token is an access token.

The txn counter is seeded from the wall clock (UnixNano) rather than 0 so that transaction ids keep increasing across process restarts. Homeservers dedupe by (access_token, txnId); a fresh process starting back at "runlore-1" could otherwise collide with a pre-restart id and have its message silently dropped. Caveat: a backwards wall-clock jump across a restart could still collide — an acceptable residual given the dedup window is minutes and the prior behaviour offered zero protection.

func (*Matrix) Deliver

func (m *Matrix) Deliver(ctx context.Context, inv providers.Investigation) error

Deliver sends the formatted investigation as an m.notice message. It carries both a plaintext body (the fallback Matrix renders literally) and a rich formatted_body (org.matrix.custom.html) so the message's mrkdwn renders as bold/links/code instead of leaking raw *asterisks* to Matrix clients.

type Multi

type Multi struct {
	// contains filtered or unexported fields
}

Multi delivers to several notifiers, best-effort: a failing notifier is logged, not propagated, so one bad sink doesn't block the others.

func BuildEnabled added in v0.2.0

func BuildEnabled(deps Deps) (*Multi, error)

BuildEnabled builds every registered notifier whose Build returns non-nil, in deterministic (name-sorted) order, and wraps them in a Multi.

func NewMulti

func NewMulti(log *slog.Logger, notifiers ...providers.Notifier) *Multi

NewMulti builds a fan-out notifier.

func (*Multi) Deliver

func (m *Multi) Deliver(ctx context.Context, inv providers.Investigation) error

Deliver fans out to every notifier (best-effort: one bad sink never blocks the others), logs each failure, and returns the joined errors so the caller can tell delivery was incomplete. Returns nil when all sinks succeed.

func (*Multi) DeliverProgress added in v0.3.0

func (m *Multi) DeliverProgress(ctx context.Context, up providers.ProgressUpdate) error

DeliverProgress fans an interim progress ping out to every wrapped notifier that implements ProgressNotifier (the type-assert capability check), skipping those that don't (Matrix/webhook may no-op for now). It is best-effort by contract: a failing sink is logged and swallowed, never propagated — a progress ping must never fail an investigation. Returns nil always.

func (*Multi) Len

func (m *Multi) Len() int

Len reports how many notifiers are configured.

type Slack

type Slack struct {
	// contains filtered or unexported fields
}

Slack delivers via a Slack incoming webhook.

func NewSlack

func NewSlack(webhookURL string) *Slack

NewSlack builds a Slack webhook notifier.

func (*Slack) Deliver

func (s *Slack) Deliver(ctx context.Context, inv providers.Investigation) error

Deliver posts the formatted investigation to the webhook. When an action carries an ApprovalID, it renders interactive Approve/Reject buttons (Block Kit).

func (*Slack) DeliverProgress added in v0.3.0

func (s *Slack) DeliverProgress(ctx context.Context, up providers.ProgressUpdate) error

DeliverProgress posts an interim progress ping to the webhook (ProgressNotifier).

type SlackBot

type SlackBot struct {
	// contains filtered or unexported fields
}

SlackBot delivers via the Slack Web API (chat.postMessage) using a bot token, for workspaces that provision a bot app instead of an incoming webhook. Unlike a webhook, chat.postMessage targets an explicit channel and returns HTTP 200 with {"ok":false,"error":...} on logical failures (e.g. not_in_channel).

func NewSlackBot

func NewSlackBot(token, channel string) *SlackBot

NewSlackBot builds a bot-token Slack notifier posting to channel (ID or name).

func (*SlackBot) Deliver

func (s *SlackBot) Deliver(ctx context.Context, inv providers.Investigation) error

Deliver posts the formatted investigation to the configured channel via chat.postMessage, surfacing both transport and Slack API (ok:false) errors.

func (*SlackBot) DeliverProgress added in v0.3.0

func (s *SlackBot) DeliverProgress(ctx context.Context, up providers.ProgressUpdate) error

DeliverProgress posts an interim progress ping to the channel (ProgressNotifier).

Directories

Path Synopsis
Package webhook is a generic outgoing-webhook notifier: it POSTs each investigation's findings as JSON to an operator-configured URL.
Package webhook is a generic outgoing-webhook notifier: it POSTs each investigation's findings as JSON to an operator-configured URL.

Jump to

Keyboard shortcuts

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