chenhg5/cc-connect · error

max: token is required

Error message

max: token is required

What it means

The MAX platform's New() constructor requires a "token" string in its options map and fails with "max: token is required" when it is absent or empty. The token authenticates all MAX Bot API requests, so the platform cannot be constructed without one. This is a fail-fast validation at configuration load time.

Source

Thrown at platform/max/max.go:107

//	api_base       = "https://platform-api.max.ru"  # optional override
//	webhook_url    = "https://your.domain/webhook"  # optional; switches
//	                                               # platform to webhook mode
//	webhook_listen = ":8080"                       # optional, default ":8080"
//	webhook_path   = "/webhook"                    # optional, default "/webhook";
//	                                               # must match the path in webhook_url
//	webhook_secret = "<random-string>"             # optional; if set, sent to MAX
//	                                               # so MAX includes it in the
//	                                               # X-Max-Bot-Api-Secret header
//	                                               # of every webhook POST (?s= also
//	                                               # accepted for manual testing)
//	webhook_resubscribe_interval = "5m"            # optional, default 5m; cc-connect
//	                                               # periodically re-POSTs the
//	                                               # subscription because MAX has been
//	                                               # observed to silently drop it
func New(opts map[string]any) (core.Platform, error) {
	token, _ := opts["token"].(string)
	if token == "" {
		return nil, fmt.Errorf("max: token is required")
	}
	apiBase, _ := opts["api_base"].(string)
	if apiBase == "" {
		apiBase = defaultAPIBase
	}
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("max", allowFrom)

	webhookURL, _ := opts["webhook_url"].(string)
	webhookListen, _ := opts["webhook_listen"].(string)
	webhookPath, _ := opts["webhook_path"].(string)
	webhookSecret, _ := opts["webhook_secret"].(string)
	if webhookURL != "" && webhookListen == "" {
		webhookListen = ":8080"
	}
	if webhookPath == "" {
		webhookPath = "/webhook"
	} else if !strings.HasPrefix(webhookPath, "/") {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add token = "<your MAX bot token>" to the MAX platform section of config.toml
  2. If using an env var, ensure it is exported in the daemon's environment and the interpolation resolves non-empty
  3. Verify the token is in the correct [platform.max] table, not a sibling section
  4. Obtain a bot token from the MAX bot platform if you don't have one

Example fix

# before (config.toml)
[platform.max]
token = ""

# after
[platform.max]
token = "your-max-bot-token"
Defensive patterns

Strategy: validation

Validate before calling

cfg := ""
if v, ok := opts["token"].(string); ok {
    cfg = v
}
if cfg == "" {
    // abort before calling New()
}

Type guard

func tokenFromOpts(opts map[string]any) (string, bool) {
    t, ok := opts["token"].(string)
    return t, ok && t != ""
}

Try / catch

p, err := max.New(opts)
if err != nil {
    if strings.Contains(err.Error(), "token is required") {
        return fmt.Errorf("config: set [platform.max] token in config.toml: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Creating the MAX platform with opts lacking opts["token"] or with an empty string — e.g., the config.toml [platform.max] section has no token field, or the token value is an empty/unset variable interpolation.

Common situations: Fresh install where config.example.toml was copied but the token placeholder never filled in; environment-variable interpolation producing an empty string because MAX_BOT_TOKEN is unset; token accidentally placed in the wrong config section so the factory never sees it.

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/6e57cf47b936ba9d. Report an issue: GitHub.