chenhg5/cc-connect · error
dingtalk: SendImage: invalid reply context type %T
Error message
dingtalk: SendImage: invalid reply context type %T
What it means
This error is returned by Platform.SendImage when the rctx (reply context) argument is not of the internal replyContext struct type. SendImage implements core.ImageSender and expects the reply context that the DingTalk platform itself issued (containing senderStaffId needed for the oToMessages API). Receiving any other type means the caller passed a context from a different platform or a foreign value, so the image cannot be routed to a DingTalk user.
Source
Thrown at platform/dingtalk/dingtalk.go:1017
// AddDoneReaction adds a DingTalk done emotion when configured.
func (p *Platform) AddDoneReaction(rctx any) {
rc, ok := rctx.(replyContext)
if !ok || p.doneEmoji == "" || rc.messageID == "" || rc.conversationId == "" {
return
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := p.sendEmotion(ctx, rc, p.doneEmoji, false); err != nil {
slog.Debug("dingtalk: add done emotion failed", "error", err)
}
}
// SendImage uploads and sends an image via DingTalk oToMessages API.
// Implements core.ImageSender.
func (p *Platform) SendImage(ctx context.Context, rctx any, img core.ImageAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("dingtalk: SendImage: invalid reply context type %T", rctx)
}
name := img.FileName
if name == "" {
name = "image.png"
}
mediaID, err := p.uploadMedia(ctx, img.Data, name, "image")
if err != nil {
return fmt.Errorf("dingtalk: upload image: %w", err)
}
slog.Debug("dingtalk: image uploaded", "media_id", mediaID, "size", len(img.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 exactly the reply context the DingTalk platform handed you with the inbound message — don't synthesize one
- Check that you are not mixing reply contexts across platforms (a feishu context won't work here)
- Ensure rctx is not nil before calling SendImage
- If you need to send images outside a reply flow, use the platform's general Send API rather than SendImage
Example fix
// before: rc := someOtherPlatformReplyContext err := p.SendImage(ctx, rc, img) // after: use the dingtalk replyContext delivered with the message err := p.SendImage(ctx, dingtalkReplyCtx, img)
Defensive patterns
Strategy: type-guard
Validate before calling
// Go: verify the context type before calling SendImage
if _, ok := rctx.(dingtalk.ReplyContext); !ok {
return errors.New("sendImage: rctx is not a dingtalk reply context")
} Type guard
func isDingTalkReplyContext(rctx any) bool {
_, ok := rctx.(replyContext)
return ok
} Try / catch
if err := p.SendImage(ctx, rctx, img); err != nil {
if strings.Contains(err.Error(), "invalid reply context type") {
slog.Error("wrong reply context passed to dingtalk SendImage",
"got", fmt.Sprintf("%T", rctx))
}
} Prevention
- Always pass the reply context exactly as delivered by the platform's inbound message hook
- Never share reply contexts across platform adapters
- Never construct a replyContext manually; obtain it from the platform
- Nil-check rctx before invoking platform-specific senders
When it happens
Trigger: Calling SendImage with a rctx that is not platform/dingtalk's replyContext — e.g. passing a replyContext from the feishu/telegram platform, a nil value, or a hand-constructed context obtained outside the platform's own message pipeline.
Common situations: Cross-platform plugins forwarding reply contexts between adapters; custom code constructing its own reply context instead of using the one delivered with the inbound message; wiring bugs where contexts are mixed up between platforms.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- dingtalk: invalid reply context type %T
- dingtalk: SendFile: invalid reply context type %T
- googlechat: SendImage: invalid reply context type %T
- googlechat: SendFile: invalid reply context type %T
- max: unexpected replyCtx type %T
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/5c4200850b222ac8.
Report an issue: GitHub.