{"record":{"id":"fd394f4be81c9f9c","repo":"chenhg5/cc-connect","slug":"telegram-s-bot-not-connected","errorCode":null,"errorMessage":"telegram: %s: bot not connected","messagePattern":"telegram: (.+?): bot not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"platform/telegram/telegram.go","lineNumber":728,"sourceCode":"\tnotify := false\n\tp.mu.Lock()\n\tif p.bot == b && p.generation == gen {\n\t\tp.bot = nil\n\t\tp.selfUser = nil\n\t\tnotify = !p.stopping\n\t}\n\tp.mu.Unlock()\n\n\tif notify {\n\t\tp.notifyUnavailable(fmt.Errorf(\"telegram: connection lost\"))\n\t}\n}\n\nfunc (p *Platform) connectedBot(action string) (telegramBot, error) {\n\tp.mu.RLock()\n\tdefer p.mu.RUnlock()\n\tif p.bot == nil {\n\t\treturn nil, fmt.Errorf(\"telegram: %s: bot not connected\", action)\n\t}\n\treturn p.bot, nil\n}\n\nfunc (p *Platform) botUsername() string {\n\tp.mu.RLock()\n\tdefer p.mu.RUnlock()\n\tif p.selfUser == nil {\n\t\treturn \"\"\n\t}\n\treturn p.selfUser.Username\n}\n\nfunc (p *Platform) hasEverConnected() bool {\n\tp.mu.RLock()\n\tdefer p.mu.RUnlock()\n\treturn p.everConnected\n}","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L710-L746","documentation":"connectedBot(action) returns this error when a send-side operation (reactToMessage, handleCallbackQuery, Reply, Send, SendImage, SendFile) is attempted while p.bot is nil — i.e., the platform has not finished connecting or the connection was lost. The action name is interpolated to identify the failing call.","triggerScenarios":"Calling Reply/Send/SendImage/SendFile (or reaction/callback handlers) before Start() completed the first connection, or after a connection loss cleared the bot but before reconnect succeeded.","commonSituations":"Messages queued by the engine during a network outage get rejected; a reply arrives for a session while the bot is reconnecting; platform started but still in backoff.","solutions":["Wait for the platform to (re)connect before sending; check the availability/unavailable notification state","Add caller-side retry with backoff for transient bot-not-connected windows","Verify Start() was called and succeeded (no token/network errors earlier)","Check network issues that caused the connection loss"],"exampleFix":"// before\nif err := plat.Send(ctx, chatID, text); err != nil { return err }\n// after\nif err := plat.Send(ctx, chatID, text); err != nil {\n    if strings.Contains(err.Error(), \"bot not connected\") {\n        time.Sleep(backoff)\n        return plat.Send(ctx, chatID, text)\n    }\n    return err\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := plat.Send(ctx, chatID, text); err != nil {\n    if strings.Contains(err.Error(), \"bot not connected\") {\n        time.Sleep(2 * time.Second)\n        return plat.Send(ctx, chatID, text)\n    }\n    return err\n}","preventionTips":["Don't send before Start() completes successfully","Buffer/queue messages while the platform reports unavailable","Retry with backoff on this transient error","Watch for connection-loss notifications as a signal to pause sends"],"tags":["telegram","connection","lifecycle","send"],"backgroundTag":"connection-lost","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"}