chenhg5/cc-connect · error

wecom: SendImage: invalid reply context type %T

Error message

wecom: SendImage: invalid reply context type %T

What it means

SendImage() implements core.ImageSender and, like Reply, requires the rctx parameter to be the wecom platform's internal replyContext struct. Any other value fails the type assertion and returns this error, which embeds the offending type for diagnosis.

Source

Thrown at platform/wecom/wecom.go:498

			slog.Error("wecom: send failed", "user", rc.userID, "chunk", i, "error", sendErr)
			return sendErr
		}
	}
	slog.Debug("wecom: message sent", "user", rc.userID, "chunks", len(chunks), "total_len", len(content))
	return nil
}

// Send sends a new message (same as Reply for WeChat Work)
func (p *Platform) Send(ctx context.Context, rctx any, content string) error {
	return p.Reply(ctx, rctx, content)
}

// SendImage uploads and sends an image to the user.
// 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("wecom: SendImage: invalid reply context type %T", rctx)
	}

	accessToken, err := p.getAccessToken()
	if err != nil {
		return fmt.Errorf("wecom: send image: %w", err)
	}

	mediaID, err := p.uploadImageMedia(accessToken, img)
	if err != nil {
		return fmt.Errorf("wecom: send image: %w", err)
	}

	payload := map[string]any{
		"touser":  rc.userID,
		"msgtype": "image",
		"agentid": p.agentID,
		"image":   map[string]string{"media_id": mediaID},
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Pass the replyContext value produced by this platform's inbound message handling
  2. Ensure the exact type matches (value type replyContext, not a pointer or copy in another package)
  3. Route image sends through the engine rather than calling platform methods with hand-made contexts

Example fix

// before
err := p.SendImage(ctx, &rc, img) // pointer vs value type mismatch
// after
err := p.SendImage(ctx, rc, img) // replyContext value from the inbound message
Defensive patterns

Strategy: type-guard

Type guard

rc, ok := rctx.(replyContext)
if !ok {
	return fmt.Errorf("cannot send image: expected wecom replyContext, got %T", rctx)
}

Prevention

When it happens

Trigger: Calling SendImage with nil, a plain string user ID, a *replyContext pointer instead of the value type (or vice versa), or a reply context from a different platform adapter.

Common situations: Generic image-forwarding middleware written against multiple platforms that passes its own context struct; refactor changing replyContext between value and pointer types; cross-wiring platform adapters.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/21015685296c2ad8. Report an issue: GitHub.