{"record":{"id":"ce5885ae65ba6d8f","repo":"chenhg5/cc-connect","slug":"telegram-send-w","errorCode":null,"errorMessage":"telegram: send: %w","messagePattern":"telegram: send: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1079,"sourceCode":"\t\t\tslog.Warn(\"telegram: HTML rejected by Telegram, sending as plain text\",\n\t\t\t\t\"method\", \"Reply\",\n\t\t\t\t\"error\", errMsg,\n\t\t\t\t\"html_prefix\", truncateForLog(html, 200),\n\t\t\t\t\"html_len\", len(html),\n\t\t\t)\n\t\t\tparams.Text = content\n\t\t\tparams.ParseMode = \"\"\n\t\t\t_, err = bot.SendMessage(ctx, params)\n\t\t} else if strings.Contains(errMsg, \"message is too long\") {\n\t\t\t// Handle message too long by splitting and sending as multiple messages\n\t\t\tslog.Warn(\"telegram: message too long, splitting into chunks\",\n\t\t\t\t\"method\", \"Reply\",\n\t\t\t\t\"html_len\", len(html),\n\t\t\t)\n\t\t\treturn p.sendChunked(ctx, bot, rc, html)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"telegram: send: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Send sends a new message (not a reply)\nfunc (p *Platform) Send(ctx context.Context, rctx any, content string) 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\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\thtml := core.MarkdownToSimpleHTML(content)\n\tparams := &tgbot.SendMessageParams{","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1061-L1097","documentation":"The Telegram platform's Reply method wraps any error returned by the underlying bot API sendMessage call with the prefix \"telegram: send: \". It indicates the message (as HTML) could not be delivered to Telegram. The original transport/API error is preserved via %w for errors.Is/As inspection.","triggerScenarios":"Calling Platform.Reply with a replyContext whose chat is unreachable: bot.SendMessage returns a network error, Telegram API error (chat not found, bot blocked, message too long if chunking path not taken), or rate limit.","commonSituations":"Bot kicked from or never added to the chat; wrong chat_id in the reply context; Telegram API downtime or local network failure; hitting the 4096-char limit when the html_len pre-check did not route to sendChunked; flood limits from many rapid replies.","solutions":["Check the wrapped cause with errors.Unwrap / errors.As to see whether it is network, auth, or a Telegram API error","Verify the bot is a member of the target chat and the chatID in replyContext is correct","Ensure the bot token is valid (run cc-connect doctor or call getMe)","Retry with backoff on 429 responses; Telegram rate limits bots per chat","Pre-check HTML length so oversized messages go through sendChunked instead of a single sendMessage"],"exampleFix":"// before\nerr := p.Reply(ctx, rctx, hugeMessage) // single sendMessage fails\n// after\nif len(html) > 4000 {\n    return p.sendChunked(ctx, bot, rc, html)\n}","handlingStrategy":"retry","validationCode":"// check message length before sending\nif len([]rune(html)) > 4096 {\n    return p.sendChunked(ctx, bot, rc, html)\n}","typeGuard":null,"tryCatchPattern":"if err := p.Reply(ctx, rc, html); err != nil {\n    var apiErr *tgbot.Error\n    if errors.As(err, &apiErr) && apiErr.ResponseCode == 429 {\n        // wait retry-after and retry\n    }\n    return fmt.Errorf(\"telegram reply failed: %w\", err)\n}","preventionTips":["Keep the bot in the target chat and verify chat IDs","Handle 429 flood limits with retry-after delays","Chunk messages over 4096 chars before sending","Monitor Telegram API status for outages"],"tags":["telegram","network","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-14T05:17:10.506Z"}