notification

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 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)

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 FormatPriority

func FormatPriority(priority int8) string

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

func FormatPriorityIcon

func FormatPriorityIcon(priority int8) string

FormatPriorityIcon 获取优先级对应的图标

func GetEventTypeIcon

func GetEventTypeIcon(eventType string) string

GetEventTypeIcon 获取事件类型对应的图标

func GetEventTypeText

func GetEventTypeText(eventType string) string

GetEventTypeText 获取事件类型的文本描述

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 获取超时时间

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"`
}

BatchSendNotificationPayload 批量发送通知任务载荷

type ChannelConfig

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

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) IsEnabled

func (e *EmailChannel) IsEnabled() bool

IsEnabled 检查通道是否启用

func (*EmailChannel) Send

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

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

func (*EmailChannel) Validate

func (e *EmailChannel) Validate() error

Validate 验证邮件通道配置有效性

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) IsEnabled

func (f *FeishuChannel) IsEnabled() bool

IsEnabled 检查通道是否启用

func (*FeishuChannel) Send

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

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

func (*FeishuChannel) Validate

func (f *FeishuChannel) Validate() error

Validate 验证飞书配置有效性

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

Close 关闭管理器资源

func (*Manager) GetAvailableChannels

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

GetAvailableChannels 获取所有可用通知渠道

func (*Manager) GetChannelStats

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

GetChannelStats 获取渠道统计信息

func (*Manager) ProcessNotificationTask

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

ProcessNotificationTask 处理通知队列任务

func (*Manager) ReloadChannel

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

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

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

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 NewProcessor

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

func (*Processor) HandleBatchSendNotification

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

HandleBatchSendNotification 处理批量通知发送任务

func (*Processor) HandleRetryFailedNotification

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

HandleRetryFailedNotification 处理重试失败的通知任务

func (*Processor) HandleScheduledNotification

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

HandleScheduledNotification 处理定时通知任务

func (*Processor) HandleSendNotification

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

HandleSendNotification 处理单个通知发送任务

func (*Processor) RegisterTasks

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

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 发送响应

Jump to

Keyboard shortcuts

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