chenhg5/cc-connect · error
qqbot: SendImage: invalid reply context type %T
Error message
qqbot: SendImage: invalid reply context type %T
What it means
SendImage() (core.ImageSender implementation) also requires replyCtx to be *replyContext. The assertion failure is reported with the unexpected concrete type (%T) to ease debugging. The rich-media upload API needs the group/c2c IDs carried in that context, so sending cannot proceed without it.
Source
Thrown at platform/qqbot/qqbot.go:238
if !ok {
return fmt.Errorf("qqbot: invalid reply context")
}
chunks := core.SplitMessageCodeFenceAware(content, messageMaxLen)
for _, chunk := range chunks {
if err := p.sendMessage(rctx, chunk); err != nil {
return err
}
}
return nil
}
// SendImage uploads and sends an image via QQ Bot rich media API.
// Implements core.ImageSender.
func (p *Platform) SendImage(ctx context.Context, replyCtx any, img core.ImageAttachment) error {
rctx, ok := replyCtx.(*replyContext)
if !ok {
return fmt.Errorf("qqbot: SendImage: invalid reply context type %T", replyCtx)
}
fileInfo, err := p.uploadRichMedia(rctx, 1, img.Data, "")
if err != nil {
return fmt.Errorf("qqbot: upload image: %w", err)
}
var url string
switch rctx.messageType {
case "group":
url = fmt.Sprintf("%s/v2/groups/%s/messages", p.apiBase(), rctx.groupOpenID)
case "c2c":
url = fmt.Sprintf("%s/v2/users/%s/messages", p.apiBase(), rctx.userOpenID)
default:
return fmt.Errorf("qqbot: unknown message type %q", rctx.messageType)
}
body := map[string]any{View on GitHub (pinned to 4000b2338a)
Solutions
- Pass through the unmodified replyCtx obtained from the incoming QQ Bot message event.
- Check the %T in the message — it names the wrong type that was actually supplied.
- Verify the platform interface dispatch (capability check for core.ImageSender) routes to qqbot, not another adapter.
- In tests, construct the context via the platform's own receive path rather than a hand-made struct.
Example fix
// before var ctx any = "group:ABC123" err := p.SendImage(context.Background(), ctx, img) // after ctx := msg.ReplyContext() // *replyContext issued by qqbot receive path err := p.SendImage(context.Background(), ctx, img)
Defensive patterns
Strategy: type-guard
Type guard
rc, ok := replyCtx.(*replyContext)
if !ok {
return fmt.Errorf("SendImage: expected qqbot *replyContext, got %T", replyCtx)
} Try / catch
if err := p.SendImage(ctx, replyCtx, img); err != nil {
if strings.Contains(err.Error(), "invalid reply context type") {
slog.Error("reply ctx from wrong platform", "got", replyCtx)
}
} Prevention
- Check core.ImageSender capability on the platform before invoking SendImage.
- Store the originating platform with each reply context so dispatch never mixes them.
- In tests, build contexts via the platform's receive path, not hand-made structs.
- Log %T of the context on mismatch for fast diagnosis.
When it happens
Trigger: Calling SendImage() with nil, a foreign reply-context type, or a context from another platform package.
Common situations: An engine feature that assumes all platforms accept the same replyCtx shape; forwarding image attachments across platforms; unit tests passing a stub context instead of the platform's own type.
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
- qqbot: invalid reply context
- qqbot: upload image: %w
- qqbot: SendWithButtons: invalid reply context type %T
- cron_expr must be a string
- enabled must be a boolean
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/8257779d868deaac.
Report an issue: GitHub.