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 ¶
- Variables
- func NewDiscordSender() *webhookChannelSender
- func NewSlackSender() *webhookChannelSender
- type ChannelSender
- type Dispatcher
- type Enqueuer
- type Input
- type Registry
- type Service
- func (s *Service) Create(workspaceID uint, in Input) (*models.NotificationChannel, error)
- func (s *Service) Delete(workspaceID, id uint) error
- func (s *Service) Get(workspaceID, id uint) (*models.NotificationChannel, error)
- func (s *Service) List(workspaceID uint) ([]models.NotificationChannel, error)
- func (s *Service) Reencrypt(ctx context.Context, workspaceID uint) (int, error)
- func (s *Service) Test(ctx context.Context, workspaceID, id uint) error
- func (s *Service) Update(workspaceID, id uint, in Input) (*models.NotificationChannel, error)
- type TelegramSender
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
func (r *Registry) Send(ctx context.Context, ch *models.NotificationChannel, e *models.AppEvent) error
Send dispatches an event to a channel via its type's sender.
func (*Registry) Sender ¶
func (r *Registry) Sender(t models.NotificationChannelType) (ChannelSender, bool)
Sender returns the sender for a channel type, or false if unsupported.
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) 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 ¶
Reencrypt re-encrypts the secret values in each notification channel's config (bot token, webhook URL) under the workspace's active DEK. Idempotent.
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 ¶
func (s *TelegramSender) Send(ctx context.Context, ch *models.NotificationChannel, e *models.AppEvent) error
Send renders the event and posts it to the configured chat.
func (*TelegramSender) Validate ¶
func (s *TelegramSender) Validate(ctx context.Context, ch *models.NotificationChannel) error
Validate confirms the bot token is valid and the chat is reachable by sending a confirmation message.