Documentation
¶
Index ¶
- func AfterSend(fn func(Notification, error))
- func Broadcast(n Notification)
- func Fake(record func(Notification)) (restore func())
- func Send(n Notification) error
- func SendMail(n Notification) error
- type DBNotification
- type DatabaseChannel
- func (c *DatabaseChannel) All(ctx context.Context, notifiableID, notifiableType string) ([]DBNotification, error)
- func (c *DatabaseChannel) Delete(ctx context.Context, id string) error
- func (c *DatabaseChannel) DeleteAll(ctx context.Context, notifiableID, notifiableType string) error
- func (c *DatabaseChannel) MarkAllAsRead(ctx context.Context, notifiableID, notifiableType string) error
- func (c *DatabaseChannel) MarkAsRead(ctx context.Context, id string) error
- func (c *DatabaseChannel) Migrate() error
- func (c *DatabaseChannel) Send(ctx context.Context, notifiableID, notifiableType, notificationType string, ...) error
- func (c *DatabaseChannel) Unread(ctx context.Context, notifiableID, notifiableType string) ([]DBNotification, error)
- type DatabaseNotification
- type DiscordChannel
- type DiscordEmbed
- type DiscordEmbedField
- type DiscordEmbedFooter
- type DiscordMessage
- type DiscordNotification
- type Notification
- type SlackAttachment
- type SlackChannel
- type SlackField
- type SlackMessage
- type SlackNotification
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterSend ¶
func AfterSend(fn func(Notification, error))
AfterSend registers a callback invoked when Send completes. It receives the notification and the error from the mail step (if any); if mail succeeded, the notification was also broadcast (when applicable) before the hook runs.
func Broadcast ¶
func Broadcast(n Notification)
Broadcast sends the notification over the transmit SSE system (if configured). When no Transmit plugin/transport is registered, this is a no-op.
func Fake ¶ added in v1.15.0
func Fake(record func(Notification)) (restore func())
Fake makes Send, SendMail and Broadcast hand notifications to record instead of delivering them, until restore is called. Used by nimbustesting.FakeNotifications.
func Send ¶
func Send(n Notification) error
Send delivers the notification on all supported channels. A notification with a mail message fails to send when no mail driver is configured (mail.Default is nil); return nil from ToMail to skip mail.
func SendMail ¶
func SendMail(n Notification) error
SendMail sends the notification via the configured mail driver (if any).
Types ¶
type DBNotification ¶
type DBNotification struct {
ID string `gorm:"primaryKey;size:36" json:"id"`
Type string `gorm:"size:255;index" json:"type"`
NotifiableID string `gorm:"size:255;index:idx_notifiable" json:"notifiable_id"`
NotifiableType string `gorm:"size:255;index:idx_notifiable" json:"notifiable_type"`
Data string `gorm:"type:text" json:"data"` // JSON-encoded
ReadAt *time.Time `json:"read_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DBNotification represents a stored notification record.
func (DBNotification) TableName ¶
func (DBNotification) TableName() string
TableName returns the table name for the notification model.
type DatabaseChannel ¶
type DatabaseChannel struct {
// contains filtered or unexported fields
}
DatabaseChannel stores notifications in the database.
func NewDatabaseChannel ¶
func NewDatabaseChannel(db *lucid.DB) *DatabaseChannel
NewDatabaseChannel creates a database notification channel.
func (*DatabaseChannel) All ¶
func (c *DatabaseChannel) All(ctx context.Context, notifiableID, notifiableType string) ([]DBNotification, error)
All returns all notifications for a notifiable.
func (*DatabaseChannel) Delete ¶
func (c *DatabaseChannel) Delete(ctx context.Context, id string) error
Delete removes a notification by ID.
func (*DatabaseChannel) DeleteAll ¶
func (c *DatabaseChannel) DeleteAll(ctx context.Context, notifiableID, notifiableType string) error
DeleteAll removes all notifications for a notifiable.
func (*DatabaseChannel) MarkAllAsRead ¶
func (c *DatabaseChannel) MarkAllAsRead(ctx context.Context, notifiableID, notifiableType string) error
MarkAllAsRead marks all notifications for a notifiable as read.
func (*DatabaseChannel) MarkAsRead ¶
func (c *DatabaseChannel) MarkAsRead(ctx context.Context, id string) error
MarkAsRead marks a notification as read.
func (*DatabaseChannel) Migrate ¶
func (c *DatabaseChannel) Migrate() error
Migrate creates the notifications table.
func (*DatabaseChannel) Send ¶
func (c *DatabaseChannel) Send(ctx context.Context, notifiableID, notifiableType, notificationType string, n DatabaseNotification) error
Send stores the notification in the database.
func (*DatabaseChannel) Unread ¶
func (c *DatabaseChannel) Unread(ctx context.Context, notifiableID, notifiableType string) ([]DBNotification, error)
Unread returns unread notifications for a notifiable.
type DatabaseNotification ¶
type DatabaseNotification interface {
Notification
// ToDatabase returns the data map to store in the notifications table.
// Return nil to skip the database channel.
ToDatabase() map[string]any
}
DatabaseNotification is for notifications that support the database channel.
type DiscordChannel ¶
type DiscordChannel struct {
WebhookURL string
// Client overrides the HTTP client (default: 10s timeout).
Client *http.Client
}
DiscordChannel sends notifications via Discord webhooks.
func NewDiscordChannel ¶
func NewDiscordChannel(webhookURL string) *DiscordChannel
NewDiscordChannel creates a Discord channel with the given webhook URL.
func (*DiscordChannel) Send ¶
func (c *DiscordChannel) Send(n DiscordNotification) error
Send sends the notification to Discord.
type DiscordEmbed ¶
type DiscordEmbed struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
Color int `json:"color,omitempty"` // decimal color value
Fields []DiscordEmbedField `json:"fields,omitempty"`
Timestamp string `json:"timestamp,omitempty"` // ISO8601
}
DiscordEmbed represents an embedded rich content block.
type DiscordEmbedField ¶
type DiscordEmbedField struct {
Name string `json:"name"`
Value string `json:"value"`
Inline bool `json:"inline,omitempty"`
}
DiscordEmbedField is a field within a Discord embed.
type DiscordEmbedFooter ¶
type DiscordEmbedFooter struct {
}
DiscordEmbedFooter is the footer of a Discord embed.
type DiscordMessage ¶
type DiscordMessage struct {
Content string `json:"content,omitempty"`
Username string `json:"username,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Embeds []DiscordEmbed `json:"embeds,omitempty"`
}
DiscordMessage represents a Discord webhook message.
type DiscordNotification ¶
type DiscordNotification interface {
Notification
// ToDiscord returns the Discord webhook message, or nil to skip.
ToDiscord() *DiscordMessage
}
DiscordNotification is for notifications that support the Discord channel.
type Notification ¶
type Notification interface {
// ToMail returns the mail message for this notification, or nil to skip mail.
ToMail() *mail.Message
// ToBroadcast returns the channel and payload for realtime broadcasts.
// Return empty channel to skip broadcast.
ToBroadcast() (channel string, payload any)
}
Notification describes a multi-channel notification. Implementations can choose to support one or more channels.
type SlackAttachment ¶
type SlackAttachment struct {
Color string `json:"color,omitempty"`
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
Fields []SlackField `json:"fields,omitempty"`
Fallback string `json:"fallback,omitempty"`
}
SlackAttachment represents a Slack message attachment.
type SlackChannel ¶
type SlackChannel struct {
WebhookURL string
// Client overrides the HTTP client (default: 10s timeout).
Client *http.Client
}
SlackChannel sends notifications via Slack incoming webhooks.
func NewSlackChannel ¶
func NewSlackChannel(webhookURL string) *SlackChannel
NewSlackChannel creates a Slack channel with the given webhook URL.
func (*SlackChannel) Send ¶
func (c *SlackChannel) Send(n SlackNotification) error
Send sends the notification to Slack.
type SlackField ¶
type SlackField struct {
Title string `json:"title"`
Value string `json:"value"`
Short bool `json:"short,omitempty"`
}
SlackField is a key-value field in a Slack attachment.
type SlackMessage ¶
type SlackMessage struct {
Channel string `json:"channel,omitempty"`
Text string `json:"text,omitempty"`
Username string `json:"username,omitempty"`
IconEmoji string `json:"icon_emoji,omitempty"`
Attachments []SlackAttachment `json:"attachments,omitempty"`
}
SlackMessage represents a Slack webhook message.
type SlackNotification ¶
type SlackNotification interface {
Notification
// ToSlack returns the Slack message, or nil to skip.
ToSlack() *SlackMessage
}
SlackNotification is for notifications that support the Slack channel.