Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 57 additions & 32 deletions agent/app/service/agents_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ func extractFeishuConfig(conf map[string]interface{}) dto.AgentFeishuConfig {
if len(feishu) == 0 {
return result
}
if enabled, ok := feishu["enabled"].(bool); ok {
result.Enabled = enabled
}
result.Enabled = extractFeishuPluginEnabled(conf, extractBoolValue(feishu["enabled"], result.Enabled))
if threadSession, ok := feishu["threadSession"].(bool); ok {
result.ThreadSession = threadSession
}
Expand All @@ -408,16 +406,34 @@ func extractFeishuConfig(conf map[string]interface{}) dto.AgentFeishuConfig {
}
result.GroupAllowFrom = extractStringList(feishu["groupAllowFrom"])
defaultBot := defaultFeishuBot()
defaultBot.Enabled = extractBoolValue(feishu["enabled"], defaultBot.Enabled)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Read legacy default enabled from accounts.default

This assignment changes defaultBot.Enabled to depend only on feishu["enabled"], but older saved Feishu configs stored the default bot’s enabled flag under accounts.default.enabled while feishu.enabled represented the overall channel state. In configs where the default bot was disabled and another account was enabled, this now reloads the default bot as enabled and a subsequent save will silently turn it back on. Preserve backward compatibility by falling back to defaultAccount["enabled"] when it exists.

Useful? React with 👍 / 👎.

defaultBot.Name = extractDisplayName(feishu, "", "default")
defaultBot.AppID = extractStringValue(feishu["appId"])
defaultBot.AppSecret = extractStringValue(feishu["appSecret"])
if dmPolicy := extractStringValue(feishu["dmPolicy"]); dmPolicy != "" {
defaultBot.DmPolicy = dmPolicy
}
if _, ok := feishu["allowFrom"]; ok {
defaultBot.AllowFrom = extractStringList(feishu["allowFrom"])
}
accounts := childMap(feishu, "accounts")
defaultAccount := childMap(accounts, "default")
defaultBot.Enabled = extractBoolValue(defaultAccount["enabled"], extractBoolValue(feishu["enabled"], true))
defaultBot.Name = extractDisplayName(defaultAccount, extractStringValue(defaultAccount["botName"]), "Default")
if dmPolicy := extractStringValue(defaultAccount["dmPolicy"]); dmPolicy != "" {
defaultBot.DmPolicy = dmPolicy
if defaultBot.Name == "Default" {
defaultBot.Name = extractDisplayName(defaultAccount, extractStringValue(defaultAccount["botName"]), "Default")
}
if defaultBot.DmPolicy == "pairing" {
if dmPolicy := extractStringValue(defaultAccount["dmPolicy"]); dmPolicy != "" {
defaultBot.DmPolicy = dmPolicy
}
}
defaultBot.AllowFrom = extractStringList(defaultAccount["allowFrom"])
if len(defaultBot.AllowFrom) == 0 {
if _, ok := defaultAccount["allowFrom"]; ok {
defaultBot.AllowFrom = extractStringList(defaultAccount["allowFrom"])
}
}
baseEnabled := defaultBot.Enabled
baseDmPolicy := defaultBot.DmPolicy
baseAllowFrom := append([]string(nil), defaultBot.AllowFrom...)
bots := []dto.AgentFeishuBot{defaultBot}
for _, accountID := range sortedChildKeys(accounts) {
if accountID == "default" {
Expand All @@ -428,15 +444,19 @@ func extractFeishuConfig(conf map[string]interface{}) dto.AgentFeishuConfig {
AgentChannelBotBase: dto.AgentChannelBotBase{
AccountID: accountID,
Name: extractDisplayName(account, extractStringValue(account["botName"]), accountID),
Enabled: extractBoolValue(account["enabled"], true),
Enabled: extractBoolValue(account["enabled"], baseEnabled),
},
AppID: extractStringValue(account["appId"]),
AppSecret: extractStringValue(account["appSecret"]),
AllowFrom: extractStringList(account["allowFrom"]),
DmPolicy: baseDmPolicy,
AllowFrom: append([]string(nil), baseAllowFrom...),
}
if dmPolicy := extractStringValue(account["dmPolicy"]); dmPolicy != "" {
bot.DmPolicy = dmPolicy
}
if _, ok := account["allowFrom"]; ok {
bot.AllowFrom = extractStringList(account["allowFrom"])
}
bots = append(bots, bot)
}
result.Bots = bots
Expand All @@ -447,8 +467,7 @@ func setFeishuConfig(conf map[string]interface{}, config dto.AgentFeishuConfig)
channels := ensureChildMap(conf, "channels")
feishu := ensureChildMap(channels, "feishu")
defaultBot := getDefaultFeishuBot(config.Bots)
effectiveEnabled := config.Enabled && hasEnabledBots(config.Bots)
feishu["enabled"] = effectiveEnabled
feishu["enabled"] = defaultBot.Enabled
feishu["threadSession"] = config.ThreadSession
feishu["replyMode"] = config.ReplyMode
feishu["streaming"] = config.Streaming
Expand All @@ -465,9 +484,20 @@ func setFeishuConfig(conf map[string]interface{}, config dto.AgentFeishuConfig)
}
feishu["appId"] = defaultBot.AppID
feishu["appSecret"] = defaultBot.AppSecret
feishu["dmPolicy"] = defaultBot.DmPolicy
if defaultBot.Name != "" && defaultBot.Name != "Default" {
feishu["name"] = defaultBot.Name
} else {
delete(feishu, "name")
}
if defaultBot.DmPolicy == "open" {
feishu["allowFrom"] = []string{"*"}
} else if defaultBot.DmPolicy == "allowlist" {
feishu["allowFrom"] = append([]string(nil), defaultBot.AllowFrom...)
} else {
delete(feishu, "allowFrom")
}
delete(feishu, "botName")
delete(feishu, "dmPolicy")
delete(feishu, "allowFrom")
delete(feishu, "connectionMode")
delete(feishu, "domain")
delete(feishu, "webhookPath")
Expand All @@ -476,29 +506,13 @@ func setFeishuConfig(conf map[string]interface{}, config dto.AgentFeishuConfig)
delete(feishu, "resolveSenderNames")
delete(feishu, "defaultAccount")
accounts := make(map[string]interface{}, len(config.Bots))
defaultAccount := map[string]interface{}{}
if !defaultBot.Enabled {
defaultAccount["enabled"] = false
}
if defaultBot.Name != "" && defaultBot.Name != "Default" {
defaultAccount["botName"] = defaultBot.Name
}
if defaultBot.DmPolicy != "" {
defaultAccount["dmPolicy"] = defaultBot.DmPolicy
}
if defaultBot.DmPolicy == "open" {
defaultAccount["allowFrom"] = []string{"*"}
} else if defaultBot.DmPolicy == "allowlist" {
defaultAccount["allowFrom"] = append([]string(nil), defaultBot.AllowFrom...)
}
accounts["default"] = defaultAccount
for _, bot := range config.Bots {
if bot.AccountID == "default" || bot.IsDefault {
continue
}
account := map[string]interface{}{
"enabled": bot.Enabled,
"botName": bot.Name,
"name": bot.Name,
"appId": bot.AppID,
"appSecret": bot.AppSecret,
}
Expand All @@ -512,7 +526,18 @@ func setFeishuConfig(conf map[string]interface{}, config dto.AgentFeishuConfig)
}
accounts[bot.AccountID] = account
}
feishu["accounts"] = accounts
if len(accounts) > 0 {
feishu["accounts"] = accounts
} else {
delete(feishu, "accounts")
}
}

func extractFeishuPluginEnabled(conf map[string]interface{}, defaultValue bool) bool {
plugins := childMap(conf, "plugins")
entries := childMap(plugins, "entries")
lark := childMap(entries, "openclaw-lark")
return extractBoolValue(lark["enabled"], defaultValue)
}

func setFeishuPluginEnabled(conf map[string]interface{}, enabled bool) {
Expand Down
Loading