fix: allow enabling weixin before binding

This commit is contained in:
lpf
2026-03-24 11:09:03 +08:00
parent 731fc9c99c
commit 428d944e52
2 changed files with 9 additions and 19 deletions

View File

@@ -93,24 +93,17 @@ func (m *Manager) initChannels() error {
}
if m.config.Channels.Weixin.Enabled {
if len(m.config.Channels.Weixin.Accounts) == 0 && strings.TrimSpace(m.config.Channels.Weixin.BotToken) == "" {
logger.WarnCF("channels", 0, map[string]interface{}{
"channel": "weixin",
"error": "missing accounts",
weixin, err := NewWeixinChannel(m.config.Channels.Weixin, m.bus)
if err != nil {
logger.ErrorCF("channels", 0, map[string]interface{}{
logger.FieldChannel: "weixin",
logger.FieldError: err.Error(),
})
} else {
weixin, err := NewWeixinChannel(m.config.Channels.Weixin, m.bus)
if err != nil {
logger.ErrorCF("channels", 0, map[string]interface{}{
logger.FieldChannel: "weixin",
logger.FieldError: err.Error(),
})
} else {
m.channels["weixin"] = weixin
logger.InfoCF("channels", 0, map[string]interface{}{
logger.FieldChannel: "weixin",
})
}
m.channels["weixin"] = weixin
logger.InfoCF("channels", 0, map[string]interface{}{
logger.FieldChannel: "weixin",
})
}
}

View File

@@ -187,9 +187,6 @@ func Validate(cfg *Config) []error {
if cfg.Channels.OutboundDedupeWindowSeconds <= 0 {
errs = append(errs, fmt.Errorf("channels.outbound_dedupe_window_seconds must be > 0"))
}
if cfg.Channels.Weixin.Enabled && len(cfg.Channels.Weixin.Accounts) == 0 && strings.TrimSpace(cfg.Channels.Weixin.BotToken) == "" {
errs = append(errs, fmt.Errorf("channels.weixin.accounts or channels.weixin.bot_token is required when channels.weixin.enabled=true"))
}
if cfg.Channels.Telegram.Enabled && cfg.Channels.Telegram.Token == "" {
errs = append(errs, fmt.Errorf("channels.telegram.token is required when channels.telegram.enabled=true"))
}