chenhg5/cc-connect · critical

telegram: token is required

Error message

telegram: token is required

What it means

telegram.New() validates the required 'token' option at construction time. If opts['token'] is absent or an empty string, it refuses to build the Platform and returns this error instead of failing later at runtime with cryptic Telegram 401 responses.

Solutions

  1. Set the token in your config: [platforms.telegram] token = "123456:ABC-DEF..."
  2. Verify the bot token env var is exported and non-empty before launching cc-connect
  3. Check for typos in the option key name (must be exactly "token")
  4. Obtain a token from @BotFather if none exists

Example fix

// before
[platforms.telegram]
allow_from = "user1"
# after
[platforms.telegram]
token = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
allow_from = "user1"
Defensive patterns

Strategy: validation

Validate before calling

token := os.Getenv("TELEGRAM_TOKEN")
if token == "" { return fmt.Errorf("TELEGRAM_TOKEN not set") }

Try / catch

p, err := telegram.New(opts)
if err != nil {
    slog.Error("telegram init failed", "err", err)
    os.Exit(1)
}

Prevention

When it happens

Trigger: Calling telegram.New(opts) with a map that lacks the "token" key, or where opts["token"] is set to "" or is a non-string type (the type assertion fails and yields "").

Common situations: Missing token in config.toml ([platforms.telegram] section), env var substitution producing an empty string (TELEGRAM_TOKEN unset), or typo in the config key name.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at platform/telegram/telegram.go:140

	stopping            bool
	generation          uint64
	unavailableNotified bool
	everConnected       bool
	newBot              botFactory
	newBackoffTimer     func(time.Duration) backoffTimer
	newTypingTicker     func(time.Duration) typingTicker
}

const (
	initialReconnectBackoff = time.Second
	maxReconnectBackoff     = 30 * time.Second
	stableConnectionWindow  = 10 * time.Second
)

func New(opts map[string]any) (core.Platform, error) {
	token, _ := opts["token"].(string)
	if token == "" {
		return nil, fmt.Errorf("telegram: token is required")
	}
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("telegram", allowFrom)

	// Build HTTP client with optional proxy support.
	// Timeout must exceed the server-side long-poll duration (pollTimeout − 1s = 59s)
	// to avoid the HTTP client racing with Telegram's response. 90s gives 30s headroom.
	httpClient := &http.Client{Timeout: 90 * time.Second}
	if proxyURL, _ := opts["proxy"].(string); proxyURL != "" {
		u, err := url.Parse(proxyURL)
		if err != nil {
			return nil, fmt.Errorf("telegram: invalid proxy URL %q: %w", proxyURL, err)
		}
		proxyUser, _ := opts["proxy_username"].(string)
		proxyPass, _ := opts["proxy_password"].(string)
		if proxyUser != "" {
			u.User = url.UserPassword(proxyUser, proxyPass)
		}

View on GitHub (pinned to 4000b2338a)