chenhg5/cc-connect · error
dingtalk: SendFile: invalid reply context type %T
Error message
dingtalk: SendFile: invalid reply context type %T
What it means
SendFile type-asserts its rctx parameter to the DingTalk platform's internal replyContext; this error means the value passed is not a DingTalk reply context (foreign platform's context, nil, or wrong concrete type). File replies must use the reply context belonging to the same platform instance.
Source
Thrown at platform/dingtalk/dingtalk.go:1103
if p.cardTemplateID == "" {
return nil, fmt.Errorf("dingtalk: card_template_id not configured")
}
if p.isCardDegraded() {
return nil, fmt.Errorf("dingtalk: card API temporarily degraded")
}
rc, ok := replyCtx.(replyContext)
if !ok {
return nil, fmt.Errorf("dingtalk: invalid reply context type %T", replyCtx)
}
return p.createAICard(ctx, rc)
}
// SendFile uploads and sends a file via DingTalk oToMessages API.
// Implements core.FileSender.
func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("dingtalk: SendFile: invalid reply context type %T", rctx)
}
name := file.FileName
if name == "" {
name = "file"
}
mediaID, err := p.uploadMedia(ctx, file.Data, name, "file")
if err != nil {
return fmt.Errorf("dingtalk: upload file: %w", err)
}
slog.Debug("dingtalk: file uploaded", "media_id", mediaID, "name", name, "size", len(file.Data))
token, err := p.getAccessToken()
if err != nil {
return fmt.Errorf("dingtalk: get access token: %w", err)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Pass only reply contexts obtained from this DingTalk platform's message handling
- Check the engine routing so file sends go to the platform that produced the context
- Clear persisted/cached reply contexts after restarts or upgrades
- Ensure you're not wrapping the context in another type (e.g. a struct with an embedded context)
Example fix
// before
p.SendFile(ctx, genericCtx, file)
// after
if _, ok := genericCtx.(dingtalk.ReplyContext); !ok {
return fmt.Errorf("not a dingtalk reply context")
}
p.SendFile(ctx, genericCtx, file) Defensive patterns
Strategy: type-guard
Type guard
func canSendFile(p core.Platform, rctx any) bool {
fs, ok := p.(core.FileSender)
if !ok { return false }
_ = fs
return rctx != nil // and platform-specific context check
} Try / catch
if err := p.SendFile(ctx, rctx, file); err != nil {
if strings.Contains(err.Error(), "invalid reply context") {
return fmt.Errorf("file send routed to wrong platform context: %w", err)
}
return err
} Prevention
- Route file sends through the same platform instance that produced the reply context
- Check for core.FileSender capability before calling SendFile
- Avoid persisting and replaying reply contexts across restarts
When it happens
Trigger: Calling SendFile with a reply context from another platform; passing nil; replaying a context from a different DingTalk Platform instance or stale build.
Common situations: Cross-platform message routing bugs; cached reply contexts reused after platform restart; engine handing a telegram context to the dingtalk platform.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- dingtalk: SendImage: invalid reply context type %T
- dingtalk: upload file: %w
- cron_expr must be a string
- enabled must be a boolean
- cloud_web: nil reply context
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/1070349c8758d15b.
Report an issue: GitHub.