notify

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package notify turns persisted application events into outbound notifications: it fans an event out to a workspace's webhooks and channels, and renders/sends channel messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("notification channel not found")
	ErrNameRequired       = errors.New("channel name is required")
	ErrUnsupportedType    = errors.New("unsupported channel type")
	ErrTokenRequired      = errors.New("telegram bot token is required")
	ErrChatIDRequired     = errors.New("telegram chat id is required")
	ErrWebhookURLRequired = errors.New("webhook url is required")
	ErrInvalidEvent       = errors.New("unknown or non-notifiable event")
)

Functions

func NewDiscordSender

func NewDiscordSender() *webhookChannelSender

NewDiscordSender posts to a Discord webhook ({"content": ...}).

func NewSlackSender

func NewSlackSender() *webhookChannelSender

NewSlackSender posts to a Slack incoming webhook ({"text": ...}).

Types

type ChannelSender

type ChannelSender interface {
	// Send delivers the event to the channel. Returning an error signals the
	// worker to retry.
	Send(ctx context.Context, ch *models.NotificationChannel, e *models.AppEvent) error
	// Validate checks the channel's configuration by performing a live probe
	// (used by the test endpoint).
	Validate(ctx context.Context, ch *models.NotificationChannel) error
}

ChannelSender delivers a rendered event message over one transport.

type Dispatcher

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

Dispatcher implements events.Notifier. It enqueues a single fan-out task per event; channel resolution and delivery happen in the worker.

func NewDispatcher

func NewDispatcher(enqueuer Enqueuer) *Dispatcher

func (*Dispatcher) OnEvent

func (d *Dispatcher) OnEvent(e *models.AppEvent)

OnEvent schedules fan-out for a persisted, notifiable event. Best-effort: a failure is logged but never propagated to the recorder.

type Enqueuer

type Enqueuer interface {
	EnqueueNotifyFanout(appEventID uint) error
}

Enqueuer schedules the fan-out of a recorded event. Implemented by worker.Producer; defined here so this package does not import worker (which in turn imports this package for the sender registry).

type Input

type Input struct {
	Type    models.NotificationChannelType
	Name    string
	Events  []string
	Enabled bool
	// Telegram.
	BotToken string
	ChatID   string
	// Slack / Discord.
	WebhookURL string
}

Input describes a channel to create or update. Secret values are plaintext; they are encrypted before storage and, on update, an empty value leaves the stored secret unchanged.

type Registry

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

Registry resolves a sender by channel type.

func NewRegistry

func NewRegistry() *Registry

NewRegistry builds the default registry with all supported channel types.

func (*Registry) Send

Send dispatches an event to a channel via its type's sender.

func (*Registry) Sender

Sender returns the sender for a channel type, or false if unsupported.

func (*Registry) Validate

func (r *Registry) Validate(ctx context.Context, ch *models.NotificationChannel) error

Validate probes a channel's configuration via its type's sender.

type Service

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

Service manages notification-channel configuration and on-demand testing.

func NewService

func NewService(repo *repositories.NotificationChannelRepository, registry *Registry) *Service

func (*Service) Create

func (s *Service) Create(workspaceID uint, in Input) (*models.NotificationChannel, error)

func (*Service) Delete

func (s *Service) Delete(workspaceID, id uint) error

func (*Service) Get

func (s *Service) Get(workspaceID, id uint) (*models.NotificationChannel, error)

func (*Service) List

func (s *Service) List(workspaceID uint) ([]models.NotificationChannel, error)

func (*Service) Reencrypt

func (s *Service) Reencrypt(ctx context.Context, workspaceID uint) (int, error)

Reencrypt re-encrypts the secret values in each notification channel's config (bot token, webhook URL) under the workspace's active DEK. Idempotent.

func (*Service) Test

func (s *Service) Test(ctx context.Context, workspaceID, id uint) error

Test sends a confirmation message to the channel using its stored config.

func (*Service) Update

func (s *Service) Update(workspaceID, id uint, in Input) (*models.NotificationChannel, error)

type TelegramSender

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

TelegramSender delivers notifications via the Telegram Bot API.

func NewTelegramSender

func NewTelegramSender() *TelegramSender

func (*TelegramSender) Send

Send renders the event and posts it to the configured chat.

func (*TelegramSender) Validate

Validate confirms the bot token is valid and the chat is reachable by sending a confirmation message.

Jump to

Keyboard shortcuts

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