webhook

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package webhook delivers outbound notifications to operator-configured URLs (used by alerts and the daily digest). Two delivery contracts: HMAC-signed JSON for generic endpoints, and Slack's {"text": ...} shape for Slack incoming webhooks (which reject anything else). Persisted store, best-effort async delivery.

Index

Constants

View Source
const FormatSlack = "slack"

FormatSlack marks an endpoint whose deliveries use Slack's incoming-webhook contract: {"text": "<plain-text rendering>"} instead of signed JSON.

Variables

This section is empty.

Functions

func Send

func Send(ep Endpoint, body []byte, text string) (int, error)

Send POSTs one delivery to an endpoint and returns the HTTP status the endpoint answered with (0 when no response arrived). Slack-format endpoints receive {"text": text} — Slack rejects any other body shape and cannot verify signature headers — while every other endpoint keeps the signed-JSON contract unchanged: the body verbatim plus X-Smolanalytics-Signature. text is the plain-text rendering of body; if a caller passes none, the raw JSON body is used as the text so a Slack message still carries the facts instead of failing.

func SendTest added in v0.8.0

func SendTest(ep Endpoint) (int, error)

SendTest fires a synthetic delivery through the exact path real alerts and digests take (same format rules, signing, SSRF guard, and HTTP client), so a 2xx here means real deliveries will land. Returns the endpoint's HTTP status. Shared by POST /v1/webhooks/{id}/test and the MCP test_webhook tool.

Types

type Endpoint

type Endpoint struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	URL     string    `json:"url"`
	Secret  string    `json:"secret"` // signs the payload so the receiver can verify
	Format  string    `json:"format,omitempty"`
	Enabled bool      `json:"enabled"`
	Created time.Time `json:"created"`
}

Endpoint is one registered webhook target.

func (Endpoint) SlackFormat added in v0.8.0

func (e Endpoint) SlackFormat() bool

SlackFormat reports whether deliveries to e use Slack's {"text": ...} contract: either the endpoint was created with format "slack", or the URL is a Slack incoming webhook (hooks.slack.com) — the host check also covers endpoints persisted before the format field existed.

type Store

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

func Open

func Open(path string) (*Store, error)

func (*Store) Add

func (s *Store) Add(name, url, format string) (Endpoint, error)

Add registers a new endpoint. format is "" (auto-detect: Slack contract for hooks.slack.com URLs, signed JSON for everything else) or "slack" to force the Slack text contract for Slack-compatible receivers on other hosts (Mattermost, Rocket.Chat, …).

func (*Store) Delete

func (s *Store) Delete(id string) error

func (*Store) DeliverAll

func (s *Store) DeliverAll(payload any, text string)

DeliverAll fires the payload to every enabled endpoint, async + best-effort. text is the plain-text rendering that Slack-format endpoints receive.

func (*Store) Get

func (s *Store) Get(id string) (Endpoint, bool)

func (*Store) List

func (s *Store) List() []Endpoint

Jump to

Keyboard shortcuts

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