{"record":{"id":"1a0436b84ac22085","repo":"chenhg5/cc-connect","slug":"telegram-invalid-chat-id-in-q","errorCode":null,"errorMessage":"telegram: invalid chat ID in %q","messagePattern":"telegram: invalid chat ID in %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1383,"sourceCode":"\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"download file %s: status %d\", fileID, resp.StatusCode)\n\t}\n\treturn io.ReadAll(resp.Body)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// Formats:\n\t//   telegram:{chatID}                      - shared session, no topic\n\t//   telegram:{chatID}:{threadID}           - shared session, with topic\n\t//   telegram:{chatID}:{userID}             - per-user session, no topic\n\t//   telegram:{chatID}:{threadID}:{userID}  - per-user session, with topic\n\tparts := strings.SplitN(sessionKey, \":\", 5)\n\tif len(parts) < 2 || parts[0] != \"telegram\" {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid session key %q\", sessionKey)\n\t}\n\tchatID, err := strconv.ParseInt(parts[1], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid chat ID in %q\", sessionKey)\n\t}\n\n\tthreadID := 0\n\tswitch len(parts) {\n\tcase 2:\n\t\t// telegram:{chatID}\n\tcase 3:\n\t\tif p.shareSessionInChannel {\n\t\t\t// telegram:{chatID}:{threadID}\n\t\t\tthreadID, err = strconv.Atoi(parts[2])\n\t\t\tif err != nil {\n\t\t\t\tslog.Warn(\"telegram: invalid thread ID\", \"raw\", parts[2], \"error\", err)\n\t\t\t}\n\t\t}\n\t\t// else: telegram:{chatID}:{userID} — no threadID\n\tcase 4:\n\t\t// telegram:{chatID}:{threadID}:{userID}\n\t\tthreadID, err = strconv.Atoi(parts[2])","sourceCodeStart":1365,"sourceCodeEnd":1401,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1365-L1401","documentation":"The session-key parser in platform/telegram/telegram.go:1383 found the 'telegram:' prefix and at least 2 segments, but the second segment (the chat ID) is not a valid base-10 64-bit integer. Telegram chat IDs are int64 values, so a non-numeric or out-of-range chat ID makes the session unusable.","triggerScenarios":"Calling the session-key parse function with keys like 'telegram:abc:123' (non-numeric chat ID), 'telegram:' (empty chat ID), or a chat ID that overflows int64.","commonSituations":"Hand-crafted or hand-edited session keys; group chat IDs stored without the required minus sign ('-100...') then corrupted by trimming; keys copied from logs with surrounding characters; storing chat IDs as floats losing precision.","solutions":["Print the raw key and confirm segment 2 after 'telegram:' parses as strconv.ParseInt(..., 10, 64)","Fix the stored key to contain the exact numeric chat ID including any leading '-'","Regenerate the session from a live Telegram update so the chat ID is captured directly from the API","Validate chat IDs when persisting sessions (reject non-int64 values at write time)"],"exampleFix":"// before\nkey := \"telegram:chat_12345\"\n// after\nkey := \"telegram:-1001234567890\"","handlingStrategy":"validation","validationCode":"func validChatID(key string) bool {\n    parts := strings.SplitN(key, \":\", 5)\n    if len(parts) < 2 || parts[0] != \"telegram\" {\n        return false\n    }\n    _, err := strconv.ParseInt(parts[1], 10, 64)\n    return err == nil\n}","typeGuard":"func chatIDFromKey(key string) (int64, bool) {\n    parts := strings.SplitN(key, \":\", 5)\n    if len(parts) < 2 {\n        return 0, false\n    }\n    id, err := strconv.ParseInt(parts[1], 10, 64)\n    return id, err == nil\n}","tryCatchPattern":"sess, err := parseSessionKey(key)\nif err != nil {\n    slog.Warn(\"bad telegram chat ID in session key, dropping session\", \"key\", key, \"err\", err)\n    return errSessionDropped\n}","preventionTips":["Store chat IDs as int64 end-to-end; avoid float/string round-trips that lose precision","Preserve the leading '-' on group/supergroup chat IDs when persisting","Validate keys at write time (on session save) so bad IDs never enter storage","Copy keys from API responses, never from log lines or manual transcription"],"tags":["telegram","session-key","chat-id","parsing","golang"],"backgroundTag":"invalid-identifier-format","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}