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 ¶
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 ¶
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 ¶
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.
type MultiNotifier ¶
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.
type NopNotifier ¶
type NopNotifier struct{}
NopNotifier is a no-op notifier that discards all notifications. Useful for testing or when notifications are disabled.
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 ¶
MustNotifierFromContext extracts the Notifier or panics.
func NotifierFromContext ¶
NotifierFromContext extracts the Notifier from context. Returns nil if no notifier is configured.
type SlackNotifier ¶
SlackNotifier sends notifications to a Slack webhook.
func NewSlackNotifier ¶
func NewSlackNotifier(webhookURL string, opts ...SlackOption) *SlackNotifier
NewSlackNotifier creates a Slack webhook 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 ¶
WebhookNotifier sends notifications to a generic HTTP webhook.
func NewWebhookNotifier ¶
func NewWebhookNotifier(url string, headers map[string]string) *WebhookNotifier
NewWebhookNotifier creates a webhook notifier.