{"record":{"id":"1ab58c239c89c604","repo":"chenhg5/cc-connect","slug":"telegram-sendaudio-invalid-reply-context-type-t","errorCode":null,"errorMessage":"telegram: SendAudio: invalid reply context type %T","messagePattern":"telegram: SendAudio: invalid reply context type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1188,"sourceCode":"\t\tname = \"attachment\"\n\t}\n\tparams := &tgbot.SendDocumentParams{\n\t\tChatID:          rc.chatID,\n\t\tMessageThreadID: rc.threadID,\n\t\tDocument:        &models.InputFileUpload{Filename: name, Data: bytes.NewReader(file.Data)},\n\t}\n\tif _, err := bot.SendDocument(ctx, params); err != nil {\n\t\treturn fmt.Errorf(\"telegram: send file: %w\", err)\n\t}\n\treturn nil\n}\n\n// SendAudio sends synthesized audio back to Telegram.\n// It prefers voice messages and falls back to audio files for mp3/m4a on sendVoice failure.\nfunc (p *Platform) SendAudio(ctx context.Context, rctx any, audio []byte, format string) error {\n\trc, ok := rctx.(replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"telegram: SendAudio: invalid reply context type %T\", rctx)\n\t}\n\n\tsendData := audio\n\tsendFormat := strings.ToLower(strings.TrimSpace(format))\n\tif sendFormat == \"\" {\n\t\tsendFormat = \"ogg\"\n\t}\n\n\tswitch sendFormat {\n\tcase \"ogg\", \"opus\", \"mp3\", \"m4a\":\n\t\t// Attempt these formats directly with sendVoice first.\n\tdefault:\n\t\tconverted, err := telegramConvertAudioToOpus(ctx, audio, sendFormat)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"telegram: SendAudio: convert %s to opus: %w\", sendFormat, err)\n\t\t}\n\t\tsendData = converted\n\t\tsendFormat = \"opus\"","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1170-L1206","documentation":"Platform.SendAudio requires rctx to be the telegram replyContext type; any other value fails the assertion and returns this error with the dynamic type. Same guard as the other Send* methods, labeled SendAudio.","triggerScenarios":"Calling SendAudio with nil, a foreign platform's context, or a raw chat-id value instead of the telegram replyContext.","commonSituations":"TTS pipelines calling the adapter directly without a captured reply context; cross-platform message routing bugs; tests using the wrong mock type.","solutions":["Pass the replyContext captured from the telegram incoming message","Nil-check rctx before calling","Construct a telegram replyContext explicitly for proactive sends","Use the %T value in the error to locate the wrong type at the call site"],"exampleFix":"// before\np.SendAudio(ctx, chatID, audio, \"ogg\")\n// after\nrc := telegramReplyContextFor(chatID, threadID)\np.SendAudio(ctx, rc, audio, \"ogg\")","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func toTelegramReplyContext(rctx any) (replyContext, error) {\n    rc, ok := rctx.(replyContext)\n    if !ok {\n        return replyContext{}, fmt.Errorf(\"got %T, want telegram replyContext\", rctx)\n    }\n    return rc, nil\n}","tryCatchPattern":"if err := p.SendAudio(ctx, rctx, audio, format); err != nil {\n    if strings.Contains(err.Error(), \"invalid reply context type\") {\n        return fmt.Errorf(\"SendAudio context bug: %w\", err)\n    }\n    return err\n}","preventionTips":["Obtain the context from the telegram message handler","Never reuse other platforms' contexts","Nil-check before calls","Write a test covering the SendAudio happy path to catch wiring regressions"],"tags":["telegram","type-assertion","invalid-argument"],"backgroundTag":"incompatible-source-type","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"}