Files
notifier/internal/domain/notifier.go
T
igodwin 35b6c8aed3 Enhance notification APIs with HTML email support, CC/BCC, and structured logging
Add comprehensive improvements across REST and gRPC APIs:
  - Add structured logging for all notification operations
  - Implement HTML email support with multipart/alternative MIME
  - Add CC and BCC recipient support for email notifications
  - Add GetNotifiers endpoint to query available notifier configurations
  - Support configurable From name in SMTP configuration
  - Auto-detect content type (text vs HTML) in notification bodies
  - Improve error handling and validation across all endpoints

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

  Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 23:31:32 -07:00

87 lines
3.3 KiB
Go

package domain
import (
"context"
)
// Notifier is the core interface that all notification implementations must satisfy
type Notifier interface {
// Send sends a notification and returns the result
Send(ctx context.Context, notification *Notification) (*NotificationResult, error)
// Type returns the notification type this notifier handles
Type() NotificationType
// Validate checks if a notification can be sent with this notifier
Validate(notification *Notification) error
// Close performs cleanup when the notifier is no longer needed
Close() error
}
// NotifierFactory creates notifier instances based on configuration
type NotifierFactory interface {
// Create creates a notifier for the given type and account
// If account is empty, the default account for the type will be used
Create(notificationType NotificationType, account string) (Notifier, error)
// RegisterNotifier registers a custom notifier implementation
RegisterNotifier(notificationType NotificationType, account string, notifier Notifier) error
// SupportedTypes returns all supported notification types
SupportedTypes() []NotificationType
// GetAccounts returns all registered accounts for a given notification type
GetAccounts(notificationType NotificationType) []string
}
// NotificationService is the high-level service interface for managing notifications
type NotificationService interface {
// Send queues a notification for delivery
Send(ctx context.Context, notification *Notification) (*NotificationResult, error)
// SendBatch queues multiple notifications for delivery
SendBatch(ctx context.Context, notifications []*Notification) ([]*NotificationResult, error)
// GetNotification retrieves a notification by ID
GetNotification(ctx context.Context, id string) (*Notification, error)
// ListNotifications retrieves notifications matching the filter
ListNotifications(ctx context.Context, filter *NotificationFilter) ([]*Notification, error)
// CancelNotification cancels a pending notification
CancelNotification(ctx context.Context, id string) error
// RetryNotification retries a failed notification
RetryNotification(ctx context.Context, id string) (*NotificationResult, error)
// GetStats returns notification statistics
GetStats(ctx context.Context) (*NotificationStats, error)
// GetNotifiers returns information about available notifiers
GetNotifiers(ctx context.Context) (*NotifiersResponse, error)
}
// NotificationStats contains statistics about notification processing
type NotificationStats struct {
TotalSent int64 `json:"total_sent"`
TotalFailed int64 `json:"total_failed"`
TotalPending int64 `json:"total_pending"`
TotalQueued int64 `json:"total_queued"`
ByType map[string]int64 `json:"by_type"`
ByStatus map[string]int64 `json:"by_status"`
AverageLatency float64 `json:"average_latency_ms"`
}
// NotifierInfo contains information about a configured notifier type
type NotifierInfo struct {
Type NotificationType `json:"type"`
Accounts []string `json:"accounts"`
DefaultAccount string `json:"default_account"`
}
// NotifiersResponse contains the list of available notifiers
type NotifiersResponse struct {
Notifiers []NotifierInfo `json:"notifiers"`
}