{"record":{"id":"b8aa8554c99f320a","repo":"chenhg5/cc-connect","slug":"telegram-token-is-required","errorCode":null,"errorMessage":"telegram: token is required","messagePattern":"telegram: token is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"platform/telegram/telegram.go","lineNumber":140,"sourceCode":"\tstopping            bool\n\tgeneration          uint64\n\tunavailableNotified bool\n\teverConnected       bool\n\tnewBot              botFactory\n\tnewBackoffTimer     func(time.Duration) backoffTimer\n\tnewTypingTicker     func(time.Duration) typingTicker\n}\n\nconst (\n\tinitialReconnectBackoff = time.Second\n\tmaxReconnectBackoff     = 30 * time.Second\n\tstableConnectionWindow  = 10 * time.Second\n)\n\nfunc New(opts map[string]any) (core.Platform, error) {\n\ttoken, _ := opts[\"token\"].(string)\n\tif token == \"\" {\n\t\treturn nil, fmt.Errorf(\"telegram: token is required\")\n\t}\n\tallowFrom, _ := opts[\"allow_from\"].(string)\n\tcore.CheckAllowFrom(\"telegram\", allowFrom)\n\n\t// Build HTTP client with optional proxy support.\n\t// Timeout must exceed the server-side long-poll duration (pollTimeout − 1s = 59s)\n\t// to avoid the HTTP client racing with Telegram's response. 90s gives 30s headroom.\n\thttpClient := &http.Client{Timeout: 90 * time.Second}\n\tif proxyURL, _ := opts[\"proxy\"].(string); proxyURL != \"\" {\n\t\tu, err := url.Parse(proxyURL)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"telegram: invalid proxy URL %q: %w\", proxyURL, err)\n\t\t}\n\t\tproxyUser, _ := opts[\"proxy_username\"].(string)\n\t\tproxyPass, _ := opts[\"proxy_password\"].(string)\n\t\tif proxyUser != \"\" {\n\t\t\tu.User = url.UserPassword(proxyUser, proxyPass)\n\t\t}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L122-L158","documentation":"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.","triggerScenarios":"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 \"\").","commonSituations":"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.","solutions":["Set the token in your config: [platforms.telegram] token = \"123456:ABC-DEF...\"","Verify the bot token env var is exported and non-empty before launching cc-connect","Check for typos in the option key name (must be exactly \"token\")","Obtain a token from @BotFather if none exists"],"exampleFix":"// before\n[platforms.telegram]\nallow_from = \"user1\"\n# after\n[platforms.telegram]\ntoken = \"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\"\nallow_from = \"user1\"","handlingStrategy":"validation","validationCode":"token := os.Getenv(\"TELEGRAM_TOKEN\")\nif token == \"\" { return fmt.Errorf(\"TELEGRAM_TOKEN not set\") }","typeGuard":null,"tryCatchPattern":"p, err := telegram.New(opts)\nif err != nil {\n    slog.Error(\"telegram init failed\", \"err\", err)\n    os.Exit(1)\n}","preventionTips":["Keep the token in config.toml or an env var and assert non-empty at startup","Check the key is exactly \"token\" and a string type","Run cc-connect doctor to catch missing platform config early"],"tags":["telegram","config","token","startup"],"backgroundTag":"missing-required-config","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}