{"record":{"id":"dede6241377e4a5e","repo":"chenhg5/cc-connect","slug":"telegram-send-image-w","errorCode":null,"errorMessage":"telegram: send image: %w","messagePattern":"telegram: send image: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1153,"sourceCode":"\t\treturn fmt.Errorf(\"telegram: invalid reply context type %T\", rctx)\n\t}\n\tbot, err := p.connectedBot(\"send image\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tname := img.FileName\n\tif name == \"\" {\n\t\tname = \"image\"\n\t}\n\tslog.Debug(\"telegram: sending image\", \"chat_id\", rc.chatID, \"name\", name, \"size\", len(img.Data))\n\tparams := &tgbot.SendPhotoParams{\n\t\tChatID:          rc.chatID,\n\t\tMessageThreadID: rc.threadID,\n\t\tPhoto:           &models.InputFileUpload{Filename: name, Data: bytes.NewReader(img.Data)},\n\t}\n\tif _, err := bot.SendPhoto(ctx, params); err != nil {\n\t\treturn fmt.Errorf(\"telegram: send image: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {\n\trc, ok := rctx.(replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"telegram: invalid reply context type %T\", rctx)\n\t}\n\tbot, err := p.connectedBot(\"send file\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tname := file.FileName\n\tif name == \"\" {\n\t\tname = \"attachment\"\n\t}","sourceCodeStart":1135,"sourceCodeEnd":1171,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1135-L1171","documentation":"Platform.SendImage wraps errors from bot.SendPhoto with \"telegram: send image: \". It means the photo upload/delivery to Telegram failed; the image bytes are streamed via InputFileUpload so large payloads and network faults are the usual causes.","triggerScenarios":"bot.SendPhoto fails: multipart upload interrupted, image exceeds Telegram's 10 MB photo limit, invalid chat/thread ID, bot lacks access, or Telegram API returns an error.","commonSituations":"Sending screenshots or generated images larger than 10 MB (Telegram photo limit); flaky networks during multipart upload; bot removed from chat; sending to a topic thread that no longer exists.","solutions":["Check the wrapped cause for the real error (size limit vs network vs chat access)","Resize/compress images to under 10 MB before SendPhoto, or send as a document instead","Verify bot membership in the target chat and valid threadID","Retry transient upload failures with backoff","Validate img.Data is non-empty and a supported format (jpg/png/webp) before sending"],"exampleFix":"// before\nif len(img.Data) > 10*1024*1024 { /* silently too large */ }\nbot.SendPhoto(ctx, params) // fails\n// after\nif len(img.Data) > 10*1024*1024 {\n    return p.SendFile(ctx, rctx, core.FileAttachment{Name: name, Data: img.Data})\n}\n_, err := bot.SendPhoto(ctx, params)","handlingStrategy":"validation","validationCode":"// validate image before upload\nif len(img.Data) == 0 {\n    return errors.New(\"empty image data\")\n}\nif len(img.Data) > 10*1024*1024 {\n    return errors.New(\"image exceeds Telegram 10MB photo limit; send as document\")\n}","typeGuard":null,"tryCatchPattern":"if err := p.SendImage(ctx, rc, img); err != nil {\n    var apiErr *tgbot.Error\n    if errors.As(err, &apiErr) {\n        // inspect apiErr.Description for size/chat errors\n    }\n    return err\n}","preventionTips":["Keep photos under 10MB or route through SendFile","Compress screenshots before upload","Verify bot chat membership","Retry transient upload failures with backoff"],"tags":["telegram","image-upload","api-error"],"backgroundTag":"api-request-failed","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"}