fix: 解决钉钉@问题
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user