How DeepSeek-Reasonix Implements the Multi-Channel Bot Gateway for QQ, Feishu, and WeChat

DeepSeek-Reasonix uses a unified bot gateway architecture with platform-specific adapters, shared message routing, and centralized configuration to handle QQ, Feishu, and WeChat through a common runtime interface.

The esengine/DeepSeek-Reasonix repository implements a production-ready multi-channel bot gateway that abstracts three major Chinese IM platforms behind a single runtime. This design lets developers deploy one service that simultaneously listens and responds on QQ, Feishu/Lark, and WeChat without duplicating core logic. The gateway follows a layered architecture: configuration management, adapter binding, runtime coordination, and platform-specific implementations.

Bot Gateway Architecture Overview

The gateway separates concerns across four distinct layers. Each layer has a clear responsibility and well-defined interfaces, making the system extensible for additional platforms.

Configuration Layer

All platform credentials, sandbox flags, and access controls live in internal/config/config.go. The struct QQBotConfig defines QQ-specific settings at lines 851-860, with parallel structures for Feishu (FeishuBotConfig) and WeChat (WeixinBotConfig).

Key configuration fields include:

  • app_id – platform-specific application identifier
  • app_secret_env – environment variable name holding the secret (never hardcoded)
  • sandbox – boolean flag for testing mode
  • model – LLM model selection per platform
  • workspace_root – filesystem isolation path

The QQ configuration section demonstrates this pattern:

[bot.qq]
enabled = true
app_id = "1234567890"
app_secret_env = "QQ_BOT_APP_SECRET"
sandbox = false
model = "gpt-4o-mini"
workspace_root = "/home/user/workspace"

Adapter Binding Layer

In internal/botruntime/runtime.go, the gateway constructs bot.AdapterBinding structs that marry each platform adapter with its metadata. Line 350 creates the QQ binding:

bot.AdapterBinding{
    ID:       "qq",
    Platform: bot.PlatformQQ,
    Adapter:  qq.New(cfg.Bot.QQ, logger),
}

Lines 354-356 repeat this pattern for Feishu (feishu.New) and WeChat (weixin.New). Each binding carries a unique ID string, a Platform enum value, and the concrete adapter instance.

Runtime Coordinator Layer

The Start function in runtime.go (line 87) iterates over all bindings, launches enabled adapters, and registers them with the shared router. The coordinator handles:

  • Enable checks – BotAccessActive(cfg.Bot.QQ.Access) at line 182 filters disabled platforms
  • Lifecycle management – graceful startup and shutdown of each adapter
  • Access control enforcement – allow-lists, approval modes, and rate limiting

The router (botruntime.NewRouter) provides the central message hub where all adapters converge.

Platform-Specific Adapter Layer

Three sub-packages implement the bot.Adapter interface:

Package File Platform-Specific Features
internal/bot/qq adapter.go QQ API, sandbox mode, inline keyboards
internal/bot/feishu adapter.go Feishu card messages, user/group allow-lists
internal/bot/weixin adapter.go WeChat template messages, event callbacks

Each adapter handles HTTP callbacks, message normalization, authentication, and platform-specific formatting.

How Message Flow Works

Understanding the data path clarifies how the bot gateway achieves unified multi-channel operation.

Inbound Message Flow

  1. Platform webhook hits adapter endpoint – QQ, Feishu, or WeChat sends HTTP callback
  2. Adapter authenticates and parses payload – signature verification, token validation
  3. Adapter constructs bot.Message – normalizes to common struct with Platform, ChatID, Text, and metadata
  4. Router receives normalized message – passes to Reasonix core for processing

Outbound Message Flow

  1. Reasonix core generates reply – produces bot.Message with target platform specified
  2. Router selects adapter by Message.Platform – PlatformQQ, PlatformFeishu, or PlatformWeixin
  3. Adapter formats for target API – QQ inline keyboards, Feishu cards, or WeChat templates
  4. Adapter executes platform request – authenticates and sends via official API

This normalization lets the rest of the Reasonix codebase remain platform-agnostic.

Runtime Initialization Example

Starting the multi-channel bot gateway requires minimal boilerplate. The runtime auto-detects enabled platforms from configuration:

func main() {
    cfg, _ := config.Load("reasonix.toml")
    logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

    // Build runtime with automatic platform detection
    rt := botruntime.New(cfg, logger)

    // Block until shutdown signal or fatal error
    if err := rt.Start(context.Background()); err != nil {
        log.Fatalf("bot runtime failed: %v", err)
    }
}

The botruntime.New constructor inspects cfg.Bot.QQ.Enabled, cfg.Bot.Feishu.Enabled, and cfg.Bot.Weixin.Enabled to determine which adapters to instantiate.

Sending Messages Across Channels

The unified bot.Message struct and shared router enable simple cross-platform dispatch. Here's sending a message to QQ:

msg := bot.Message{
    Platform: bot.PlatformQQ,
    ChatID:   "12345678",          // QQ group or user ID
    Text:     "Hello from Reasonix!",
}
router.Dispatch(msg)

Changing platforms requires only modifying the Platform field and ChatID format—no other code changes needed.

Access Control and Validation

The CLI entry point in internal/cli/bot.go validates gateway configuration before startup. Lines 287-294 check credential availability:

if bc.QQ.Enabled {
    secret := os.Getenv(bc.QQ.AppSecretEnv)
    if secret == "" {
        addCheck("bot.qq.app_secret", "missing", bc.QQ.AppSecretEnv+" is not set")
    }
}

This pattern repeats for Feishu and WeChat, ensuring the bot gateway fails fast with clear diagnostics rather than runtime authentication errors.

Key Source Files Reference

File Purpose
internal/config/config.go Platform-specific configuration structs (QQBotConfig, FeishuBotConfig, WeixinBotConfig)
internal/botruntime/runtime.go Adapter orchestration, enable checks, router initialization
internal/bot/types.go Platform enum and Adapter interface definition
internal/bot/qq/adapter.go QQ platform implementation
internal/bot/feishu/adapter.go Feishu/Lark platform implementation
internal/bot/weixin/adapter.go WeChat platform implementation
internal/cli/bot.go CLI validation and gateway startup banner

Adding New IM Platforms

The adapter pattern makes extending the multi-channel bot gateway straightforward:

  1. Define configuration struct in internal/config/config.go
  2. Create internal/bot/<platform>/adapter.go implementing bot.Adapter
  3. Add PlatformNewPlatform enum value in internal/bot/types.go
  4. Register binding in internal/botruntime/runtime.go with constructor call

No changes required to the message router, access control, or core Reasonix logic.

Summary

  • Unified configuration in internal/config/config.go holds per-platform credentials and settings without hardcoding secrets
  • Adapter binding pattern wraps platform-specific constructors (qq.New, feishu.New, weixin.New) with consistent metadata
  • Runtime coordinator in runtime.go manages adapter lifecycles and wires them to the shared router
  • Message normalization through bot.Message lets Reasonix treat all channels uniformly while adapters handle platform quirks
  • Platform packages (internal/bot/qq, feishu, weixin) encapsulate authentication, formatting, and API specifics

Frequently Asked Questions

How does DeepSeek-Reasonix keep credentials secure for the bot gateway?

Credentials are never stored in configuration files. The app_secret_env field holds an environment variable name, and internal/cli/bot.go validates presence at startup. This pattern applies to QQ, Feishu, and WeChat configurations equally.

Can I run multiple platforms simultaneously?

Yes. The runtime in internal/botruntime/runtime.go accepts any combination of enabled platforms. Each adapter runs concurrently with its own HTTP server or webhook handler, all routing through the shared message bus.

What happens if one platform adapter fails?

The Start function handles adapter errors individually. A failure in one platform (e.g., invalid Feishu credentials) does not prevent other adapters from starting. Each adapter's error surface is isolated to prevent cascade failures.

How do I test the bot gateway without production credentials?

Set sandbox = true in the platform configuration section. The QQ adapter specifically supports sandbox mode for development, and similar test mechanisms exist in Feishu and WeChat adapters through their respective configuration flags.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →