mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 20:47:30 +08:00
feishu: add private/group controls (allow_chats, group enable, mention gating)
This commit is contained in:
@@ -152,6 +152,15 @@ func (c *FeishuChannel) handleMessageReceive(_ context.Context, event *larkim.P2
|
||||
if chatID == "" {
|
||||
return nil
|
||||
}
|
||||
chatType := strings.ToLower(strings.TrimSpace(stringValue(message.ChatType)))
|
||||
if !c.isAllowedChat(chatID, chatType) {
|
||||
logger.WarnCF("feishu", "Feishu message rejected by chat allowlist", map[string]interface{}{
|
||||
logger.FieldSenderID: extractFeishuSenderID(sender),
|
||||
logger.FieldChatID: chatID,
|
||||
"chat_type": chatType,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
senderID := extractFeishuSenderID(sender)
|
||||
if senderID == "" {
|
||||
@@ -162,6 +171,13 @@ func (c *FeishuChannel) handleMessageReceive(_ context.Context, event *larkim.P2
|
||||
if content == "" {
|
||||
content = "[empty message]"
|
||||
}
|
||||
if !c.shouldHandleGroupMessage(chatType, content) {
|
||||
logger.DebugCF("feishu", "Ignoring group message without mention/command", map[string]interface{}{
|
||||
logger.FieldSenderID: senderID,
|
||||
logger.FieldChatID: chatID,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
metadata := map[string]string{}
|
||||
if messageID := stringValue(message.MessageId); messageID != "" {
|
||||
@@ -187,6 +203,44 @@ func (c *FeishuChannel) handleMessageReceive(_ context.Context, event *larkim.P2
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *FeishuChannel) isAllowedChat(chatID, chatType string) bool {
|
||||
chatID = strings.TrimSpace(chatID)
|
||||
chatType = strings.ToLower(strings.TrimSpace(chatType))
|
||||
isGroup := chatType != "" && chatType != "p2p"
|
||||
if isGroup && !c.config.EnableGroups {
|
||||
return false
|
||||
}
|
||||
if len(c.config.AllowChats) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, allowed := range c.config.AllowChats {
|
||||
if strings.TrimSpace(allowed) == chatID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *FeishuChannel) shouldHandleGroupMessage(chatType, content string) bool {
|
||||
chatType = strings.ToLower(strings.TrimSpace(chatType))
|
||||
isGroup := chatType != "" && chatType != "p2p"
|
||||
if !isGroup {
|
||||
return true
|
||||
}
|
||||
if !c.config.RequireMentionInGroups {
|
||||
return true
|
||||
}
|
||||
trimmed := strings.TrimSpace(content)
|
||||
if strings.HasPrefix(trimmed, "/") {
|
||||
return true
|
||||
}
|
||||
lower := strings.ToLower(trimmed)
|
||||
if strings.Contains(lower, "@") || strings.Contains(lower, "<at") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func extractFeishuSenderID(sender *larkim.EventSender) string {
|
||||
if sender == nil || sender.SenderId == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user