notification

package
v0.0.0-...-0409f2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func TestMailNotification_SendGroupInvitationEmail

func TestMailNotification_SendGroupInvitationEmail(t *testing.T)

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

Send sends a notification via SMS

func (*AliyunSMS) SendCode

func (a *AliyunSMS) SendCode(ctx context.Context, phone, code string) error

SendCode sends a verification code 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 AliyunSMSConfig struct {
	AccessKeyId     string
	AccessKeySecret string
	SignName        string
	TemplateCode    string
	Endpoint        string // 默认 cn-hangzhou
}

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

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

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

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

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

Send sends an internal notification

func (*InternalNotificationAdapter) Type

Type returns the notification type

type InternalNotificationService

type InternalNotificationService struct {
	DB *gorm.DB // 数据库实例
}

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 将通知标记为已读

func (*InternalNotificationService) Send

func (s *InternalNotificationService) Send(userID uint, title, content string) error

Send 发送站内通知

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

func (*JPush) Send

func (j *JPush) Send(ctx context.Context, req NotificationRequest) error

Send sends a notification via JPush

func (*JPush) Type

func (j *JPush) Type() NotificationType

Type returns the notification type

type JPushClient

type JPushClient interface {
	Push(ctx context.Context, title, content string, audience map[string]interface{}, extras map[string]interface{}) error
}

type JPushConfig

type JPushConfig struct {
	AppKey       string
	MasterSecret string
}

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

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

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

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

Send sends a notification via WeChat Work

func (*WeChatWorkNotification) Type

Type returns the notification type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL