feat: add feishu and aliyunsms
This commit is contained in:
@@ -21,6 +21,7 @@ const (
|
||||
MessageTypeEmail = channels.MessageTypeEmail
|
||||
MessageTypeDtalk = channels.MessageTypeDtalk
|
||||
MessageTypeQyWeiXin = channels.MessageTypeQyWeiXin
|
||||
MessageTypeFeishu = channels.MessageTypeFeishu
|
||||
MessageTypeCustom = channels.MessageTypeCustom
|
||||
MessageTypeWeChatOFAccount = channels.MessageTypeWeChatOFAccount
|
||||
MessageTypeMessageNest = channels.MessageTypeMessageNest
|
||||
@@ -93,6 +94,7 @@ func GetGlobalChannelRegistry() *ChannelRegistry {
|
||||
globalChannelRegistry.Register(channels.NewEmailChannel())
|
||||
globalChannelRegistry.Register(channels.NewDtalkChannel())
|
||||
globalChannelRegistry.Register(channels.NewQyWeiXinChannel())
|
||||
globalChannelRegistry.Register(channels.NewFeishuChannel())
|
||||
globalChannelRegistry.Register(channels.NewCustomChannel())
|
||||
globalChannelRegistry.Register(channels.NewWeChatOFAccountChannel())
|
||||
globalChannelRegistry.Register(channels.NewMessageNestChannel())
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package channels
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"message-nest/models"
|
||||
"message-nest/pkg/message"
|
||||
"message-nest/service/send_ins_service"
|
||||
"message-nest/service/send_way_service"
|
||||
)
|
||||
|
||||
type FeishuChannel struct{ *BaseChannel }
|
||||
|
||||
func NewFeishuChannel() *FeishuChannel {
|
||||
return &FeishuChannel{BaseChannel: NewBaseChannel(MessageTypeFeishu, []string{FormatTypeMarkdown, FormatTypeText})}
|
||||
}
|
||||
|
||||
func (c *FeishuChannel) SendUnified(msgObj interface{}, ins models.SendTasksIns, content *UnifiedMessageContent) (string, string) {
|
||||
auth, ok := msgObj.(send_way_service.WayDetailFeishu)
|
||||
if !ok {
|
||||
return "", "类型转换失败"
|
||||
}
|
||||
insService := send_ins_service.SendTaskInsService{}
|
||||
errStr, configInterface := insService.ValidateDiffIns(ins)
|
||||
if errStr != "" {
|
||||
return errStr, ""
|
||||
}
|
||||
_, ok = configInterface.(models.InsFeishuConfig)
|
||||
if !ok {
|
||||
return "飞书config校验失败", ""
|
||||
}
|
||||
contentType, formattedContent, err := c.FormatContent(content)
|
||||
if err != nil {
|
||||
return "", err.Error()
|
||||
}
|
||||
atMobiles := content.GetAtMobiles()
|
||||
atUserIds := content.GetAtUserIds()
|
||||
// 合并 @ 人员列表
|
||||
atList := append(atMobiles, atUserIds...)
|
||||
if content.IsAtAll() {
|
||||
atList = append(atList, "all")
|
||||
}
|
||||
cli := message.Feishu{AccessToken: auth.AccessToken, Secret: auth.Secret}
|
||||
var res []byte
|
||||
var errMsg string
|
||||
if contentType == FormatTypeText {
|
||||
res, err = cli.SendMessageText(formattedContent, atList...)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", err.Error())
|
||||
}
|
||||
} else if contentType == FormatTypeMarkdown {
|
||||
res, err = cli.SendMessageMarkdown(content.Title, formattedContent, atList...)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", err.Error())
|
||||
}
|
||||
} else {
|
||||
errMsg = fmt.Sprintf("未知的飞书发送内容类型:%s", contentType)
|
||||
}
|
||||
return string(res), errMsg
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
package channels
|
||||
|
||||
// 消息格式类型常量
|
||||
import "message-nest/pkg/constant"
|
||||
|
||||
// 重导出常量,保持向后兼容
|
||||
const (
|
||||
FormatTypeText = "text"
|
||||
FormatTypeHTML = "html"
|
||||
FormatTypeMarkdown = "markdown"
|
||||
FormatTypeText = constant.FormatTypeText
|
||||
FormatTypeHTML = constant.FormatTypeHTML
|
||||
FormatTypeMarkdown = constant.FormatTypeMarkdown
|
||||
)
|
||||
|
||||
// 消息类型常量
|
||||
const (
|
||||
MessageTypeEmail = "Email"
|
||||
MessageTypeDtalk = "Dtalk"
|
||||
MessageTypeQyWeiXin = "QyWeiXin"
|
||||
MessageTypeCustom = "Custom"
|
||||
MessageTypeWeChatOFAccount = "WeChatOFAccount"
|
||||
MessageTypeMessageNest = "MessageNest"
|
||||
MessageTypeAliyunSMS = "AliyunSMS"
|
||||
MessageTypeEmail = constant.MessageTypeEmail
|
||||
MessageTypeDtalk = constant.MessageTypeDtalk
|
||||
MessageTypeQyWeiXin = constant.MessageTypeQyWeiXin
|
||||
MessageTypeFeishu = constant.MessageTypeFeishu
|
||||
MessageTypeCustom = constant.MessageTypeCustom
|
||||
MessageTypeWeChatOFAccount = constant.MessageTypeWeChatOFAccount
|
||||
MessageTypeMessageNest = constant.MessageTypeMessageNest
|
||||
MessageTypeAliyunSMS = constant.MessageTypeAliyunSMS
|
||||
)
|
||||
|
||||
// UnifiedMessageContent 统一的消息内容结构
|
||||
|
||||
Reference in New Issue
Block a user