chenhg5/cc-connect · error

weixin: token is required (ilink bot Bearer token)

Error message

weixin: token is required (ilink bot Bearer token)

What it means

New constructs the weixin platform and requires a non-empty "token" option — the ilink bot Bearer token used to authenticate against WeChat's API. If the token is missing or only whitespace, construction fails immediately with this error.

Source

Thrown at platform/weixin/weixin.go:173

	var b strings.Builder
	for _, r := range s {
		switch r {
		case '/', '\\', ':', '\x00':
			b.WriteByte('_')
		default:
			b.WriteRune(r)
		}
	}
	return b.String()
}

// New constructs a Weixin platform. Required options: token.
// Optional: base_url, cdn_base_url (default https://novac2c.cdn.weixin.qq.com/c2c), allow_from, route_tag, account_id, long_poll_timeout_ms,
// state_dir (override persistence dir), proxy, cc_data_dir + cc_project (injected by main).
func New(opts map[string]any) (core.Platform, error) {
	token, _ := opts["token"].(string)
	if strings.TrimSpace(token) == "" {
		return nil, fmt.Errorf("weixin: token is required (ilink bot Bearer token)")
	}
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("weixin", allowFrom)

	baseURL, _ := opts["base_url"].(string)
	cdnBaseURL, _ := opts["cdn_base_url"].(string)
	if strings.TrimSpace(cdnBaseURL) == "" {
		cdnBaseURL = defaultCDNBaseURL
	}
	cdnBaseURL = strings.TrimRight(strings.TrimSpace(cdnBaseURL), "/")
	routeTag, _ := opts["route_tag"].(string)
	accountLabel, _ := opts["account_id"].(string)
	if accountLabel == "" {
		accountLabel = "default"
	}
	lp := pickInt(opts["long_poll_timeout_ms"])

	// Send-volume quota (see defaultBurstLimit constants). 0 disables the quota.

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set token = "<ilink bot Bearer token>" in the weixin platform config
  2. Verify the config key is exactly "token" and under the weixin platform section
  3. Check that any env-var interpolation for the token resolves to a non-empty value

Example fix

// before
err := weixin.New(map[string]any{"base_url": "https://ilink.ai"})
// after
err := weixin.New(map[string]any{"base_url": "https://ilink.ai", "token": os.Getenv("WEIXIN_TOKEN")})
Defensive patterns

Strategy: validation

Validate before calling

tok, _ := opts["token"].(string)
if strings.TrimSpace(tok) == "" {
    return errors.New("weixin platform requires a non-empty token")
}
_ = weixin.New(opts)

Try / catch

p, err := weixin.New(opts)
if err != nil {
    if strings.Contains(err.Error(), "token is required") {
        log.Fatal("missing weixin token in config")
    }
    return err
}

Prevention

When it happens

Trigger: Calling weixin.New(opts) (or starting cc-connect with a [platform.weixin] config block) where opts["token"] is absent, an empty string, or whitespace only.

Common situations: config.toml omits the token field; token defined under the wrong platform section; environment-variable substitution produced an empty string; typos like "Token" or "api_key" instead of "token".

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/368a45541d78f8cc. Report an issue: GitHub.