mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-06 15:38:59 +08:00
autonomy notify routing: use enabled channel allow_from instead of notify_allow_chats
This commit is contained in:
@@ -938,6 +938,21 @@ 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
|
||||||
|
notifyAllowFrom := []string{}
|
||||||
|
switch strings.ToLower(a.NotifyChannel) {
|
||||||
|
case "telegram":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.Telegram.AllowFrom...)
|
||||||
|
case "feishu":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.Feishu.AllowFrom...)
|
||||||
|
case "whatsapp":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.WhatsApp.AllowFrom...)
|
||||||
|
case "discord":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.Discord.AllowFrom...)
|
||||||
|
case "qq":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.QQ.AllowFrom...)
|
||||||
|
case "dingtalk":
|
||||||
|
notifyAllowFrom = append(notifyAllowFrom, cfg.Channels.DingTalk.AllowFrom...)
|
||||||
|
}
|
||||||
return autonomy.NewEngine(autonomy.Options{
|
return autonomy.NewEngine(autonomy.Options{
|
||||||
Enabled: a.Enabled,
|
Enabled: a.Enabled,
|
||||||
TickIntervalSec: a.TickIntervalSec,
|
TickIntervalSec: a.TickIntervalSec,
|
||||||
@@ -959,6 +974,6 @@ func buildAutonomyEngine(cfg *config.Config, msgBus *bus.MessageBus) *autonomy.E
|
|||||||
Workspace: cfg.WorkspacePath(),
|
Workspace: cfg.WorkspacePath(),
|
||||||
DefaultNotifyChannel: a.NotifyChannel,
|
DefaultNotifyChannel: a.NotifyChannel,
|
||||||
DefaultNotifyChatID: a.NotifyChatID,
|
DefaultNotifyChatID: a.NotifyChatID,
|
||||||
NotifyAllowChats: a.NotifyAllowChats,
|
NotifyAllowFrom: notifyAllowFrom,
|
||||||
}, msgBus)
|
}, msgBus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,7 @@
|
|||||||
"waiting_resume_debounce_sec": 5,
|
"waiting_resume_debounce_sec": 5,
|
||||||
"allowed_task_keywords": [],
|
"allowed_task_keywords": [],
|
||||||
"notify_channel": "",
|
"notify_channel": "",
|
||||||
"notify_chat_id": "",
|
"notify_chat_id": ""
|
||||||
"notify_allow_chats": []
|
|
||||||
},
|
},
|
||||||
"texts": {
|
"texts": {
|
||||||
"no_response_fallback": "I've completed processing but have no response to give.",
|
"no_response_fallback": "I've completed processing but have no response to give.",
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type Options struct {
|
|||||||
Workspace string
|
Workspace string
|
||||||
DefaultNotifyChannel string
|
DefaultNotifyChannel string
|
||||||
DefaultNotifyChatID string
|
DefaultNotifyChatID string
|
||||||
NotifyAllowChats []string
|
NotifyAllowFrom []string
|
||||||
NotifyCooldownSec int
|
NotifyCooldownSec int
|
||||||
NotifySameReasonCooldownSec int
|
NotifySameReasonCooldownSec int
|
||||||
QuietHours string
|
QuietHours string
|
||||||
@@ -643,9 +643,9 @@ func (e *Engine) shouldNotify(key string, reason string) bool {
|
|||||||
if strings.TrimSpace(e.opts.DefaultNotifyChannel) == "" || strings.TrimSpace(e.opts.DefaultNotifyChatID) == "" {
|
if strings.TrimSpace(e.opts.DefaultNotifyChannel) == "" || strings.TrimSpace(e.opts.DefaultNotifyChatID) == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(e.opts.NotifyAllowChats) > 0 {
|
if len(e.opts.NotifyAllowFrom) > 0 {
|
||||||
allowed := false
|
allowed := false
|
||||||
for _, c := range e.opts.NotifyAllowChats {
|
for _, c := range e.opts.NotifyAllowFrom {
|
||||||
if c == e.opts.DefaultNotifyChatID {
|
if c == e.opts.DefaultNotifyChatID {
|
||||||
allowed = true
|
allowed = true
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package autonomy
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestShouldNotify_RespectsNotifyAllowChats(t *testing.T) {
|
func TestShouldNotify_RespectsNotifyAllowFrom(t *testing.T) {
|
||||||
e := &Engine{opts: Options{
|
e := &Engine{opts: Options{
|
||||||
DefaultNotifyChannel: "telegram",
|
DefaultNotifyChannel: "telegram",
|
||||||
DefaultNotifyChatID: "chat-1",
|
DefaultNotifyChatID: "chat-1",
|
||||||
NotifyAllowChats: []string{"chat-2", "chat-3"},
|
NotifyAllowFrom: []string{"chat-2", "chat-3"},
|
||||||
NotifyCooldownSec: 1,
|
NotifyCooldownSec: 1,
|
||||||
NotifySameReasonCooldownSec: 1,
|
NotifySameReasonCooldownSec: 1,
|
||||||
}}
|
}}
|
||||||
@@ -14,7 +14,7 @@ func TestShouldNotify_RespectsNotifyAllowChats(t *testing.T) {
|
|||||||
t.Fatalf("expected notify to be blocked when chat not in allowlist")
|
t.Fatalf("expected notify to be blocked when chat not in allowlist")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.opts.NotifyAllowChats = []string{"chat-1"}
|
e.opts.NotifyAllowFrom = []string{"chat-1"}
|
||||||
if !e.shouldNotify("k2", "") {
|
if !e.shouldNotify("k2", "") {
|
||||||
t.Fatalf("expected notify to pass when chat in allowlist")
|
t.Fatalf("expected notify to pass when chat in allowlist")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ type AutonomyConfig struct {
|
|||||||
AllowedTaskKeywords []string `json:"allowed_task_keywords" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_ALLOWED_TASK_KEYWORDS"`
|
AllowedTaskKeywords []string `json:"allowed_task_keywords" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_ALLOWED_TASK_KEYWORDS"`
|
||||||
NotifyChannel string `json:"notify_channel" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_NOTIFY_CHANNEL"`
|
NotifyChannel string `json:"notify_channel" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_NOTIFY_CHANNEL"`
|
||||||
NotifyChatID string `json:"notify_chat_id" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_NOTIFY_CHAT_ID"`
|
NotifyChatID string `json:"notify_chat_id" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_NOTIFY_CHAT_ID"`
|
||||||
NotifyAllowChats []string `json:"notify_allow_chats" env:"CLAWGO_AGENTS_DEFAULTS_AUTONOMY_NOTIFY_ALLOW_CHATS"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AgentTextConfig struct {
|
type AgentTextConfig struct {
|
||||||
@@ -333,7 +332,6 @@ func DefaultConfig() *Config {
|
|||||||
AllowedTaskKeywords: []string{},
|
AllowedTaskKeywords: []string{},
|
||||||
NotifyChannel: "",
|
NotifyChannel: "",
|
||||||
NotifyChatID: "",
|
NotifyChatID: "",
|
||||||
NotifyAllowChats: []string{},
|
|
||||||
},
|
},
|
||||||
Texts: AgentTextConfig{
|
Texts: AgentTextConfig{
|
||||||
NoResponseFallback: "I've completed processing but have no response to give.",
|
NoResponseFallback: "I've completed processing but have no response to give.",
|
||||||
|
|||||||
Reference in New Issue
Block a user