notify

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package notify provides fire-and-forget webhook notifications with payload tracking.

Package notify provides fire-and-forget webhook notifications.

The webhook URL is stored encrypted in .context/.notify.enc using the same AES-256-GCM key as the scratchpad (resolved via rc.KeyPath()). When no webhook is configured, all operations are silent noops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventAllowed

func EventAllowed(event string, allowed []string) bool

EventAllowed reports whether the given event passes the filter.

A nil or empty allowed list means no events pass (opt-in only).

Parameters:

  • event: the event name to check
  • allowed: list of permitted event names

Returns:

  • bool: true if event appears in the allowed list

func LoadWebhook

func LoadWebhook() (string, error)

LoadWebhook reads and decrypts the webhook URL from .context/.notify.enc.

Returns ("", nil) if either the key file or encrypted file is missing (silent noop: webhook not configured).

Returns:

  • string: the decrypted webhook URL, or "" if not configured
  • error: non-nil only if decryption fails (missing files are silent)

func MaskURL

func MaskURL(url string) string

MaskURL shows the scheme + host and masks everything after the path start.

Parameters:

  • url: full webhook URL.

Returns:

  • string: masked URL safe for display.

func PostJSON

func PostJSON(url string, body []byte) (*http.Response, error)

PostJSON sends a JSON payload to a webhook URL and returns the response. The URL is always user-configured via encrypted storage.

Parameters:

  • url: webhook endpoint.
  • body: JSON-encoded payload bytes.

Returns:

  • *http.Response: the HTTP response (caller must close Body).
  • error: on HTTP failure.

func SaveWebhook

func SaveWebhook(url string) error

SaveWebhook encrypts and writes the webhook URL to .context/.notify.enc.

If the scratchpad key does not exist, it is generated and saved first.

Parameters:

  • url: the webhook endpoint to store

Returns:

  • error: non-nil if key generation, encryption, or file write fails

func Send

func Send(event, message, sessionID string, detail *TemplateRef) error

Send fires a webhook notification. It is a silent noop when:

  • no webhook URL is configured
  • the event is not in the allowed list
  • the HTTP request fails (fire-and-forget)

Parameters:

  • event: notification category (e.g. "relay", "nudge")
  • message: short human-readable summary
  • sessionID: Claude Code session ID (may be empty)
  • detail: structured template reference (nil omits the field)

Types

type Payload

type Payload struct {
	Event     string       `json:"event"`
	Message   string       `json:"message"`
	Detail    *TemplateRef `json:"detail,omitempty"`
	SessionID string       `json:"session_id,omitempty"`
	Timestamp string       `json:"timestamp"`
	Project   string       `json:"project"`
}

Payload is the JSON body sent to the webhook endpoint.

type TemplateRef

type TemplateRef struct {
	Hook      string         `json:"hook"`
	Variant   string         `json:"variant"`
	Variables map[string]any `json:"variables,omitempty"`
}

TemplateRef identifies the hook template and variables that produced a notification, allowing receivers to filter, re-render, or aggregate without parsing opaque rendered text.

func NewTemplateRef

func NewTemplateRef(hook, variant string, vars map[string]any) *TemplateRef

NewTemplateRef constructs a TemplateRef.

Nil variables are omitted from JSON.

Parameters:

  • hook: Hook name that triggered the notification
  • variant: Template variant within the hook
  • vars: Template variables; nil is omitted from JSON

Returns:

  • *TemplateRef: Populated reference

Jump to

Keyboard shortcuts

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