refactor: move bot_name from agents.defaults to per-channel config
Move bot_name to TelegramConfig and DingTalkConfig so each channel can independently configure its display name, as suggested in review. - Remove BotName from AgentDefaults - Add BotName to TelegramConfig (env: PICOCLAW_CHANNELS_TELEGRAM_BOT_NAME) - Add BotName to DingTalkConfig (env: PICOCLAW_CHANNELS_DINGTALK_BOT_NAME) - Update telegram_commands.go to read from channel config - Update dingtalk.go to read from its own config (remove botName param) - Update manager.go to match new DingTalk constructor signature
This commit is contained in:
parent
e808fb0831
commit
1bd42c6a0e
4 changed files with 8 additions and 5 deletions
|
|
@ -32,11 +32,12 @@ type DingTalkChannel struct {
|
|||
}
|
||||
|
||||
// NewDingTalkChannel creates a new DingTalk channel instance
|
||||
func NewDingTalkChannel(cfg config.DingTalkConfig, messageBus *bus.MessageBus, botName string) (*DingTalkChannel, error) {
|
||||
func NewDingTalkChannel(cfg config.DingTalkConfig, messageBus *bus.MessageBus) (*DingTalkChannel, error) {
|
||||
if cfg.ClientID == "" || cfg.ClientSecret == "" {
|
||||
return nil, fmt.Errorf("dingtalk client_id and client_secret are required")
|
||||
}
|
||||
|
||||
botName := cfg.BotName
|
||||
if botName == "" {
|
||||
botName = "PicoClaw"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func (m *Manager) initChannels() error {
|
|||
|
||||
if m.config.Channels.DingTalk.Enabled && m.config.Channels.DingTalk.ClientID != "" {
|
||||
logger.DebugC("channels", "Attempting to initialize DingTalk channel")
|
||||
dingtalk, err := NewDingTalkChannel(m.config.Channels.DingTalk, m.bus, m.config.Agents.Defaults.BotName)
|
||||
dingtalk, err := NewDingTalkChannel(m.config.Channels.DingTalk, m.bus)
|
||||
if err != nil {
|
||||
logger.ErrorCF("channels", "Failed to initialize DingTalk channel", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func (c *cmd) Help(ctx context.Context, message telego.Message) error {
|
|||
}
|
||||
|
||||
func (c *cmd) Start(ctx context.Context, message telego.Message) error {
|
||||
botName := c.config.Agents.Defaults.BotName
|
||||
botName := c.config.Channels.Telegram.BotName
|
||||
if botName == "" {
|
||||
botName = "PicoClaw"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ type AgentDefaults struct {
|
|||
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
|
||||
Temperature float64 `json:"temperature" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
|
||||
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
|
||||
BotName string `json:"bot_name" env:"PICOCLAW_AGENTS_DEFAULTS_BOT_NAME"`
|
||||
}
|
||||
|
||||
type ChannelsConfig struct {
|
||||
|
|
@ -92,6 +91,7 @@ type TelegramConfig struct {
|
|||
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_TELEGRAM_ENABLED"`
|
||||
Token string `json:"token" env:"PICOCLAW_CHANNELS_TELEGRAM_TOKEN"`
|
||||
Proxy string `json:"proxy" env:"PICOCLAW_CHANNELS_TELEGRAM_PROXY"`
|
||||
BotName string `json:"bot_name" env:"PICOCLAW_CHANNELS_TELEGRAM_BOT_NAME"`
|
||||
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_TELEGRAM_ALLOW_FROM"`
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +128,7 @@ type DingTalkConfig struct {
|
|||
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_DINGTALK_ENABLED"`
|
||||
ClientID string `json:"client_id" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_ID"`
|
||||
ClientSecret string `json:"client_secret" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_SECRET"`
|
||||
BotName string `json:"bot_name" env:"PICOCLAW_CHANNELS_DINGTALK_BOT_NAME"`
|
||||
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_DINGTALK_ALLOW_FROM"`
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +228,6 @@ func DefaultConfig() *Config {
|
|||
MaxTokens: 8192,
|
||||
Temperature: 0.7,
|
||||
MaxToolIterations: 20,
|
||||
BotName: "PicoClaw",
|
||||
},
|
||||
},
|
||||
Channels: ChannelsConfig{
|
||||
|
|
@ -239,6 +239,7 @@ func DefaultConfig() *Config {
|
|||
Telegram: TelegramConfig{
|
||||
Enabled: false,
|
||||
Token: "",
|
||||
BotName: "PicoClaw",
|
||||
AllowFrom: FlexibleStringSlice{},
|
||||
},
|
||||
Feishu: FeishuConfig{
|
||||
|
|
@ -270,6 +271,7 @@ func DefaultConfig() *Config {
|
|||
Enabled: false,
|
||||
ClientID: "",
|
||||
ClientSecret: "",
|
||||
BotName: "PicoClaw",
|
||||
AllowFrom: FlexibleStringSlice{},
|
||||
},
|
||||
Slack: SlackConfig{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue