Documentation
¶
Index ¶
- Variables
- func TestMailNotification_SendGroupInvitationEmail(t *testing.T)
- type AliyunSMS
- type AliyunSMSClient
- type AliyunSMSConfig
- type DingTalkConfig
- type DingTalkNotification
- func (d *DingTalkNotification) Send(ctx context.Context, req NotificationRequest) error
- func (d *DingTalkNotification) SendMarkdown(ctx context.Context, title, content string) error
- func (d *DingTalkNotification) SendText(ctx context.Context, content string) error
- func (d *DingTalkNotification) Type() NotificationType
- type FeishuConfig
- type FeishuNotification
- func (f *FeishuNotification) Send(ctx context.Context, req NotificationRequest) error
- func (f *FeishuNotification) SendRichText(ctx context.Context, title, content string) error
- func (f *FeishuNotification) SendText(ctx context.Context, content string) error
- func (f *FeishuNotification) Type() NotificationType
- type InternalNotification
- type InternalNotificationAdapter
- type InternalNotificationService
- func (s *InternalNotificationService) BatchDelete(userID uint, notificationIDs []uint) (int64, error)
- func (s *InternalNotificationService) Delete(userID uint, notificationID uint) error
- func (s *InternalNotificationService) GetOne(userID uint, notificationID uint) (InternalNotification, error)
- func (s *InternalNotificationService) GetPaginatedNotifications(userID uint, page, size int, filter string, ...) ([]InternalNotification, int64, int64, int64, error)
- func (s *InternalNotificationService) GetUnreadNotifications(userID uint) ([]InternalNotification, error)
- func (s *InternalNotificationService) GetUnreadNotificationsCount(userID uint) (count int64, err error)
- func (s *InternalNotificationService) MarkAllAsRead(userID uint) error
- func (s *InternalNotificationService) MarkAsRead(notificationID uint) error
- func (s *InternalNotificationService) Send(userID uint, title, content string) error
- type JPush
- func (j *JPush) PushToAlias(ctx context.Context, alias []string, title, content string, ...) error
- func (j *JPush) PushToAll(ctx context.Context, title, content string, extras map[string]interface{}) error
- func (j *JPush) Send(ctx context.Context, req NotificationRequest) error
- func (j *JPush) Type() NotificationType
- type JPushClient
- type JPushConfig
- type MailConfig
- type MailNotification
- func (m *MailNotification) Send(ctx context.Context, req NotificationRequest) error
- func (m *MailNotification) SendGroupInvitationEmail(...) error
- func (m *MailNotification) SendHTML(to, subject, htmlBody string) error
- func (m *MailNotification) SendPasswordResetEmail(to, username, resetURL string) error
- func (m *MailNotification) SendPlain(to, subject, body string) error
- func (m *MailNotification) SendVerificationCode(to, code string) error
- func (m *MailNotification) SendVerificationEmail(to, username, verifyURL string) error
- func (m *MailNotification) SendWelcomeEmail(to string, username string, verifyURL string) error
- func (m *MailNotification) Type() NotificationType
- type Notification
- type NotificationManager
- type NotificationRequest
- type NotificationType
- type WeChatWorkConfig
- type WeChatWorkNotification
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedNotificationType is returned when notification type is not supported ErrUnsupportedNotificationType = errors.New("unsupported notification type") // ErrInvalidRecipient is returned when recipient is invalid ErrInvalidRecipient = errors.New("invalid recipient") // ErrNotificationNotConfigured is returned when notification is not configured ErrNotificationNotConfigured = errors.New("notification not configured") )
Functions ¶
Types ¶
type AliyunSMS ¶
type AliyunSMS struct {
// contains filtered or unexported fields
}
AliyunSMS represents Aliyun SMS notification
func NewAliyunSMS ¶
func NewAliyunSMS(cfg AliyunSMSConfig, cli AliyunSMSClient) *AliyunSMS
NewAliyunSMS creates a new Aliyun SMS notification instance
func (*AliyunSMS) Send ¶
func (a *AliyunSMS) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification via SMS
func (*AliyunSMS) Type ¶
func (a *AliyunSMS) Type() NotificationType
Type returns the notification type
type AliyunSMSClient ¶
type AliyunSMSClient interface {
Send(ctx context.Context, phone, sign, template string, params map[string]string) error
}
AliyunSMSClient is the interface for sending SMS (for dependency injection)
type AliyunSMSConfig ¶
type DingTalkConfig ¶
type DingTalkConfig struct {
WebhookURL string // DingTalk webhook URL
Secret string // DingTalk webhook secret (optional)
}
DingTalkConfig represents DingTalk webhook configuration
type DingTalkNotification ¶
type DingTalkNotification struct {
// contains filtered or unexported fields
}
DingTalkNotification implements DingTalk notification
func NewDingTalkNotification ¶
func NewDingTalkNotification(config DingTalkConfig) *DingTalkNotification
NewDingTalkNotification creates a new DingTalk notification instance
func (*DingTalkNotification) Send ¶
func (d *DingTalkNotification) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification via DingTalk
func (*DingTalkNotification) SendMarkdown ¶
func (d *DingTalkNotification) SendMarkdown(ctx context.Context, title, content string) error
SendMarkdown sends a markdown message to DingTalk
func (*DingTalkNotification) SendText ¶
func (d *DingTalkNotification) SendText(ctx context.Context, content string) error
SendText sends a text message to DingTalk
func (*DingTalkNotification) Type ¶
func (d *DingTalkNotification) Type() NotificationType
Type returns the notification type
type FeishuConfig ¶
type FeishuConfig struct {
WebhookURL string // Feishu webhook URL
Secret string // Feishu webhook secret (optional)
}
FeishuConfig represents Feishu webhook configuration
type FeishuNotification ¶
type FeishuNotification struct {
// contains filtered or unexported fields
}
FeishuNotification implements Feishu notification
func NewFeishuNotification ¶
func NewFeishuNotification(config FeishuConfig) *FeishuNotification
NewFeishuNotification creates a new Feishu notification instance
func (*FeishuNotification) Send ¶
func (f *FeishuNotification) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification via Feishu
func (*FeishuNotification) SendRichText ¶
func (f *FeishuNotification) SendRichText(ctx context.Context, title, content string) error
SendRichText sends a rich text message to Feishu
func (*FeishuNotification) SendText ¶
func (f *FeishuNotification) SendText(ctx context.Context, content string) error
SendText sends a text message to Feishu
func (*FeishuNotification) Type ¶
func (f *FeishuNotification) Type() NotificationType
Type returns the notification type
type InternalNotification ¶
type InternalNotification struct {
ID uint `json:"id" gorm:"primaryKey"` // 通知 ID
UserID uint `json:"user_id"` // 用户 ID
Title string `json:"title"` // 通知标题
Content string `json:"content"` // 通知内容
Read bool `json:"read"` // 是否已读
CreatedAt time.Time `json:"created_at"` // 创建时间
}
InternalNotification 站内通知
type InternalNotificationAdapter ¶
type InternalNotificationAdapter struct {
// contains filtered or unexported fields
}
InternalNotificationAdapter adapts InternalNotificationService to Notification interface
func NewInternalNotificationAdapter ¶
func NewInternalNotificationAdapter(service *InternalNotificationService) *InternalNotificationAdapter
NewInternalNotificationAdapter creates a new internal notification adapter
func (*InternalNotificationAdapter) Send ¶
func (i *InternalNotificationAdapter) Send(ctx context.Context, req NotificationRequest) error
Send sends an internal notification
func (*InternalNotificationAdapter) Type ¶
func (i *InternalNotificationAdapter) Type() NotificationType
Type returns the notification type
type InternalNotificationService ¶
InternalNotificationService 站内通知服务
func NewInternalNotificationService ¶
func NewInternalNotificationService(db *gorm.DB) *InternalNotificationService
NewInternalNotificationService 创建站内通知服务实例
func (*InternalNotificationService) BatchDelete ¶
func (s *InternalNotificationService) BatchDelete(userID uint, notificationIDs []uint) (int64, error)
BatchDelete 批量删除通知
func (*InternalNotificationService) Delete ¶
func (s *InternalNotificationService) Delete(userID uint, notificationID uint) error
func (*InternalNotificationService) GetOne ¶
func (s *InternalNotificationService) GetOne(userID uint, notificationID uint) (InternalNotification, error)
func (*InternalNotificationService) GetPaginatedNotifications ¶
func (s *InternalNotificationService) GetPaginatedNotifications( userID uint, page, size int, filter string, titleKeyword, contentKeyword string, startTime, endTime time.Time, ) ([]InternalNotification, int64, int64, int64, error)
GetPaginatedNotifications 获取用户的分页通知,扩展返回未读和已读总数
func (*InternalNotificationService) GetUnreadNotifications ¶
func (s *InternalNotificationService) GetUnreadNotifications(userID uint) ([]InternalNotification, error)
GetUnreadNotifications 获取用户的未读通知
func (*InternalNotificationService) GetUnreadNotificationsCount ¶
func (s *InternalNotificationService) GetUnreadNotificationsCount(userID uint) (count int64, err error)
func (*InternalNotificationService) MarkAllAsRead ¶
func (s *InternalNotificationService) MarkAllAsRead(userID uint) error
MarkAsRead 将通知标记为已读
func (*InternalNotificationService) MarkAsRead ¶
func (s *InternalNotificationService) MarkAsRead(notificationID uint) error
MarkAsRead 将通知标记为已读
type JPush ¶
type JPush struct {
// contains filtered or unexported fields
}
JPush represents JPush notification
func NewJPush ¶
func NewJPush(cfg JPushConfig, cli JPushClient) *JPush
NewJPush creates a new JPush notification instance
func (*JPush) PushToAlias ¶
func (j *JPush) PushToAlias(ctx context.Context, alias []string, title, content string, extras map[string]interface{}) error
PushToAlias pushes notification to specific aliases
func (*JPush) PushToAll ¶
func (j *JPush) PushToAll(ctx context.Context, title, content string, extras map[string]interface{}) error
PushToAll pushes notification to all users
type JPushClient ¶
type JPushConfig ¶
type MailConfig ¶
type MailConfig struct {
Host string `json:"host"` // SMTP 服务器地址
Port int64 `json:"port"` // SMTP 服务器端口
Username string `json:"username"` // SMTP 用户名
Password string `json:"password"` // SMTP 密码
From string `json:"from"` // 发件人邮箱
}
MailConfig 邮件配置
type MailNotification ¶
type MailNotification struct {
Config MailConfig
}
MailNotification represents email notification
func NewMailNotification ¶
func NewMailNotification(config MailConfig) *MailNotification
NewMailNotification creates a new email notification instance
func (*MailNotification) Send ¶
func (m *MailNotification) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification via email
func (*MailNotification) SendGroupInvitationEmail ¶
func (m *MailNotification) SendGroupInvitationEmail(to, inviteeName, inviterName, groupName, groupType, groupDescription, acceptURL string) error
SendGroupInvitationEmail 发送组织邀请邮件
func (*MailNotification) SendHTML ¶
func (m *MailNotification) SendHTML(to, subject, htmlBody string) error
func (*MailNotification) SendPasswordResetEmail ¶
func (m *MailNotification) SendPasswordResetEmail(to, username, resetURL string) error
SendPasswordResetEmail 发送密码重置邮件
func (*MailNotification) SendPlain ¶
func (m *MailNotification) SendPlain(to, subject, body string) error
SendPlain sends a plain text email (legacy method)
func (*MailNotification) SendVerificationCode ¶
func (m *MailNotification) SendVerificationCode(to, code string) error
func (*MailNotification) SendVerificationEmail ¶
func (m *MailNotification) SendVerificationEmail(to, username, verifyURL string) error
SendVerificationEmail 发送邮箱验证邮件
func (*MailNotification) SendWelcomeEmail ¶
func (m *MailNotification) SendWelcomeEmail(to string, username string, verifyURL string) error
SendHTML sends an HTML email using the embedded welcome template
func (*MailNotification) Type ¶
func (m *MailNotification) Type() NotificationType
Type returns the notification type
type Notification ¶
type Notification interface {
// Send sends a notification
Send(ctx context.Context, req NotificationRequest) error
// Type returns the notification type
Type() NotificationType
}
Notification is the unified notification interface
type NotificationManager ¶
type NotificationManager struct {
// contains filtered or unexported fields
}
NotificationManager manages multiple notification channels
func NewNotificationManager ¶
func NewNotificationManager() *NotificationManager
NewNotificationManager creates a new notification manager
func (*NotificationManager) Register ¶
func (nm *NotificationManager) Register(notif Notification)
Register registers a notification handlers
func (*NotificationManager) Send ¶
func (nm *NotificationManager) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification using the appropriate handlers
func (*NotificationManager) SendMultiple ¶
func (nm *NotificationManager) SendMultiple(ctx context.Context, reqs []NotificationRequest) []error
SendMultiple sends notifications to multiple channels
type NotificationRequest ¶
type NotificationRequest struct {
Type NotificationType // Notification type
Title string // Notification title
Content string // Notification content
To []string // Recipients (email addresses, phone numbers, user IDs, etc.)
Extras map[string]interface{} // Extra data for specific notification types
Context context.Context // Context for cancellation/timeout
}
NotificationRequest represents a unified notification request
type NotificationType ¶
type NotificationType string
NotificationType represents the type of notification
const ( TypeInternal NotificationType = "internal" // Internal notification (in-app) TypeEmail NotificationType = "email" // Email notification TypeSMS NotificationType = "sms" // SMS notification TypePush NotificationType = "push" // Push notification (JPush, etc.) TypeDingTalk NotificationType = "dingtalk" // DingTalk notification TypeWeChat NotificationType = "wechat" // WeChat Work notification TypeFeishu NotificationType = "feishu" // Feishu notification )
type WeChatWorkConfig ¶
type WeChatWorkConfig struct {
CorpID string // Enterprise ID
AgentID string // Application ID
Secret string // Application Secret
}
WeChatWorkConfig represents WeChat Work configuration
type WeChatWorkNotification ¶
type WeChatWorkNotification struct {
// contains filtered or unexported fields
}
WeChatWorkNotification implements WeChat Work notification
func NewWeChatWorkNotification ¶
func NewWeChatWorkNotification(config WeChatWorkConfig) *WeChatWorkNotification
NewWeChatWorkNotification creates a new WeChat Work notification instance
func (*WeChatWorkNotification) Send ¶
func (w *WeChatWorkNotification) Send(ctx context.Context, req NotificationRequest) error
Send sends a notification via WeChat Work
func (*WeChatWorkNotification) Type ¶
func (w *WeChatWorkNotification) Type() NotificationType
Type returns the notification type