chenhg5/cc-connect · error

wecom: send image: %w

Error message

wecom: send image: %w

What it means

After validating the reply context, SendImage() calls getAccessToken() to authenticate the message/send and media/upload API calls. Any token acquisition failure (network, bad credentials, WeCom errcode) is returned wrapped as "wecom: send image: %w".

Source

Thrown at platform/wecom/wecom.go:503

	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},
	}

	body, _ := json.Marshal(payload)
	apiURL := p.wecomAPIURL("/cgi-bin/message/send", url.Values{
		"access_token": []string{accessToken},
	})

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the underlying token error (see the wrapped cause): update corp_id/corp_secret, restore network access, or correct proxy settings
  2. Confirm the app's trusted IP allowlist includes the server's egress address
  3. Test token acquisition independently via curl on the gettoken endpoint before retrying image sends

Example fix

// before
"corp_secret": "typo-secret" // token fetch fails -> send image: gettoken errcode 40001
// after
"corp_secret": "correctCurrentSecret"
Defensive patterns

Strategy: try-catch

Try / catch

if err := p.SendImage(ctx, rctx, img); err != nil {
	var netErr net.Error
	if errors.As(err, &netErr) && netErr.Timeout() {
		// retry with backoff
	}
	return fmt.Errorf("image delivery failed: %w", err)
}

Prevention

When it happens

Trigger: getAccessToken fails inside SendImage: invalid corp_secret (errcode 40001), unreachable API host, blocked egress, or timeout via a misconfigured proxy.

Common situations: Rotated corp secret not updated in config; restricted egress on the deployment host; trusted-IP allowlist in the WeCom app excluding the server.

Related errors


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