Documentation
¶
Index ¶
- func GetBaseDir() string
- type CLIUtils
- type DeleteSubscriptionRequest
- type DeviceInfo
- type HistoryResponse
- type JSONLStorage
- type JSONStorage
- func (s *JSONStorage) AddNotificationHistory(userID string, notification NotificationHistory) error
- func (s *JSONStorage) AddSubscription(userID string, sub Subscription) error
- func (s *JSONStorage) DeleteSubscription(userID string, endpoint string) error
- func (s *JSONStorage) GetAllSubscriptions() ([]Subscription, error)
- func (s *JSONStorage) GetNotificationHistory(userID string, limit, offset int, filters map[string]string) ([]NotificationHistory, int, error)
- func (s *JSONStorage) GetSubscriptions(userID string) ([]Subscription, error)
- func (s *JSONStorage) RotateNotificationHistory(userID string, maxEntries int) error
- func (s *JSONStorage) UpdateSubscription(userID string, subscriptionID string, updates Subscription) error
- type NotificationHistory
- type NotificationResult
- type Service
- func (s *Service) DeleteSubscription(userID string, endpoint string) error
- func (s *Service) GetNotificationHistory(userID string, limit, offset int, filters map[string]string) (*HistoryResponse, error)
- func (s *Service) GetStorage() Storage
- func (s *Service) GetSubscriptions(userID string) ([]Subscription, error)
- func (s *Service) ProcessWebhook(webhook WebhookRequest) error
- func (s *Service) SendNotificationToSession(sessionID string, title, body, notificationType string, ...) error
- func (s *Service) SendNotificationToUser(userID string, title, body, notificationType string, ...) error
- func (s *Service) SetSecretSyncer(syncer SubscriptionSecretSyncer)
- func (s *Service) Subscribe(user *entities.User, endpoint string, keys map[string]string, ...) (*Subscription, error)
- type Storage
- type SubscribeRequest
- type SubscribeResponse
- type Subscription
- type SubscriptionSecretSyncer
- type WebPushService
- type WebhookRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CLIUtils ¶ added in v1.70.0
type CLIUtils struct{}
CLIUtils provides utilities for command-line notification operations
func NewCLIUtils ¶ added in v1.70.0
func NewCLIUtils() *CLIUtils
NewCLIUtils creates a new CLI utilities instance
func (*CLIUtils) GetMatchingSubscriptions ¶ added in v1.70.0
func (u *CLIUtils) GetMatchingSubscriptions(userID, userType, username, sessionID string, verbose bool) ([]Subscription, error)
GetMatchingSubscriptions retrieves subscriptions matching filter criteria
func (*CLIUtils) SendNotifications ¶ added in v1.70.0
func (u *CLIUtils) SendNotifications(subscriptions []Subscription, title, body, url, icon, badge string, ttl int, urgency string, sessionID string, vapidPublicKey, vapidPrivateKey, vapidContactEmail string) ([]NotificationResult, error)
SendNotifications sends notifications to multiple subscriptions
type DeleteSubscriptionRequest ¶
type DeleteSubscriptionRequest struct {
Endpoint string `json:"endpoint" validate:"required"`
}
DeleteSubscriptionRequest represents the request body for deleting a subscription
type DeviceInfo ¶ added in v1.66.0
type DeviceInfo struct {
UserAgent string `json:"user_agent,omitempty"`
DeviceType string `json:"device_type,omitempty"` // "desktop", "mobile", "tablet"
Browser string `json:"browser,omitempty"` // "chrome", "firefox", "safari"
OS string `json:"os,omitempty"` // "windows", "macos", "linux", "android", "ios"
DeviceHash string `json:"device_hash,omitempty"` // Hash of device fingerprint
}
DeviceInfo represents device identification information
func ExtractDeviceInfo ¶ added in v1.66.0
func ExtractDeviceInfo(r *http.Request) *DeviceInfo
ExtractDeviceInfo extracts device information from HTTP request headers
type HistoryResponse ¶
type HistoryResponse struct {
Notifications []NotificationHistory `json:"notifications"`
Total int `json:"total"`
HasMore bool `json:"has_more"`
}
HistoryResponse represents the response for notification history endpoint
type JSONLStorage ¶
type JSONLStorage = JSONStorage
JSONLStorage is deprecated, use JSONStorage instead for better performance and duplicate prevention
type JSONStorage ¶ added in v1.61.0
type JSONStorage struct {
// contains filtered or unexported fields
}
JSONStorage implements Storage using JSON files (not JSONL)
func NewJSONLStorage ¶
func NewJSONLStorage(baseDir string) *JSONStorage
NewJSONLStorage creates a new JSON-based storage (deprecated name for backward compatibility)
func NewJSONStorage ¶ added in v1.61.0
func NewJSONStorage(baseDir string) *JSONStorage
NewJSONStorage creates a new JSON-based storage
func (*JSONStorage) AddNotificationHistory ¶ added in v1.61.0
func (s *JSONStorage) AddNotificationHistory(userID string, notification NotificationHistory) error
AddNotificationHistory adds a notification to the history
func (*JSONStorage) AddSubscription ¶ added in v1.61.0
func (s *JSONStorage) AddSubscription(userID string, sub Subscription) error
AddSubscription adds a new subscription for a user with improved duplicate prevention
func (*JSONStorage) DeleteSubscription ¶ added in v1.61.0
func (s *JSONStorage) DeleteSubscription(userID string, endpoint string) error
DeleteSubscription marks a subscription as inactive
func (*JSONStorage) GetAllSubscriptions ¶ added in v1.61.0
func (s *JSONStorage) GetAllSubscriptions() ([]Subscription, error)
GetAllSubscriptions returns all active subscriptions from all users
func (*JSONStorage) GetNotificationHistory ¶ added in v1.61.0
func (s *JSONStorage) GetNotificationHistory(userID string, limit, offset int, filters map[string]string) ([]NotificationHistory, int, error)
GetNotificationHistory retrieves notification history with pagination and filtering
func (*JSONStorage) GetSubscriptions ¶ added in v1.61.0
func (s *JSONStorage) GetSubscriptions(userID string) ([]Subscription, error)
GetSubscriptions returns all active subscriptions for a user with improved deduplication
func (*JSONStorage) RotateNotificationHistory ¶ added in v1.61.0
func (s *JSONStorage) RotateNotificationHistory(userID string, maxEntries int) error
RotateNotificationHistory keeps only the most recent N entries
func (*JSONStorage) UpdateSubscription ¶ added in v1.61.0
func (s *JSONStorage) UpdateSubscription(userID string, subscriptionID string, updates Subscription) error
UpdateSubscription updates an existing subscription
type NotificationHistory ¶
type NotificationHistory struct {
ID string `json:"id"`
UserID string `json:"user_id"`
SubscriptionID string `json:"subscription_id"`
Title string `json:"title"`
Body string `json:"body"`
Type string `json:"type"`
SessionID string `json:"session_id"`
Data map[string]interface{} `json:"data"`
SentAt time.Time `json:"sent_at"`
Delivered bool `json:"delivered"`
Clicked bool `json:"clicked"`
ErrorMessage *string `json:"error_message"`
}
NotificationHistory represents a notification that was sent
type NotificationResult ¶ added in v1.70.0
type NotificationResult struct {
Subscription Subscription
Error error
}
NotificationResult represents the result of sending a notification
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides notification functionality
func NewService ¶
NewService creates a new notification service
func (*Service) DeleteSubscription ¶
DeleteSubscription removes a subscription by endpoint
func (*Service) GetNotificationHistory ¶
func (s *Service) GetNotificationHistory(userID string, limit, offset int, filters map[string]string) (*HistoryResponse, error)
GetNotificationHistory retrieves notification history for a user
func (*Service) GetStorage ¶ added in v1.90.0
GetStorage returns the storage instance (used by secret syncer)
func (*Service) GetSubscriptions ¶
func (s *Service) GetSubscriptions(userID string) ([]Subscription, error)
GetSubscriptions returns all active subscriptions for a user
func (*Service) ProcessWebhook ¶
func (s *Service) ProcessWebhook(webhook WebhookRequest) error
ProcessWebhook handles incoming webhooks from agentapi
func (*Service) SendNotificationToSession ¶
func (s *Service) SendNotificationToSession(sessionID string, title, body, notificationType string, data map[string]interface{}) error
SendNotificationToSession sends a notification to all users subscribed to a session
func (*Service) SendNotificationToUser ¶
func (s *Service) SendNotificationToUser(userID string, title, body, notificationType string, data map[string]interface{}) error
SendNotificationToUser sends a notification to all subscriptions of a user
func (*Service) SetSecretSyncer ¶ added in v1.90.0
func (s *Service) SetSecretSyncer(syncer SubscriptionSecretSyncer)
SetSecretSyncer sets the secret syncer for syncing subscriptions to K8s Secrets This is optional and only used when Kubernetes mode is enabled
type Storage ¶
type Storage interface {
// Subscription methods
AddSubscription(userID string, sub Subscription) error
GetSubscriptions(userID string) ([]Subscription, error)
GetAllSubscriptions() ([]Subscription, error)
UpdateSubscription(userID string, subscriptionID string, updates Subscription) error
DeleteSubscription(userID string, endpoint string) error
// History methods
AddNotificationHistory(userID string, notification NotificationHistory) error
GetNotificationHistory(userID string, limit, offset int, filters map[string]string) ([]NotificationHistory, int, error)
RotateNotificationHistory(userID string, maxEntries int) error
}
Storage interface for notification data persistence
type SubscribeRequest ¶
type SubscribeRequest struct {
Endpoint string `json:"endpoint" validate:"required"`
Keys map[string]string `json:"keys" validate:"required"`
}
SubscribeRequest represents the request body for subscribing to push notifications
type SubscribeResponse ¶
type SubscribeResponse struct {
Success bool `json:"success"`
SubscriptionID string `json:"subscription_id"`
}
SubscribeResponse represents the response for a successful subscription
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
UserID string `json:"user_id"`
UserType string `json:"user_type"`
Username string `json:"username"`
Endpoint string `json:"endpoint"`
Keys map[string]string `json:"keys"`
SessionIDs []string `json:"session_ids"`
NotificationTypes []string `json:"notification_types"`
DeviceInfo *DeviceInfo `json:"device_info,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastUsed time.Time `json:"last_used,omitempty"`
Active bool `json:"active"`
}
Subscription represents a push notification subscription in the system
type SubscriptionSecretSyncer ¶ added in v1.90.0
type SubscriptionSecretSyncer interface {
// Sync creates or updates the subscription storage for a user
// It reads the current subscriptions from the storage and syncs them to the external storage
Sync(userID string) error
}
SubscriptionSecretSyncer syncs subscription data to an external storage (e.g., Kubernetes Secret) This interface allows the notification service to remain agnostic of the underlying storage mechanism
type WebPushService ¶
type WebPushService struct {
// contains filtered or unexported fields
}
WebPushService handles sending web push notifications
func NewWebPushService ¶
func NewWebPushService() (*WebPushService, error)
NewWebPushService creates a new web push service
func (*WebPushService) SendNotification ¶
func (s *WebPushService) SendNotification(sub Subscription, title, body string, data map[string]interface{}) error
SendNotification sends a push notification to a subscription
func (*WebPushService) SendNotificationWithOptions ¶
func (s *WebPushService) SendNotificationWithOptions(sub Subscription, title, body string, data map[string]interface{}, ttl int, urgency string) error
SendNotificationWithOptions sends a push notification with custom options