You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.2 KiB
Go

package app
import (
"joybuywork/internal/config"
"fmt"
"gits.branchcn.com/backend/microcode/plugins/alert"
)
var FeiShu alert.Plugin
func InitFeiShu() (err error) {
if config.Config.Alert.FeiShu.Url != "" {
alertConfig := alert.PluginConfig{
Type: alert.PluginConfigTypeFeiShu,
Url: config.Config.Alert.FeiShu.Url,
Secret: config.Config.Alert.FeiShu.Secret,
}
for _, v := range config.Config.Alert.Scenes {
alertConfig.Scenes = append(alertConfig.Scenes, &alert.Conf{
Type: alert.PluginConfigTypeFeiShu,
Url: v.Url,
Secret: v.Secret,
Scene: v.Scene,
})
}
FeiShu, err = alert.NewPlugin(alertConfig)
}
return
}
const (
normal = "normal"
notice = "notice"
)
// FeishuNormalSend 发送普通消息,这个给自己监听用的
func FeishuNormalSend(format string, a ...any) {
h, ok := FeiShu.Scenes[normal]
if !ok {
return
}
if len(a) > 0 {
h.SendText(fmt.Sprintf(format, a...))
return
}
h.SendText(format)
}
// FeishuNoticeSend 发送通知消息,这个是一些业务通知用的
func FeishuNoticeSend(format string, a ...any) {
h, ok := FeiShu.Scenes[notice]
if !ok {
return
}
if len(a) > 0 {
h.SendText(fmt.Sprintf(format, a...))
return
}
h.SendText(format)
}