From 4d1dd254729b5ab4b58d78a096465a20ef26ee0a Mon Sep 17 00:00:00 2001 From: Kaxi <1042864399@qq.com> Date: Wed, 3 Jun 2026 00:21:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=92=89=E9=92=89@?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.example.toml | 1 + platform/dingtalk/dingtalk.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/config.example.toml b/config.example.toml index 3e663b6..8b4fb7b 100644 --- a/config.example.toml +++ b/config.example.toml @@ -989,6 +989,7 @@ app_secret = "your-feishu-app-secret" # client_secret = "your-dingtalk-client-secret" # allow_from = "*" # Allowed staff IDs / 允许的员工 ID # share_session_in_channel = false # If true, all users in a group share one agent session / 群聊共享会话 +# require_mention = false # If true, only respond in groups when @mentioned / 群聊中仅在被 @ 时响应 # WPS Xiezuo / WPS 协作 (uncomment to enable / 取消注释以启用) # 1. Create a WPS Open Platform app and enable event WebSocket delivery diff --git a/platform/dingtalk/dingtalk.go b/platform/dingtalk/dingtalk.go index f4ddb8b..92d03f4 100644 --- a/platform/dingtalk/dingtalk.go +++ b/platform/dingtalk/dingtalk.go @@ -64,6 +64,7 @@ type Platform struct { robotCode string agentID int64 // Agent ID for work notifications API (numeric) allowFrom string + requireMention bool shareSessionInChannel bool streamClient *dingtalkClient.StreamClient streamCtxCancel context.CancelFunc @@ -87,6 +88,9 @@ func New(opts map[string]any) (core.Platform, error) { robotCode, _ := opts["robot_code"].(string) allowFrom, _ := opts["allow_from"].(string) core.CheckAllowFrom("dingtalk", allowFrom) + requireMention, _ := opts["require_mention"].(bool) + + fmt.Println("---- [debug], requireMention= ", requireMention) shareSessionInChannel, _ := opts["share_session_in_channel"].(bool) if clientID == "" || clientSecret == "" { return nil, fmt.Errorf("dingtalk: client_id and client_secret are required") @@ -132,6 +136,7 @@ func New(opts map[string]any) (core.Platform, error) { robotCode: robotCode, agentID: agentID, allowFrom: allowFrom, + requireMention: requireMention, shareSessionInChannel: shareSessionInChannel, httpClient: &http.Client{Timeout: 30 * time.Second}, cardTemplateID: cardTemplateID, @@ -235,6 +240,12 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT return } + // In group chats, only respond when the bot is @mentioned (if require_mention is set). + if p.requireMention && data.ConversationType == "2" && !data.IsInAtList { + slog.Debug("dingtalk: ignoring group message without @mention", "user", data.SenderNick) + return + } + convType := "d" // direct (1:1) if data.ConversationType == "2" { convType = "g" // group