notify

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package notify provides notification services for workflow events.

Core types:

  • Notifier: Interface for sending notifications
  • Event: Notification event with type, message, and metadata
  • EventType: Type of event (started, completed, failed, etc.)

Implementations:

  • SlackNotifier: Sends notifications to Slack webhooks
  • WebhookNotifier: Sends notifications to generic webhooks
  • LogNotifier: Logs notifications (for testing/debugging)
  • MultiNotifier: Combines multiple notifiers
  • NopNotifier: No-op notifier (for testing)

Example usage:

notifier := notify.NewSlack(webhookURL,
    notify.WithChannel("#dev-alerts"),
    notify.WithUsername("devflow-bot"),
)
err := notifier.Notify(ctx, notify.Event{
    Type:    notify.EventCompleted,
    Message: "Workflow completed successfully",
})

Index

Constants

View Source
const (
	SeverityCritical = "critical"
	SeverityError    = "error"
	SeverityWarning  = "warning"
	SeverityInfo     = "info"
)

Severity constants for notifications and findings. These are shared between notification events and review findings.

Variables

This section is empty.

Functions

func WithNotifier

func WithNotifier(ctx context.Context, n Notifier) context.Context

WithNotifier adds a Notifier to the context.

Types

type Event

type Event struct {
	Type      EventType      `json:"type"`
	RunID     string         `json:"run_id"`
	FlowID    string         `json:"flow_id"`
	NodeID    string         `json:"node_id,omitempty"`
	Message   string         `json:"message"`
	Severity  string         `json:"severity"` // SeverityInfo, SeverityWarning, SeverityError
	Timestamp time.Time      `json:"timestamp"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

Event describes a workflow event for notification.

type EventType

type EventType string

EventType represents the type of workflow event.

const (
	EventRunStarted    EventType = "run_started"
	EventRunCompleted  EventType = "run_completed"
	EventRunFailed     EventType = "run_failed"
	EventNodeStarted   EventType = "node_started"
	EventNodeCompleted EventType = "node_completed"
	EventNodeFailed    EventType = "node_failed"
	EventReviewNeeded  EventType = "review_needed"
	EventPRCreated     EventType = "pr_created"
)

Event type constants.

type LogNotifier

type LogNotifier struct {
	Logger *slog.Logger
}

LogNotifier logs notifications using slog (for testing/debugging).

func NewLogNotifier

func NewLogNotifier(logger *slog.Logger) *LogNotifier

NewLogNotifier creates a notifier that logs to the given logger. If logger is nil, uses the default slog logger.

func (*LogNotifier) Notify

func (n *LogNotifier) Notify(ctx context.Context, event Event) error

Notify implements Notifier.

type MultiNotifier

type MultiNotifier struct {
	Notifiers []Notifier
	Logger    *slog.Logger
}

MultiNotifier sends notifications to multiple notifiers.

func NewMultiNotifier

func NewMultiNotifier(notifiers ...Notifier) *MultiNotifier

NewMultiNotifier creates a notifier that fans out to multiple notifiers. Errors from individual notifiers are logged but don't stop other notifications.

func (*MultiNotifier) Notify

func (n *MultiNotifier) Notify(ctx context.Context, event Event) error

Notify implements Notifier.

type NopNotifier

type NopNotifier struct{}

NopNotifier is a no-op notifier that discards all notifications. Useful for testing or when notifications are disabled.

func (NopNotifier) Notify

func (NopNotifier) Notify(ctx context.Context, event Event) error

Notify implements Notifier.

type Notifier

type Notifier interface {
	// Notify sends a notification. Implementations should be non-blocking
	// and handle errors gracefully (log, don't crash).
	Notify(ctx context.Context, event Event) error
}

Notifier sends notifications about workflow events.

func MustNotifierFromContext

func MustNotifierFromContext(ctx context.Context) Notifier

MustNotifierFromContext extracts the Notifier or panics.

func NotifierFromContext

func NotifierFromContext(ctx context.Context) Notifier

NotifierFromContext extracts the Notifier from context. Returns nil if no notifier is configured.

type SlackNotifier

type SlackNotifier struct {
	WebhookURL string
	Channel    string
	Username   string
	Client     *http.Client
}

SlackNotifier sends notifications to a Slack webhook.

func NewSlackNotifier

func NewSlackNotifier(webhookURL string, opts ...SlackOption) *SlackNotifier

NewSlackNotifier creates a Slack webhook notifier.

func (*SlackNotifier) Notify

func (n *SlackNotifier) Notify(ctx context.Context, event Event) error

Notify implements Notifier.

type SlackOption

type SlackOption func(*SlackNotifier)

SlackOption configures SlackNotifier.

func WithSlackChannel

func WithSlackChannel(channel string) SlackOption

WithSlackChannel sets the channel to post to.

func WithSlackUsername

func WithSlackUsername(username string) SlackOption

WithSlackUsername sets the bot username.

type WebhookNotifier

type WebhookNotifier struct {
	URL     string
	Headers map[string]string
	Client  *http.Client
}

WebhookNotifier sends notifications to a generic HTTP webhook.

func NewWebhookNotifier

func NewWebhookNotifier(url string, headers map[string]string) *WebhookNotifier

NewWebhookNotifier creates a webhook notifier.

func (*WebhookNotifier) Notify

func (n *WebhookNotifier) Notify(ctx context.Context, event Event) error

Notify implements Notifier.

Jump to

Keyboard shortcuts

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