81 lines
3.1 KiB
Go
81 lines
3.1 KiB
Go
// Package ironnotify provides an SDK for sending notifications via IronNotify.
|
|
package ironnotify
|
|
|
|
import "time"
|
|
|
|
// SeverityLevel represents the severity of a notification.
|
|
type SeverityLevel string
|
|
|
|
const (
|
|
SeverityInfo SeverityLevel = "info"
|
|
SeveritySuccess SeverityLevel = "success"
|
|
SeverityWarning SeverityLevel = "warning"
|
|
SeverityError SeverityLevel = "error"
|
|
SeverityCritical SeverityLevel = "critical"
|
|
)
|
|
|
|
// ConnectionState represents the WebSocket connection state.
|
|
type ConnectionState string
|
|
|
|
const (
|
|
StateDisconnected ConnectionState = "disconnected"
|
|
StateConnecting ConnectionState = "connecting"
|
|
StateConnected ConnectionState = "connected"
|
|
StateReconnecting ConnectionState = "reconnecting"
|
|
)
|
|
|
|
// NotificationAction represents an action button on a notification.
|
|
type NotificationAction struct {
|
|
Label string `json:"label"`
|
|
URL string `json:"url,omitempty"`
|
|
Action string `json:"action,omitempty"`
|
|
Style string `json:"style,omitempty"`
|
|
}
|
|
|
|
// NotificationPayload represents the data sent to create a notification.
|
|
type NotificationPayload struct {
|
|
EventType string `json:"eventType"`
|
|
Title string `json:"title"`
|
|
Message string `json:"message,omitempty"`
|
|
Severity SeverityLevel `json:"severity,omitempty"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
Actions []NotificationAction `json:"actions,omitempty"`
|
|
UserID string `json:"userId,omitempty"`
|
|
GroupKey string `json:"groupKey,omitempty"`
|
|
DeduplicationKey string `json:"deduplicationKey,omitempty"`
|
|
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
|
|
}
|
|
|
|
// Notification represents a notification received from the server.
|
|
type Notification struct {
|
|
ID string `json:"id"`
|
|
EventType string `json:"eventType"`
|
|
Title string `json:"title"`
|
|
Message string `json:"message,omitempty"`
|
|
Severity SeverityLevel `json:"severity"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
Actions []NotificationAction `json:"actions,omitempty"`
|
|
UserID string `json:"userId,omitempty"`
|
|
GroupKey string `json:"groupKey,omitempty"`
|
|
Read bool `json:"read"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
|
|
}
|
|
|
|
// SendResult represents the result of sending a notification.
|
|
type SendResult struct {
|
|
Success bool `json:"success"`
|
|
NotificationID string `json:"notificationId,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Queued bool `json:"queued,omitempty"`
|
|
}
|
|
|
|
// NotificationHandler is a callback function for receiving notifications.
|
|
type NotificationHandler func(notification Notification)
|
|
|
|
// UnreadCountHandler is a callback function for unread count changes.
|
|
type UnreadCountHandler func(count int)
|
|
|
|
// ConnectionStateHandler is a callback function for connection state changes.
|
|
type ConnectionStateHandler func(state ConnectionState)
|