Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions internal/bot/feishu/feishu.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type feishuMsgEvent struct {
MessageID string `json:"message_id"`
RootID string `json:"root_id"`
ParentID string `json:"parent_id"`
ThreadID string `json:"thread_id"`
ChatID string `json:"chat_id"`
ChatType string `json:"chat_type"`
MsgType string `json:"msg_type"`
Expand Down Expand Up @@ -432,16 +433,21 @@ func (a *adapter) handleMessage(msg feishuMsgEvent) {
return
}

// @mention gating:仅在群聊中检查是否 @了 bot
// @mention gating:仅在群聊或话题群中检查是否 @了 bot
chatType := bot.ChatDM
if msg.ChatType == "group" {
if msg.ChatType == "group" || msg.ChatType == "topic_group" {
chatType = bot.ChatGroup
if a.cfg.RequireMention && len(msg.Mentions) == 0 {
a.logger.Info("feishu message ignored", "reason", "missing_mention", "chat", logHash(msg.ChatID), "message", logHash(msg.MessageID))
return
}
}

threadID := firstNonEmpty(msg.ThreadID, msg.RootID)
if threadID == "" && msg.ChatType == "topic_group" {
threadID = msg.ChatID
}

ib := bot.InboundMessage{
Platform: bot.PlatformFeishu,
ChatType: chatType,
Expand All @@ -450,6 +456,7 @@ func (a *adapter) handleMessage(msg feishuMsgEvent) {
UserName: "",
Text: content.Text,
MessageID: msg.MessageID,
ThreadID: threadID,
}

// 获取用户信息填充用户名
Expand Down Expand Up @@ -623,7 +630,11 @@ func (a *adapter) sendCard(ctx context.Context, msg bot.OutboundMessage) (bot.Se
"elements": elements,
}

cardJSON, _ := json.Marshal(cardPayload)
cardJSON, err := json.Marshal(cardPayload)
if err != nil {
a.logger.Warn("feishu card marshal error", "err", err)
return bot.SendResult{}, fmt.Errorf("feishu card marshal: %w", err)
}
return a.sendSDKContent(ctx, msg, larkim.MsgTypeInteractive, string(cardJSON))
}

Expand Down
7 changes: 4 additions & 3 deletions internal/bot/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ func (s *renderSink) Emit(e event.Event) {
if e.Tool.Err != "" {
fmt.Fprintf(&s.buf, "\n❌ %s 出错: %s", name, e.Tool.Err)
} else {
// 截断输出
// 截断输出(按字符数而非字节数,避免截断多字节 UTF-8 字符)
output := e.Tool.Output
if len(output) > 500 {
output = output[:500] + "\n... (已截断)"
runes := []rune(output)
if len(runes) > 500 {
output = string(runes[:500]) + "\n... (已截断)"
}
fmt.Fprintf(&s.buf, "\n✅ %s 完成", name)
if output != "" {
Expand Down