Documentation
¶
Index ¶
- Constants
- func CreateBatchSendNotificationTask(requests []*SendRequest, metadata map[string]interface{}) (*asynq.Task, error)
- func CreateRetryFailedNotificationTask(request *SendRequest, originalMessageID string, retryCount int, ...) (*asynq.Task, error)
- func CreateScheduledNotificationTask(request *SendRequest, scheduledAt time.Time, scheduleType string, ...) (*asynq.Task, error)
- func CreateSendNotificationTask(request *SendRequest, metadata map[string]interface{}) (*asynq.Task, error)
- func FormatPriority(priority int8) string
- func FormatPriorityIcon(priority int8) string
- func GetEventTypeIcon(eventType string) string
- func GetEventTypeText(eventType string) string
- func RenderTemplate(content string, request *SendRequest) (string, error)
- type Attachment
- type BaseChannelConfig
- type BatchSendNotificationPayload
- type ChannelConfig
- type EmailChannel
- func (e *EmailChannel) GetMaxRetries() int
- func (e *EmailChannel) GetName() string
- func (e *EmailChannel) GetRetryInterval() time.Duration
- func (e *EmailChannel) IsEnabled() bool
- func (e *EmailChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)
- func (e *EmailChannel) Validate() error
- type EmailConfig
- type FeishuChannel
- func (f *FeishuChannel) GetMaxRetries() int
- func (f *FeishuChannel) GetName() string
- func (f *FeishuChannel) GetRetryInterval() time.Duration
- func (f *FeishuChannel) IsEnabled() bool
- func (f *FeishuChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)
- func (f *FeishuChannel) Validate() error
- type FeishuConfig
- type Manager
- func (m *Manager) BatchSendNotification(ctx context.Context, requests []*SendRequest) ([]*SendResponse, error)
- func (m *Manager) Close() error
- func (m *Manager) GetAvailableChannels() []string
- func (m *Manager) GetChannelStats() map[string]interface{}
- func (m *Manager) ProcessNotificationTask(ctx context.Context, task *asynq.Task) error
- func (m *Manager) ReloadChannel(channelName string) error
- func (m *Manager) SendNotification(ctx context.Context, request *SendRequest) (*SendResponse, error)
- func (m *Manager) SendNotificationAsync(ctx context.Context, request *SendRequest, delay time.Duration) error
- func (m *Manager) ValidateChannelConfig(channelName string) error
- type NotificationChannel
- type NotificationConfig
- type Processor
- func (p *Processor) HandleBatchSendNotification(ctx context.Context, task *asynq.Task) error
- func (p *Processor) HandleRetryFailedNotification(ctx context.Context, task *asynq.Task) error
- func (p *Processor) HandleScheduledNotification(ctx context.Context, task *asynq.Task) error
- func (p *Processor) HandleSendNotification(ctx context.Context, task *asynq.Task) error
- func (p *Processor) RegisterTasks(mux *asynq.ServeMux)
- type RetryFailedNotificationPayload
- type ScheduledNotificationPayload
- type SendNotificationPayload
- type SendRequest
- type SendResponse
Constants ¶
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)
CreateBatchSendNotificationTask 创建批量发送通知任务
func CreateRetryFailedNotificationTask ¶
func CreateRetryFailedNotificationTask(request *SendRequest, originalMessageID string, retryCount int, lastError string, metadata map[string]interface{}) (*asynq.Task, error)
CreateRetryFailedNotificationTask 创建重试失败通知任务
func CreateScheduledNotificationTask ¶
func CreateScheduledNotificationTask(request *SendRequest, scheduledAt time.Time, scheduleType string, metadata map[string]interface{}) (*asynq.Task, error)
CreateScheduledNotificationTask 创建定时通知任务
func CreateSendNotificationTask ¶
func CreateSendNotificationTask(request *SendRequest, metadata map[string]interface{}) (*asynq.Task, error)
CreateSendNotificationTask 创建发送通知任务
func FormatPriorityIcon ¶
FormatPriorityIcon 获取优先级对应的图标
func RenderTemplate ¶
func RenderTemplate(content string, request *SendRequest) (string, error)
RenderTemplate 渲染模板内容
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"` // 超时时间
}
BaseChannelConfig 基础渠道配置
func (*BaseChannelConfig) GetMaxRetries ¶
func (c *BaseChannelConfig) GetMaxRetries() int
GetMaxRetries 获取最大重试次数
func (*BaseChannelConfig) GetRetryInterval ¶
func (c *BaseChannelConfig) GetRetryInterval() time.Duration
GetRetryInterval 获取重试间隔
func (*BaseChannelConfig) GetTimeout ¶
func (c *BaseChannelConfig) GetTimeout() time.Duration
GetTimeout 获取超时时间
type BatchSendNotificationPayload ¶
type BatchSendNotificationPayload struct {
Requests []*SendRequest `json:"requests"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
BatchSendNotificationPayload 批量发送通知任务载荷
type ChannelConfig ¶
ChannelConfig 渠道配置接口
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
GetMaxRetries 获取最大重试次数
func (*EmailChannel) GetName ¶
func (e *EmailChannel) GetName() string
func (*EmailChannel) GetRetryInterval ¶
func (e *EmailChannel) GetRetryInterval() time.Duration
GetRetryInterval 获取重试间隔
func (*EmailChannel) Send ¶
func (e *EmailChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)
Send 发送邮件通知到指定收件人
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
}
EmailConfig 邮箱配置
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
GetMaxRetries 获取最大重试次数
func (*FeishuChannel) GetName ¶
func (f *FeishuChannel) GetName() string
func (*FeishuChannel) GetRetryInterval ¶
func (f *FeishuChannel) GetRetryInterval() time.Duration
GetRetryInterval 获取重试间隔时间
func (*FeishuChannel) Send ¶
func (f *FeishuChannel) Send(ctx context.Context, request *SendRequest) (*SendResponse, error)
Send 发送飞书消息到指定接收人
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
}
FeishuConfig 飞书配置
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) BatchSendNotification ¶
func (m *Manager) BatchSendNotification(ctx context.Context, requests []*SendRequest) ([]*SendResponse, error)
BatchSendNotification 批量发送通知
func (*Manager) GetAvailableChannels ¶
GetAvailableChannels 获取所有可用通知渠道
func (*Manager) GetChannelStats ¶
GetChannelStats 获取渠道统计信息
func (*Manager) ProcessNotificationTask ¶
ProcessNotificationTask 处理通知队列任务
func (*Manager) ReloadChannel ¶
ReloadChannel 重新加载指定渠道
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 ¶
ValidateChannelConfig 验证指定渠道配置
type NotificationChannel ¶
type NotificationChannel interface {
// GetName 获取渠道名称
GetName() string
// Send 发送通知
Send(ctx context.Context, request *SendRequest) (*SendResponse, error)
// Validate 验证配置
Validate() error
// IsEnabled 是否启用
IsEnabled() bool
// GetMaxRetries 获取最大重试次数
GetMaxRetries() int
// GetRetryInterval 获取重试间隔
GetRetryInterval() time.Duration
}
NotificationChannel 通知渠道接口
type NotificationConfig ¶
type NotificationConfig interface {
GetEmail() EmailConfig
GetFeishu() FeishuConfig
}
NotificationConfig 通知配置
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor 通知任务处理器
func (*Processor) HandleBatchSendNotification ¶
HandleBatchSendNotification 处理批量通知发送任务
func (*Processor) HandleRetryFailedNotification ¶
HandleRetryFailedNotification 处理重试失败的通知任务
func (*Processor) HandleScheduledNotification ¶
HandleScheduledNotification 处理定时通知任务
func (*Processor) HandleSendNotification ¶
HandleSendNotification 处理单个通知发送任务
func (*Processor) RegisterTasks ¶
RegisterTasks 注册任务处理器
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"`
}
RetryFailedNotificationPayload 重试失败通知任务载荷
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"`
}
ScheduledNotificationPayload 定时通知任务载荷
type SendNotificationPayload ¶
type SendNotificationPayload struct {
Request *SendRequest `json:"request"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
SendNotificationPayload 发送通知任务载荷
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"` // 附件
}
SendRequest 发送请求
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"` // 响应数据
}
SendResponse 发送响应