{"record":{"id":"9a86a5dd2ced2589","repo":"chenhg5/cc-connect","slug":"telegram-invalid-reply-context-type-t","errorCode":null,"errorMessage":"telegram: invalid reply context type %T","messagePattern":"telegram: invalid reply context type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1041,"sourceCode":"\t}\n\n\tslog.Debug(\"telegram: ignoring group message not directed at bot\", \"chat\", msg.Chat.ID, \"bot\", botName, \"text\", msg.Text, \"entities\", msg.Entities)\n\treturn false\n}\n\nfunc isCommand(msg *models.Message) bool {\n\tfor _, e := range msg.Entities {\n\t\tif e.Type == models.MessageEntityTypeBotCommand && e.Offset == 0 {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (p *Platform) Reply(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(\"reply\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\thtml := core.MarkdownToSimpleHTML(content)\n\tparams := &tgbot.SendMessageParams{\n\t\tChatID:          rc.chatID,\n\t\tMessageThreadID: rc.threadID,\n\t\tText:            html,\n\t\tParseMode:       models.ParseModeHTML,\n\t\tReplyParameters: &models.ReplyParameters{MessageID: rc.messageID},\n\t}\n\n\tif _, err := bot.SendMessage(ctx, params); err != nil {\n\t\terrMsg := err.Error()\n\t\t// Handle HTML parsing errors by falling back to plain text","sourceCodeStart":1023,"sourceCodeEnd":1059,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1023-L1059","documentation":"Reply() asserts that the reply context passed by the engine is the telegram package's internal replyContext type. Receiving any other value (nil, a different platform's context struct, or a raw string) means a wiring bug, so it fails fast with a type-name-bearing error for diagnosis.","triggerScenarios":"Calling Reply(ctx, rctx, content) where rctx is not a telegram.replyContext — typically because the reply context was produced by a different platform adapter or was never created by a telegram ReceiveMessage/handler path.","commonSituations":"Cross-platform message routing bug where a Slack/Telegram context is fed to the Telegram platform; test code passing a placeholder context; custom code constructing reply contexts manually.","solutions":["Ensure Reply is only called with reply contexts obtained from this telegram Platform's incoming message handling","Check engine routing so each message goes back through the platform that produced it","In tests, build a proper telegram replyContext rather than a mock value","Read %T in the error to identify which wrong type was passed"],"exampleFix":"// before\nplat.Reply(ctx, someSlackReplyCtx, \"hi\")\n// after\nrc, ok := msg.ReplyContext.(telegram.ReplyContext)\nif !ok { return fmt.Errorf(\"not a telegram reply context\") }\nplat.Reply(ctx, rc, \"hi\")","handlingStrategy":"type-guard","validationCode":"if _, ok := rctx.(telegram.ReplyContext); !ok {\n    return fmt.Errorf(\"wrong platform context for telegram.Reply\")\n}","typeGuard":"func isTelegramReplyContext(rc any) bool {\n    _, ok := rc.(telegram.ReplyContext)\n    return ok\n}","tryCatchPattern":"if err := plat.Reply(ctx, rctx, content); err != nil {\n    if strings.Contains(err.Error(), \"invalid reply context type\") {\n        slog.Error(\"reply context from wrong platform\", \"got\", fmt.Sprintf(\"%T\", rctx))\n    }\n    return err\n}","preventionTips":["Only pass reply contexts that originated from this telegram platform","Keep engine routing 1:1 between incoming platform and outgoing Reply","Never construct reply contexts manually in application code","Check %T in the error message to identify the mismatched type"],"tags":["telegram","type-mismatch","reply","internal-api"],"backgroundTag":"type-mismatch","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"}