fix: 解决钉钉@问题
This commit is contained in:
@@ -989,6 +989,7 @@ app_secret = "your-feishu-app-secret"
|
|||||||
# client_secret = "your-dingtalk-client-secret"
|
# client_secret = "your-dingtalk-client-secret"
|
||||||
# allow_from = "*" # Allowed staff IDs / 允许的员工 ID
|
# allow_from = "*" # Allowed staff IDs / 允许的员工 ID
|
||||||
# share_session_in_channel = false # If true, all users in a group share one agent session / 群聊共享会话
|
# 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 / 取消注释以启用)
|
# WPS Xiezuo / WPS 协作 (uncomment to enable / 取消注释以启用)
|
||||||
# 1. Create a WPS Open Platform app and enable event WebSocket delivery
|
# 1. Create a WPS Open Platform app and enable event WebSocket delivery
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ type Platform struct {
|
|||||||
robotCode string
|
robotCode string
|
||||||
agentID int64 // Agent ID for work notifications API (numeric)
|
agentID int64 // Agent ID for work notifications API (numeric)
|
||||||
allowFrom string
|
allowFrom string
|
||||||
|
requireMention bool
|
||||||
shareSessionInChannel bool
|
shareSessionInChannel bool
|
||||||
streamClient *dingtalkClient.StreamClient
|
streamClient *dingtalkClient.StreamClient
|
||||||
streamCtxCancel context.CancelFunc
|
streamCtxCancel context.CancelFunc
|
||||||
@@ -87,6 +88,9 @@ func New(opts map[string]any) (core.Platform, error) {
|
|||||||
robotCode, _ := opts["robot_code"].(string)
|
robotCode, _ := opts["robot_code"].(string)
|
||||||
allowFrom, _ := opts["allow_from"].(string)
|
allowFrom, _ := opts["allow_from"].(string)
|
||||||
core.CheckAllowFrom("dingtalk", allowFrom)
|
core.CheckAllowFrom("dingtalk", allowFrom)
|
||||||
|
requireMention, _ := opts["require_mention"].(bool)
|
||||||
|
|
||||||
|
fmt.Println("---- [debug], requireMention= ", requireMention)
|
||||||
shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
|
shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
|
||||||
if clientID == "" || clientSecret == "" {
|
if clientID == "" || clientSecret == "" {
|
||||||
return nil, fmt.Errorf("dingtalk: client_id and client_secret are required")
|
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,
|
robotCode: robotCode,
|
||||||
agentID: agentID,
|
agentID: agentID,
|
||||||
allowFrom: allowFrom,
|
allowFrom: allowFrom,
|
||||||
|
requireMention: requireMention,
|
||||||
shareSessionInChannel: shareSessionInChannel,
|
shareSessionInChannel: shareSessionInChannel,
|
||||||
httpClient: &http.Client{Timeout: 30 * time.Second},
|
httpClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
cardTemplateID: cardTemplateID,
|
cardTemplateID: cardTemplateID,
|
||||||
@@ -235,6 +240,12 @@ func (p *Platform) onMessage(data *chatbot.BotCallbackDataModel, richText *richT
|
|||||||
return
|
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)
|
convType := "d" // direct (1:1)
|
||||||
if data.ConversationType == "2" {
|
if data.ConversationType == "2" {
|
||||||
convType = "g" // group
|
convType = "g" // group
|
||||||
|
|||||||
Reference in New Issue
Block a user