fix(feishu): gate group pairing by target bot (#1291)

* fix(feishu): require exact bot_open_id match for mention detection

- Previously, when bot_open_id was empty, ALL mentions were treated as bot mentions
- This caused multiple agents in same group to all respond to any mention
- Now requires bot_open_id to be set AND match exactly for mentionedBot=true
- Fixes issue where CPPAI PM would respond even when other agent was mentioned

* fix(feishu): gate group pairing by target bot

---------

Co-authored-by: ntduc <ntduc@cpp.ai.vn>
This commit is contained in:
Duc Nguyenandntduc authored and GitHub committed 2026-06-28 00:25:49 +07:00
1 parent b72959b34c
commit d460c90403
8 files changed
+728 -56

No files matched your search

+21 -7
View File
@@ -31,16 +31,18 @@ func (c *Channel) parseMessageEvent(event *MessageEvent) *messageContext {
mentionedBot := false
for _, m := range msg.Mentions {
mi := mentionInfo{
Key: m.Key,
OpenID: m.ID.OpenID,
Name: m.Name,
Key: m.Key,
OpenID: m.ID.OpenID,
UserID: m.ID.UserID,
UnionID: m.ID.UnionID,
Name: m.Name,
TenantKey: m.TenantKey,
}
mentions = append(mentions, mi)
// Check if bot is mentioned.
// If botOpenID is known, match exactly; otherwise treat any mention as bot mention
// (fallback when probeBotInfo fails — better to process than silently drop).
if c.botOpenID == "" || mi.OpenID == c.botOpenID {
// Check if this bot is mentioned. Unknown bot identity must fail closed
// so multi-agent groups do not all respond to another bot's mention.
if c.botOpenID != "" && mi.OpenID == c.botOpenID {
mentionedBot = true
}
}
@@ -252,3 +254,15 @@ func resolveMentions(text string, mentions []mentionInfo, botOpenID string) stri
}
return strings.TrimSpace(text)
}
func formatMentionInfos(mentions []mentionInfo) []string {
if len(mentions) == 0 {
return nil
}
out := make([]string, 0, len(mentions))
for _, m := range mentions {
out = append(out, fmt.Sprintf("key=%s open_id=%s user_id=%s union_id=%s name=%s tenant=%s",
m.Key, m.OpenID, m.UserID, m.UnionID, m.Name, m.TenantKey))
}
return out
}