feat: add message push function call

This commit is contained in:
engigu
2026-03-04 21:45:43 +08:00
parent d4663cb492
commit 81b8d2a93d
53 changed files with 4161 additions and 33 deletions
+43
View File
@@ -0,0 +1,43 @@
package channels
import "github.com/engigu/baihu-panel/internal/sdk/message"
type FeishuChannel struct{ *BaseChannel }
func NewFeishuChannel() Channel {
return &FeishuChannel{NewBaseChannel(ChannelFeishu, []string{FormatTypeMarkdown, FormatTypeText})}
}
func (c *FeishuChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
accessToken := config.GetString("access_token")
secret := config.GetString("secret")
if accessToken == "" {
return SendError("feishu config missing: access_token is required"), nil
}
contentType, formattedContent := c.FormatContent(msg)
atMobiles := msg.GetAtMobiles()
atUserIds := msg.GetAtUserIds()
atList := append(atMobiles, atUserIds...)
if msg.AtAll {
atList = append(atList, "all")
}
cli := message.Feishu{AccessToken: accessToken, Secret: secret}
var res []byte
var err error
if contentType == FormatTypeText {
res, err = cli.SendMessageText(formattedContent, atList...)
} else if contentType == FormatTypeMarkdown {
res, err = cli.SendMessageMarkdown(msg.Title, formattedContent, atList...)
} else {
return SendError("未知的飞书发送内容类型:%s", contentType), nil
}
if err != nil {
return ErrorResult(string(res), err), nil
}
return SuccessResult(string(res)), nil
}