mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 11:17:28 +08:00
feat: add multi-account weixin channel
This commit is contained in:
@@ -170,6 +170,7 @@ type ChannelsConfig struct {
|
||||
InboundMessageIDDedupeTTLSeconds int `json:"inbound_message_id_dedupe_ttl_seconds" env:"CLAWGO_CHANNELS_INBOUND_MESSAGE_ID_DEDUPE_TTL_SECONDS"`
|
||||
InboundContentDedupeWindowSeconds int `json:"inbound_content_dedupe_window_seconds" env:"CLAWGO_CHANNELS_INBOUND_CONTENT_DEDUPE_WINDOW_SECONDS"`
|
||||
OutboundDedupeWindowSeconds int `json:"outbound_dedupe_window_seconds" env:"CLAWGO_CHANNELS_OUTBOUND_DEDUPE_WINDOW_SECONDS"`
|
||||
Weixin WeixinConfig `json:"weixin"`
|
||||
WhatsApp WhatsAppConfig `json:"whatsapp"`
|
||||
Telegram TelegramConfig `json:"telegram"`
|
||||
Feishu FeishuConfig `json:"feishu"`
|
||||
@@ -187,6 +188,27 @@ type WhatsAppConfig struct {
|
||||
RequireMentionInGroups bool `json:"require_mention_in_groups" env:"CLAWGO_CHANNELS_WHATSAPP_REQUIRE_MENTION_IN_GROUPS"`
|
||||
}
|
||||
|
||||
type WeixinConfig struct {
|
||||
Enabled bool `json:"enabled" env:"CLAWGO_CHANNELS_WEIXIN_ENABLED"`
|
||||
BaseURL string `json:"base_url" env:"CLAWGO_CHANNELS_WEIXIN_BASE_URL"`
|
||||
DefaultBotID string `json:"default_bot_id,omitempty"`
|
||||
Accounts []WeixinAccountConfig `json:"accounts,omitempty"`
|
||||
AllowFrom []string `json:"allow_from" env:"CLAWGO_CHANNELS_WEIXIN_ALLOW_FROM"`
|
||||
BotID string `json:"bot_id,omitempty" env:"CLAWGO_CHANNELS_WEIXIN_BOT_ID"`
|
||||
BotToken string `json:"bot_token,omitempty" env:"CLAWGO_CHANNELS_WEIXIN_BOT_TOKEN"`
|
||||
IlinkUserID string `json:"ilink_user_id,omitempty" env:"CLAWGO_CHANNELS_WEIXIN_ILINK_USER_ID"`
|
||||
ContextToken string `json:"context_token,omitempty" env:"CLAWGO_CHANNELS_WEIXIN_CONTEXT_TOKEN"`
|
||||
GetUpdatesBuf string `json:"get_updates_buf,omitempty" env:"CLAWGO_CHANNELS_WEIXIN_GET_UPDATES_BUF"`
|
||||
}
|
||||
|
||||
type WeixinAccountConfig struct {
|
||||
BotID string `json:"bot_id"`
|
||||
BotToken string `json:"bot_token"`
|
||||
IlinkUserID string `json:"ilink_user_id,omitempty"`
|
||||
ContextToken string `json:"context_token,omitempty"`
|
||||
GetUpdatesBuf string `json:"get_updates_buf,omitempty"`
|
||||
}
|
||||
|
||||
type TelegramConfig struct {
|
||||
Enabled bool `json:"enabled" env:"CLAWGO_CHANNELS_TELEGRAM_ENABLED"`
|
||||
Token string `json:"token" env:"CLAWGO_CHANNELS_TELEGRAM_TOKEN"`
|
||||
@@ -465,6 +487,13 @@ func DefaultConfig() *Config {
|
||||
InboundMessageIDDedupeTTLSeconds: 600,
|
||||
InboundContentDedupeWindowSeconds: 12,
|
||||
OutboundDedupeWindowSeconds: 12,
|
||||
Weixin: WeixinConfig{
|
||||
Enabled: false,
|
||||
BaseURL: "https://ilinkai.weixin.qq.com",
|
||||
DefaultBotID: "",
|
||||
Accounts: []WeixinAccountConfig{},
|
||||
AllowFrom: []string{},
|
||||
},
|
||||
WhatsApp: WhatsAppConfig{
|
||||
Enabled: false,
|
||||
BridgeURL: "",
|
||||
|
||||
@@ -187,6 +187,9 @@ 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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user