notification

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOrganizationNotFound reports a missing organization.
	ErrOrganizationNotFound = errors.New("organization not found")
	// ErrProjectNotFound reports a missing project.
	ErrProjectNotFound = errors.New("project not found")
	// ErrChannelNotFound reports a missing notification channel.
	ErrChannelNotFound = errors.New("notification channel not found")
	// ErrChannelInUse reports that a notification channel is still referenced by rules.
	ErrChannelInUse = errors.New("notification channel is still referenced by notification rules")
	// ErrDuplicateChannelName reports duplicate channel names within the same organization.
	ErrDuplicateChannelName = errors.New("notification channel name already exists in organization")
	// ErrRuleNotFound reports a missing notification rule.
	ErrRuleNotFound = errors.New("notification rule not found")
	// ErrDuplicateRuleName reports duplicate notification rule names within the same project.
	ErrDuplicateRuleName = errors.New("notification rule name already exists in project")
)
View Source
var (
	// ErrChannelTypeUnsupported reports unsupported notification channel types.
	ErrChannelTypeUnsupported = errors.New("notification channel type is not supported")
)

Functions

func HMACPreview

func HMACPreview(secret string) string

HMACPreview returns a deterministic header-safe signature preview for masked responses.

func NormalizeChannelConfig

func NormalizeChannelConfig(channelType ChannelType, raw map[string]any) (map[string]any, error)

NormalizeChannelConfig validates and normalizes raw config before persistence.

func RedactedConfig

func RedactedConfig(channelType ChannelType, raw map[string]any) map[string]any

RedactedConfig returns a response-safe config snapshot.

func RuleEventTopic added in v0.4.0

func RuleEventTopic(eventType RuleEventType) (string, bool)

RuleEventTopic returns the only supported runtime topic for the event type.

Types

type Channel

type Channel struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	Name           string
	Type           ChannelType
	Config         map[string]any
	IsEnabled      bool
	CreatedAt      time.Time
}

Channel stores the persisted notification channel aggregate.

type ChannelConfig

type ChannelConfig interface {
	// contains filtered or unexported methods
}

ChannelConfig is the marker interface for validated adapter configuration.

func ParseChannelConfig

func ParseChannelConfig(channelType ChannelType, raw map[string]any) (ChannelConfig, error)

ParseChannelConfig turns raw persisted config into a validated typed config.

type ChannelInput

type ChannelInput struct {
	Name      string         `json:"name"`
	Type      string         `json:"type"`
	Config    map[string]any `json:"config"`
	IsEnabled *bool          `json:"is_enabled"`
}

ChannelInput carries raw create/update request values before parsing.

type ChannelPatchInput

type ChannelPatchInput struct {
	Name      *string         `json:"name"`
	Type      *string         `json:"type"`
	Config    *map[string]any `json:"config"`
	IsEnabled *bool           `json:"is_enabled"`
}

ChannelPatchInput carries raw patch values before parsing.

type ChannelType

type ChannelType string

ChannelType identifies a notification delivery integration.

const (
	ChannelTypeWebhook  ChannelType = "webhook"
	ChannelTypeTelegram ChannelType = "telegram"
	ChannelTypeSlack    ChannelType = "slack"
	ChannelTypeWeCom    ChannelType = "wecom"
)

func ParseChannelType

func ParseChannelType(raw string) (ChannelType, error)

ParseChannelType validates a raw channel type string.

func (ChannelType) String

func (t ChannelType) String() string

type ChannelUsageConflict

type ChannelUsageConflict struct {
	ChannelID uuid.UUID                   `json:"channel_id"`
	Rules     []ChannelUsageRuleReference `json:"rules"`
}

func (*ChannelUsageConflict) Error

func (e *ChannelUsageConflict) Error() string

func (*ChannelUsageConflict) Unwrap

func (e *ChannelUsageConflict) Unwrap() error

type ChannelUsageRuleReference

type ChannelUsageRuleReference struct {
	ID        uuid.UUID `json:"id"`
	ProjectID uuid.UUID `json:"project_id"`
	Name      string    `json:"name"`
	EventType string    `json:"event_type"`
	IsEnabled bool      `json:"is_enabled"`
}

type CreateChannelInput

type CreateChannelInput struct {
	OrganizationID uuid.UUID
	Name           string
	Type           ChannelType
	Config         map[string]any
	IsEnabled      bool
}

CreateChannelInput is the validated create command input.

func ParseCreateChannel

func ParseCreateChannel(organizationID uuid.UUID, raw ChannelInput) (CreateChannelInput, error)

ParseCreateChannel validates an incoming channel create request.

type CreateRuleInput

type CreateRuleInput struct {
	ProjectID uuid.UUID
	Name      string
	EventType RuleEventType
	Filter    map[string]any
	ChannelID uuid.UUID
	Template  string
	IsEnabled bool
}

CreateRuleInput is the parsed create command.

func ParseCreateRule

func ParseCreateRule(projectID uuid.UUID, raw RuleInput) (CreateRuleInput, error)

ParseCreateRule validates an incoming rule create request.

type Message

type Message struct {
	Title    string
	Body     string
	Level    string
	Link     string
	Metadata map[string]string
}

Message is the adapter-facing notification payload.

type Optional

type Optional[T any] struct {
	Set   bool
	Value T
}

Optional captures whether a field was set in a patch request.

func Some

func Some[T any](value T) Optional[T]

Some marks a value as explicitly set.

type ProjectRef

type ProjectRef struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
}

ProjectRef carries the minimal project data needed by the notification service.

type Rule

type Rule struct {
	ID        uuid.UUID
	ProjectID uuid.UUID
	ChannelID uuid.UUID
	Name      string
	EventType RuleEventType
	Filter    map[string]any
	Template  string
	IsEnabled bool
	CreatedAt time.Time
	Channel   Channel
}

Rule stores a persisted notification subscription.

func (Rule) Matches

func (r Rule) Matches(context map[string]any) bool

Matches reports whether the rule filter matches the event context.

func (Rule) RenderMessage

func (r Rule) RenderMessage(context map[string]any) (Message, error)

RenderMessage renders the rule template or falls back to the event default.

type RuleEventCatalogEntry

type RuleEventCatalogEntry struct {
	EventType       RuleEventType
	Label           string
	Group           RuleEventGroup
	Level           RuleEventLevel
	DefaultTemplate string
}

RuleEventCatalogEntry describes a selectable event type for UI/API consumers.

func SupportedRuleEvents

func SupportedRuleEvents() []RuleEventCatalogEntry

SupportedRuleEvents returns the event catalog that UI/API clients can use.

type RuleEventContract added in v0.4.0

type RuleEventContract struct {
	EventType       RuleEventType
	Label           string
	Group           RuleEventGroup
	Level           RuleEventLevel
	DefaultTemplate string
	Topic           string
}

RuleEventContract is the shared notification contract used by the API, engine, and tests.

func SupportedRuleEventContracts added in v0.4.0

func SupportedRuleEventContracts() []RuleEventContract

SupportedRuleEventContracts returns the shared runtime contract for supported notification events.

type RuleEventGroup added in v0.3.0

type RuleEventGroup string
const (
	RuleEventGroupTicketLifecycle   RuleEventGroup = "Ticket lifecycle"
	RuleEventGroupTicketReliability RuleEventGroup = "Ticket reliability"
	RuleEventGroupAgentExecution    RuleEventGroup = "Agent / execution"
	RuleEventGroupHookIntegration   RuleEventGroup = "Hook / integration"
	RuleEventGroupPRReview          RuleEventGroup = "PR / review"
	RuleEventGroupInfrastructure    RuleEventGroup = "Infrastructure"
)

func (RuleEventGroup) String added in v0.3.0

func (g RuleEventGroup) String() string

type RuleEventLevel added in v0.3.0

type RuleEventLevel string
const (
	RuleEventLevelInfo     RuleEventLevel = "info"
	RuleEventLevelWarning  RuleEventLevel = "warning"
	RuleEventLevelCritical RuleEventLevel = "critical"
)

func (RuleEventLevel) String added in v0.3.0

func (l RuleEventLevel) String() string

type RuleEventType

type RuleEventType string

RuleEventType identifies a supported notification subscription event.

const (
	RuleEventTypeTicketCreated         RuleEventType = RuleEventType(activityevent.TypeTicketCreated)
	RuleEventTypeTicketUpdated         RuleEventType = RuleEventType(activityevent.TypeTicketUpdated)
	RuleEventTypeTicketStatusChanged   RuleEventType = RuleEventType(activityevent.TypeTicketStatusChanged)
	RuleEventTypeTicketCompleted       RuleEventType = RuleEventType(activityevent.TypeTicketCompleted)
	RuleEventTypeTicketCancelled       RuleEventType = RuleEventType(activityevent.TypeTicketCancelled)
	RuleEventTypeTicketRetryScheduled  RuleEventType = RuleEventType(activityevent.TypeTicketRetryScheduled)
	RuleEventTypeTicketRetryResumed    RuleEventType = RuleEventType(activityevent.TypeTicketRetryResumed)
	RuleEventTypeTicketRetryPaused     RuleEventType = RuleEventType(activityevent.TypeTicketRetryPaused)
	RuleEventTypeTicketBudgetExhausted RuleEventType = RuleEventType(activityevent.TypeTicketBudgetExhausted)
	RuleEventTypeAgentClaimed          RuleEventType = RuleEventType(activityevent.TypeAgentClaimed)
	RuleEventTypeAgentFailed           RuleEventType = RuleEventType(activityevent.TypeAgentFailed)
	RuleEventTypeHookFailed            RuleEventType = RuleEventType(activityevent.TypeHookFailed)
	RuleEventTypeHookPassed            RuleEventType = RuleEventType(activityevent.TypeHookPassed)
	RuleEventTypePROpened              RuleEventType = RuleEventType(activityevent.TypePROpened)
	RuleEventTypePRClosed              RuleEventType = RuleEventType(activityevent.TypePRClosed)
	RuleEventTypeMachineConnected      RuleEventType = RuleEventType(activityevent.TypeMachineConnected)
	RuleEventTypeMachineDisconnected   RuleEventType = RuleEventType(activityevent.TypeMachineDisconnected)
	RuleEventTypeMachineReconnected    RuleEventType = RuleEventType(activityevent.TypeMachineReconnected)
	RuleEventTypeMachineDaemonAuthFail RuleEventType = RuleEventType(activityevent.TypeMachineDaemonAuthFailed)
)

func ParseRuleEventType

func ParseRuleEventType(raw string) (RuleEventType, error)

ParseRuleEventType validates a raw event type string against the supported catalog.

func (RuleEventType) DefaultTemplate

func (t RuleEventType) DefaultTemplate() string

DefaultTemplate returns the built-in template for the event type.

func (RuleEventType) Group added in v0.3.0

func (t RuleEventType) Group() RuleEventGroup

func (RuleEventType) Level added in v0.3.0

func (t RuleEventType) Level() RuleEventLevel

func (RuleEventType) String

func (t RuleEventType) String() string

type RuleInput

type RuleInput struct {
	Name      string         `json:"name"`
	EventType string         `json:"event_type"`
	Filter    map[string]any `json:"filter"`
	ChannelID string         `json:"channel_id"`
	Template  string         `json:"template"`
	IsEnabled *bool          `json:"is_enabled"`
}

RuleInput carries raw rule create values before parsing.

type RulePatchInput

type RulePatchInput struct {
	Name      *string         `json:"name"`
	EventType *string         `json:"event_type"`
	Filter    *map[string]any `json:"filter"`
	ChannelID *string         `json:"channel_id"`
	Template  *string         `json:"template"`
	IsEnabled *bool           `json:"is_enabled"`
}

RulePatchInput carries raw rule patch values before parsing.

type SlackConfig

type SlackConfig struct {
	WebhookURL string
}

SlackConfig holds Slack incoming webhook settings.

type TelegramConfig

type TelegramConfig struct {
	BotToken string
	ChatID   string
}

TelegramConfig holds Bot API credentials.

type UnsupportedRuleEvent added in v0.4.0

type UnsupportedRuleEvent struct {
	EventType string
	Reason    string
}

func ExplicitlyUnsupportedRuleEvents added in v0.4.0

func ExplicitlyUnsupportedRuleEvents() []UnsupportedRuleEvent

ExplicitlyUnsupportedRuleEvents returns product-level exclusions that must stay out of notification rules.

type UpdateChannelInput

type UpdateChannelInput struct {
	ChannelID uuid.UUID
	Name      Optional[string]
	Type      Optional[ChannelType]
	Config    Optional[map[string]any]
	IsEnabled Optional[bool]
}

UpdateChannelInput is the validated patch command input.

func ParseUpdateChannel

func ParseUpdateChannel(channelID uuid.UUID, raw ChannelPatchInput) (UpdateChannelInput, error)

ParseUpdateChannel validates a raw patch request into a typed update command.

type UpdateRuleInput

type UpdateRuleInput struct {
	RuleID    uuid.UUID
	Name      Optional[string]
	EventType Optional[RuleEventType]
	Filter    Optional[map[string]any]
	ChannelID Optional[uuid.UUID]
	Template  Optional[string]
	IsEnabled Optional[bool]
}

UpdateRuleInput is the parsed patch command.

func ParseUpdateRule

func ParseUpdateRule(ruleID uuid.UUID, raw RulePatchInput) (UpdateRuleInput, error)

ParseUpdateRule validates a raw rule patch request.

type WeComConfig

type WeComConfig struct {
	WebhookKey string
}

WeComConfig holds WeCom robot webhook settings.

type WebhookConfig

type WebhookConfig struct {
	URL     string
	Headers map[string]string
	Secret  string
}

WebhookConfig holds generic webhook delivery settings.

Jump to

Keyboard shortcuts

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