117 lines
3.6 KiB
Go
117 lines
3.6 KiB
Go
package notice
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
type Channel string
|
|
|
|
const (
|
|
ChannelFeishu Channel = "feishu"
|
|
ChannelDingTalk Channel = "dingtalk"
|
|
ChannelWeCom Channel = "wecom"
|
|
ChannelWebhook Channel = "webhook"
|
|
)
|
|
|
|
type MessageType string
|
|
|
|
const (
|
|
MessageText MessageType = "text"
|
|
MessageColorText MessageType = "color_text"
|
|
MessageMarkdown MessageType = "markdown"
|
|
MessageCard MessageType = "card"
|
|
)
|
|
|
|
type Color string
|
|
|
|
const (
|
|
ColorDefault Color = "default"
|
|
ColorInfo Color = "info"
|
|
ColorSuccess Color = "success"
|
|
ColorWarning Color = "warning"
|
|
ColorDanger Color = "danger"
|
|
ColorMuted Color = "muted"
|
|
)
|
|
|
|
type CardTheme string
|
|
|
|
const (
|
|
CardThemeDefault CardTheme = "default"
|
|
CardThemeBlue CardTheme = "blue"
|
|
CardThemeWathet CardTheme = "wathet"
|
|
CardThemeTurquoise CardTheme = "turquoise"
|
|
CardThemeGreen CardTheme = "green"
|
|
CardThemeYellow CardTheme = "yellow"
|
|
CardThemeOrange CardTheme = "orange"
|
|
CardThemeRed CardTheme = "red"
|
|
CardThemeCarmine CardTheme = "carmine"
|
|
CardThemeViolet CardTheme = "violet"
|
|
CardThemePurple CardTheme = "purple"
|
|
CardThemeIndigo CardTheme = "indigo"
|
|
CardThemeGrey CardTheme = "grey"
|
|
)
|
|
|
|
type Message struct {
|
|
Type MessageType `json:"type" dc:"消息类型"`
|
|
Title string `json:"title,omitempty" dc:"消息标题"`
|
|
Content string `json:"content,omitempty" dc:"文本或 Markdown 消息正文"`
|
|
Segments []TextSegment `json:"segments,omitempty" dc:"带颜色文本片段列表"`
|
|
Card *CardContent `json:"card,omitempty" dc:"卡片消息内容"`
|
|
}
|
|
|
|
type TextSegment struct {
|
|
Text string `json:"text" dc:"文本内容"`
|
|
Color Color `json:"color,omitempty" dc:"文本语义颜色"`
|
|
Bold bool `json:"bold,omitempty" dc:"是否加粗显示"`
|
|
}
|
|
|
|
type CardContent struct {
|
|
Title string `json:"title,omitempty" dc:"卡片标题"`
|
|
Theme CardTheme `json:"theme,omitempty" dc:"卡片主题,飞书映射为 Header template"`
|
|
Markdown string `json:"markdown,omitempty" dc:"卡片 Markdown 正文"`
|
|
Fields []CardField `json:"fields,omitempty" dc:"卡片字段列表"`
|
|
Actions []CardAction `json:"actions,omitempty" dc:"卡片跳转操作列表"`
|
|
}
|
|
|
|
type CardField struct {
|
|
Name string `json:"name" dc:"字段名称"`
|
|
Value string `json:"value" dc:"字段值"`
|
|
}
|
|
|
|
type CardAction struct {
|
|
Text string `json:"text" dc:"操作按钮文案"`
|
|
URL string `json:"url" dc:"操作跳转地址"`
|
|
}
|
|
|
|
type Config struct {
|
|
Webhook string `json:"webhook" dc:"机器人 Webhook 地址"`
|
|
Security *SecurityConfig `json:"security,omitempty" dc:"当前机器人独立安全校验配置"`
|
|
Timeout time.Duration `json:"timeout,omitempty" dc:"HTTP 请求超时时间"`
|
|
}
|
|
|
|
type SecurityConfig struct {
|
|
SignEnabled bool `json:"sign_enabled" dc:"是否启用机器人签名校验"`
|
|
SignSecret string `json:"sign_secret,omitempty" dc:"机器人签名校验密钥"`
|
|
}
|
|
|
|
type ZapConfig struct {
|
|
Channels []Channel `json:"channels" dc:"接收日志通知的消息渠道列表"`
|
|
Levels []zapcore.Level `json:"levels,omitempty" dc:"触发消息发送的 Zap 日志等级列表,空值默认 warn 和 error"`
|
|
OnError func(error) `json:"-" dc:"异步消息发送失败时的处理函数"`
|
|
}
|
|
|
|
type Capabilities struct {
|
|
Text bool `json:"text" dc:"是否支持普通文本"`
|
|
ColorText bool `json:"color_text" dc:"是否支持带颜色文本"`
|
|
Markdown bool `json:"markdown" dc:"是否支持 Markdown"`
|
|
Card bool `json:"card" dc:"是否支持卡片消息"`
|
|
}
|
|
|
|
type Sender interface {
|
|
Send(ctx context.Context, message Message) error
|
|
SendAsync(ctx context.Context, message Message) <-chan error
|
|
}
|