refactor: 消息模块重构,infra包路径简写等

This commit is contained in:
meilin.huang
2025-07-27 21:02:48 +08:00
parent e96379b6c0
commit 6ad6c69660
149 changed files with 969 additions and 1098 deletions

View File

@@ -1,6 +1,7 @@
package sender
import (
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
@@ -34,7 +35,7 @@ type feishuBotMsgResp struct {
// FeishuBotSender 发送飞书机器人消息
type FeishuBotSender struct{}
func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
func (f FeishuBotSender) Send(ctx context.Context, channel *msgx.Channel, msg *msgx.Msg) error {
// https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot
msgReq := feishuBotMsgReq{
MsgType: "text",
@@ -45,7 +46,7 @@ func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
// 使用receiver参数替换消息内容中可能存在的接收人信息
if len(msg.Receivers) > 0 {
if to := collx.ArrayMapFilter(msg.Receivers, func(a msgx.Receiver) (string, bool) {
if uid := a.GetExtraString("feishuUserId"); uid != "" {
if uid := a.Extra.GetStr("feishuUserId"); uid != "" {
// 使用<at user_id="userId"></at>
return fmt.Sprintf(`<at user_id="%s"></at>`, uid), true
}
@@ -62,7 +63,7 @@ func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
msgReq.Content.Text = content
if secret := channel.GetExtraString("secret"); secret != "" {
if secret := channel.Extra.GetStr("secret"); secret != "" {
timestamp := time.Now().Unix()
if sign, err := f.sign(secret, timestamp); err != nil {
return err