notification

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeishuIDTypeOpenID  = "open_id"
	FeishuIDTypeUserID  = "user_id"
	FeishuIDTypeChatID  = "chat_id"
	FeishuIDTypeEmail   = "email"
	FeishuIDTypeUnionID = "union_id"
)

飞书ID类型枚举

Variables

This section is empty.

Functions

func CreateBatchSendNotificationTask

func CreateBatchSendNotificationTask(requests []*SendRequest, metadata map[string]interface{}) (*asynq.Task, error)

func CreateRetryFailedNotificationTask

func CreateRetryFailedNotificationTask(request *SendRequest, originalMessageID string, retryCount int, lastError string, metadata map[string]interface{}) (*asynq.Task, error)

func CreateScheduledNotificationTask

func CreateScheduledNotificationTask(request *SendRequest, scheduledAt time.Time, scheduleType string, metadata map[string]interface{}) (*asynq.Task, error)

func CreateSendNotificationTask

func CreateSendNotificationTask(request *SendRequest, metadata map[string]interface{}) (*asynq.Task, error)

func FormatPriority

func FormatPriority(priority int8) string

FormatPriority 将优先级数字转为文本表示

func FormatPriorityIcon

func FormatPriorityIcon(priority int8) string

func GetEventTypeIcon

func GetEventTypeIcon(eventType string) string

func GetEventTypeText

func GetEventTypeText(eventType string) string

func RenderTemplate

func RenderTemplate(content string, request *SendRequest) (string, error)

Types

type Attachment

type Attachment struct {
	Name        string `json:"name"`         // 附件名称
	Content     []byte `json:"content"`      // 附件内容
	ContentType string `json:"content_type"` // 内容类型
	Size        int64  `json:"size"`         // 大小
}

Attachment 附件

type BaseChannelConfig

type BaseChannelConfig struct {
	Enabled       bool          `json:"enabled" yaml:"enabled"`               // 是否启用
	MaxRetries    int           `json:"max_retries" yaml:"max_retries"`       // 最大重试次数
	RetryInterval time.Duration `json:"retry_interval" yaml:"retry_interval"` // 重试间隔
	Timeout       time.Duration `json:"timeout" yaml:"timeout"`               // 超时时间
}

func (*BaseChannelConfig) GetMaxRetries

func (c *BaseChannelConfig) GetMaxRetries() int

func (*BaseChannelConfig) GetRetryInterval

func (c *BaseChannelConfig) GetRetryInterval() time.Duration

func (*BaseChannelConfig) GetTimeout

func (c *BaseChannelConfig) GetTimeout() time.Duration

func (*BaseChannelConfig) IsEnabled

func (c *BaseChannelConfig) IsEnabled() bool

IsEnabled 是否启用

type BatchSendNotificationPayload

type BatchSendNotificationPayload struct {
	Requests  []*SendRequest         `json:"requests"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

type ChannelConfig

type ChannelConfig interface {
	GetChannelName() string
	Validate() error
}

type EmailChannel

type EmailChannel struct {
	// contains filtered or unexported fields
}

func NewEmailChannel

func NewEmailChannel(config EmailConfig, logger *zap.Logger) *EmailChannel

func (*EmailChannel) GetMaxRetries

func (e *EmailChannel) GetMaxRetries() int

func (*EmailChannel) GetName

func (e *EmailChannel) GetName() string

func (*EmailChannel) GetRetryInterval

func (e *EmailChannel) GetRetryInterval() time.Duration

func (*EmailChannel) IsEnabled

func (e *EmailChannel) IsEnabled() bool

func (*EmailChannel) Send

func (e *EmailChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)

Send 发送邮件通知到指定收件人

func (*EmailChannel) Validate

func (e *EmailChannel) Validate() error

type EmailConfig

type EmailConfig interface {
	IsEnabled() bool
	GetMaxRetries() int
	GetRetryInterval() time.Duration
	GetTimeout() time.Duration
	GetChannelName() string
	Validate() error
	GetSMTPHost() string
	GetSMTPPort() int
	GetUsername() string
	GetPassword() string
	GetFromName() string
	GetUseTLS() bool
}

type FeishuChannel

type FeishuChannel struct {
	// contains filtered or unexported fields
}

func NewFeishuChannel

func NewFeishuChannel(config FeishuConfig, logger *zap.Logger) *FeishuChannel

func (*FeishuChannel) GetMaxRetries

func (f *FeishuChannel) GetMaxRetries() int

func (*FeishuChannel) GetName

func (f *FeishuChannel) GetName() string

func (*FeishuChannel) GetRetryInterval

func (f *FeishuChannel) GetRetryInterval() time.Duration

func (*FeishuChannel) IsEnabled

func (f *FeishuChannel) IsEnabled() bool

func (*FeishuChannel) Send

func (f *FeishuChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)

Send 发送飞书消息到指定接收人

func (*FeishuChannel) Validate

func (f *FeishuChannel) Validate() error

type FeishuConfig

type FeishuConfig interface {
	IsEnabled() bool
	GetMaxRetries() int
	GetRetryInterval() time.Duration
	GetTimeout() time.Duration
	GetChannelName() string
	Validate() error
	GetAppID() string
	GetAppSecret() string
	GetWebhookURL() string
	GetPrivateMessageAPI() string
	GetTenantAccessTokenAPI() string
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(config NotificationConfig, queueClient *asynq.Client, logger *zap.Logger) (*Manager, error)

func (*Manager) BatchSendNotification

func (m *Manager) BatchSendNotification(ctx context.Context, requests []*SendRequest) ([]*SendResponse, error)

BatchSendNotification 批量发送通知

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) GetAvailableChannels

func (m *Manager) GetAvailableChannels() []string

func (*Manager) GetChannelStats

func (m *Manager) GetChannelStats() map[string]interface{}

func (*Manager) ProcessNotificationTask

func (m *Manager) ProcessNotificationTask(ctx context.Context, task *asynq.Task) error

func (*Manager) ReloadChannel

func (m *Manager) ReloadChannel(channelName string) error

func (*Manager) SendNotification

func (m *Manager) SendNotification(ctx context.Context, request *SendRequest) (*SendResponse, error)

SendNotification 同步发送通知消息

func (*Manager) SendNotificationAsync

func (m *Manager) SendNotificationAsync(ctx context.Context, request *SendRequest, delay time.Duration) error

SendNotificationAsync 异步发送通知消息

func (*Manager) ValidateChannelConfig

func (m *Manager) ValidateChannelConfig(channelName string) error

type NotificationChannel

type NotificationChannel interface {
	GetName() string

	// Send 发送通知
	Send(ctx context.Context, request *SendRequest) (*SendResponse, error)

	Validate() error

	// IsEnabled 是否启用
	IsEnabled() bool

	GetMaxRetries() int

	GetRetryInterval() time.Duration
}

NotificationChannel 通知渠道接口

type NotificationConfig

type NotificationConfig interface {
	GetEmail() EmailConfig
	GetFeishu() FeishuConfig
}

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(manager *Manager, logger *zap.Logger) *Processor

func (*Processor) HandleBatchSendNotification

func (p *Processor) HandleBatchSendNotification(ctx context.Context, task *asynq.Task) error

func (*Processor) HandleRetryFailedNotification

func (p *Processor) HandleRetryFailedNotification(ctx context.Context, task *asynq.Task) error

func (*Processor) HandleScheduledNotification

func (p *Processor) HandleScheduledNotification(ctx context.Context, task *asynq.Task) error

func (*Processor) HandleSendNotification

func (p *Processor) HandleSendNotification(ctx context.Context, task *asynq.Task) error

func (*Processor) RegisterTasks

func (p *Processor) RegisterTasks(mux *asynq.ServeMux)

type RetryFailedNotificationPayload

type RetryFailedNotificationPayload struct {
	Request           *SendRequest           `json:"request"`
	OriginalMessageID string                 `json:"original_message_id"`
	RetryCount        int                    `json:"retry_count"`
	LastError         string                 `json:"last_error"`
	Metadata          map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt         time.Time              `json:"created_at"`
}

type ScheduledNotificationPayload

type ScheduledNotificationPayload struct {
	Request      *SendRequest           `json:"request"`
	ScheduledAt  time.Time              `json:"scheduled_at"`
	ScheduleType string                 `json:"schedule_type"` // once, daily, weekly, monthly
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt    time.Time              `json:"created_at"`
}

type SendNotificationPayload

type SendNotificationPayload struct {
	Request   *SendRequest           `json:"request"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

type SendRequest

type SendRequest struct {
	MessageID string `json:"message_id"` // 消息ID
	Subject   string `json:"subject"`    // 主题
	Content   string `json:"content"`    // 内容
	Priority  int8   `json:"priority"`   // 优先级 1-高 2-中 3-低

	RecipientType string `json:"recipient_type"` // 接收人类型
	RecipientID   string `json:"recipient_id"`   // 接收人ID
	RecipientAddr string `json:"recipient_addr"` // 接收人地址(邮箱/手机号等)
	RecipientName string `json:"recipient_name"` // 接收人名称

	// 工单相关
	InstanceID *int   `json:"instance_id,omitempty"` // 工单实例ID
	EventType  string `json:"event_type"`            // 事件类型

	Metadata    map[string]interface{} `json:"metadata,omitempty"`    // 元数据
	Templates   map[string]string      `json:"templates,omitempty"`   // 模板变量
	Attachments []Attachment           `json:"attachments,omitempty"` // 附件
}

type SendResponse

type SendResponse struct {
	Success      bool                   `json:"success"`                 // 是否成功
	MessageID    string                 `json:"message_id"`              // 消息ID
	ExternalID   string                 `json:"external_id"`             // 外部系统消息ID
	Status       string                 `json:"status"`                  // 状态
	ErrorMessage string                 `json:"error_message"`           // 错误信息
	Cost         *float64               `json:"cost,omitempty"`          // 发送成本
	SendTime     time.Time              `json:"send_time"`               // 发送时间
	ResponseData map[string]interface{} `json:"response_data,omitempty"` // 响应数据
}

Jump to

Keyboard shortcuts

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