mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-02 08:27:28 +08:00
autonomy notify: fallback to first enabled allow_from channel/chat when notify target unset
This commit is contained in:
@@ -938,8 +938,16 @@ func buildHeartbeatService(cfg *config.Config, msgBus *bus.MessageBus) *heartbea
|
|||||||
|
|
||||||
func buildAutonomyEngine(cfg *config.Config, msgBus *bus.MessageBus) *autonomy.Engine {
|
func buildAutonomyEngine(cfg *config.Config, msgBus *bus.MessageBus) *autonomy.Engine {
|
||||||
a := cfg.Agents.Defaults.Autonomy
|
a := cfg.Agents.Defaults.Autonomy
|
||||||
|
notifyChannel := strings.ToLower(strings.TrimSpace(a.NotifyChannel))
|
||||||
|
notifyChatID := strings.TrimSpace(a.NotifyChatID)
|
||||||
|
if notifyChannel == "" || notifyChatID == "" {
|
||||||
|
if ch, chat := inferAutonomyNotifyTarget(cfg); ch != "" && chat != "" {
|
||||||
|
notifyChannel = ch
|
||||||
|
notifyChatID = chat
|
||||||
|
}
|
||||||
|
}
|
||||||
notifyAllowFrom := []string{}
|
notifyAllowFrom := []string{}
|
||||||
switch strings.ToLower(a.NotifyChannel) {
|
switch notifyChannel {
|
||||||
case "telegram":
|
case "telegram":
|
||||||
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.Telegram.AllowFrom...)
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.Telegram.AllowFrom...)
|
||||||
case "feishu":
|
case "feishu":
|
||||||
@@ -972,8 +980,33 @@ func buildAutonomyEngine(cfg *config.Config, msgBus *bus.MessageBus) *autonomy.E
|
|||||||
CompletionTemplate: cfg.Agents.Defaults.Texts.AutonomyCompletionTemplate,
|
CompletionTemplate: cfg.Agents.Defaults.Texts.AutonomyCompletionTemplate,
|
||||||
BlockedTemplate: cfg.Agents.Defaults.Texts.AutonomyBlockedTemplate,
|
BlockedTemplate: cfg.Agents.Defaults.Texts.AutonomyBlockedTemplate,
|
||||||
Workspace: cfg.WorkspacePath(),
|
Workspace: cfg.WorkspacePath(),
|
||||||
DefaultNotifyChannel: a.NotifyChannel,
|
DefaultNotifyChannel: notifyChannel,
|
||||||
DefaultNotifyChatID: a.NotifyChatID,
|
DefaultNotifyChatID: notifyChatID,
|
||||||
NotifyAllowFrom: notifyAllowFrom,
|
NotifyAllowFrom: notifyAllowFrom,
|
||||||
}, msgBus)
|
}, msgBus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inferAutonomyNotifyTarget(cfg *config.Config) (string, string) {
|
||||||
|
if cfg == nil {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
if cfg.Channels.Telegram.Enabled && len(cfg.Channels.Telegram.AllowFrom) > 0 {
|
||||||
|
return "telegram", strings.TrimSpace(cfg.Channels.Telegram.AllowFrom[0])
|
||||||
|
}
|
||||||
|
if cfg.Channels.Feishu.Enabled && len(cfg.Channels.Feishu.AllowFrom) > 0 {
|
||||||
|
return "feishu", strings.TrimSpace(cfg.Channels.Feishu.AllowFrom[0])
|
||||||
|
}
|
||||||
|
if cfg.Channels.WhatsApp.Enabled && len(cfg.Channels.WhatsApp.AllowFrom) > 0 {
|
||||||
|
return "whatsapp", strings.TrimSpace(cfg.Channels.WhatsApp.AllowFrom[0])
|
||||||
|
}
|
||||||
|
if cfg.Channels.Discord.Enabled && len(cfg.Channels.Discord.AllowFrom) > 0 {
|
||||||
|
return "discord", strings.TrimSpace(cfg.Channels.Discord.AllowFrom[0])
|
||||||
|
}
|
||||||
|
if cfg.Channels.QQ.Enabled && len(cfg.Channels.QQ.AllowFrom) > 0 {
|
||||||
|
return "qq", strings.TrimSpace(cfg.Channels.QQ.AllowFrom[0])
|
||||||
|
}
|
||||||
|
if cfg.Channels.DingTalk.Enabled && len(cfg.Channels.DingTalk.AllowFrom) > 0 {
|
||||||
|
return "dingtalk", strings.TrimSpace(cfg.Channels.DingTalk.AllowFrom[0])
|
||||||
|
}
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user