Documentation
¶
Overview ¶
Package notify routes a notification to the channels that should receive it. The Notifier interface is satisfied both by the Dispatcher and by individual channels, so callers never need to know the routing layer exists.
Index ¶
- func NewTool(notifier pkgplugins.Notifier) pkgtools.Tool
- type Dispatcher
- func (d *Dispatcher) Channels() []string
- func (d *Dispatcher) Notify(ctx context.Context, n pkgchannel.Notification) error
- func (d *Dispatcher) NotifyUser(ctx context.Context, userID string, n pkgchannel.Notification) error
- func (d *Dispatcher) Register(ch pkgchannel.Channel)
- func (d *Dispatcher) SetAuthService(service pkgplugins.Auth)
- func (d *Dispatcher) SetChannelStore(store channelStore)
- func (d *Dispatcher) Unregister(name string)
- type Notifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher routes notifications to one or more registered channels. It implements Notifier so it can be passed to tools and scheduler wiring.
func NewDispatcher ¶
func NewDispatcher() *Dispatcher
NewDispatcher creates an empty dispatcher. Register channels before use.
func (*Dispatcher) Channels ¶
func (d *Dispatcher) Channels() []string
Channels returns the names of all registered channels.
func (*Dispatcher) Notify ¶
func (d *Dispatcher) Notify(ctx context.Context, n pkgchannel.Notification) error
Notify routes a notification to channels.
Resolution order:
- If the agent has a dedicated channel that matches the requested channel type (or no channel type is specified), use the dedicated channel.
- If Notification.Channel is set, route to that specific channel.
- Otherwise broadcast to all non-dedicated channels.
func (*Dispatcher) NotifyUser ¶
func (d *Dispatcher) NotifyUser(ctx context.Context, userID string, n pkgchannel.Notification) error
NotifyUser sends a notification to a specific user via a single channel.
Resolution order:
- If the notification came from an agent with a dedicated channel and the user has that platform identity, use the dedicated channel.
- If the user has a notify_identity_id preference, use that platform's non-dedicated channel.
- Otherwise use the first linked identity with a non-dedicated channel.
Falls back to broadcast if the user has no linked identities or if no auth store is configured.
func (*Dispatcher) Register ¶
func (d *Dispatcher) Register(ch pkgchannel.Channel)
Register adds a channel to the dispatcher.
func (*Dispatcher) SetAuthService ¶
func (d *Dispatcher) SetAuthService(service pkgplugins.Auth)
SetAuthService configures the auth directory for per-user notification routing.
func (*Dispatcher) SetChannelStore ¶
func (d *Dispatcher) SetChannelStore(store channelStore)
SetChannelStore configures the channel directory for agent-bound routing.
func (*Dispatcher) Unregister ¶
func (d *Dispatcher) Unregister(name string)
Unregister removes all channels with the given name from the dispatcher.
type Notifier ¶
type Notifier interface {
Notify(ctx context.Context, n pkgchannel.Notification) error
}
Notifier can push notifications. Both Dispatcher and individual channels satisfy this interface, so consumers don't need to know the routing layer.