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
@@ -0,0 +1,42 @@
package channels
import "github.com/engigu/baihu-panel/internal/sdk/message"
type QyWeiXinChannel struct{ *BaseChannel }
func NewQyWeiXinChannel() Channel {
return &QyWeiXinChannel{NewBaseChannel(ChannelQyWeiXin, []string{FormatTypeMarkdown, FormatTypeText})}
}
func (c *QyWeiXinChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
accessToken := config.GetString("access_token")
if accessToken == "" {
return SendError("qyweixin config missing: access_token is required"), nil
}
contentType, formattedContent := c.FormatContent(msg)
atList := []string{}
atList = append(atList, msg.GetAtUserIds()...)
atList = append(atList, msg.GetAtMobiles()...)
if msg.AtAll {
atList = append(atList, "@all")
}
cli := message.QyWeiXin{AccessToken: accessToken}
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
}