chenhg5/cc-connect · error
dingtalk: not a dingtalk session key: %q
Error message
dingtalk: not a dingtalk session key: %q
What it means
ReconstructReplyCtx (the core.ReplyContextReconstructor implementation) received a session key that does not start with the 'dingtalk:' prefix, so it cannot belong to this platform. Each platform owns its own session-key namespace; passing a key from another platform (e.g. 'telegram:...') to DingTalk's reconstructor is invalid. This is a defensive namespace check.
Source
Thrown at platform/dingtalk/dingtalk.go:1607
func normalizeQuotedMessageText(s string) string {
text := strings.TrimSpace(s)
if text == "" {
return ""
}
runes := []rune(text)
if len(runes) <= maxQuotedMessageRunes {
return text
}
return string(runes[:maxQuotedMessageRunes]) + "..."
}
// ReconstructReplyCtx implements core.ReplyContextReconstructor.
// Session key format: "dingtalk:{convType}:{conversationId}:{senderStaffId}" or "dingtalk:{convType}:{conversationId}"
// where convType is "g" (group) or "d" (direct/1:1).
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
if !strings.HasPrefix(sessionKey, "dingtalk:") {
return nil, fmt.Errorf("dingtalk: not a dingtalk session key: %q", sessionKey)
}
stripped := strings.TrimPrefix(sessionKey, "dingtalk:")
parts := strings.SplitN(stripped, ":", 3)
if len(parts) < 2 {
return nil, fmt.Errorf("dingtalk: invalid session key format: %q", sessionKey)
}
convType := parts[0]
if convType != "g" && convType != "d" {
return nil, fmt.Errorf("dingtalk: invalid conversation type %q in session key: %q", convType, sessionKey)
}
conversationId := parts[1]
if conversationId == "" {
return nil, fmt.Errorf("dingtalk: empty conversationId in session key: %q", sessionKey)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Verify the session key was produced by the DingTalk platform (starts with 'dingtalk:').
- Check the /sessions listing or persistence layer for the correct platform-scoped key.
- If migrating keys across platforms, reconstruct via the correct platform's ReconstructReplyCtx, not DingTalk's.
- For cc-connect send/cron/webhook commands, ensure the --session or config value references a dingtalk:* key when the target platform is dingtalk.
Example fix
// before
rc, err := platform.ReconstructReplyCtx(sessionKey)
// after
if !strings.HasPrefix(sessionKey, "dingtalk:") {
return fmt.Errorf("refusing to reconstruct: %q is not a dingtalk session key", sessionKey)
}
rc, err := platform.ReconstructReplyCtx(sessionKey) Defensive patterns
Strategy: validation
Validate before calling
func reconstructIfDingtalk(platform *Platform, sessionKey string) (any, error) {
if !strings.HasPrefix(sessionKey, "dingtalk:") {
return nil, fmt.Errorf("skip: key %q is not a dingtalk key", sessionKey)
}
return platform.ReconstructReplyCtx(sessionKey)
} Type guard
func isDingtalkSessionKey(key string) bool {
return strings.HasPrefix(key, "dingtalk:")
} Try / catch
ctx, err := platform.ReconstructReplyCtx(sessionKey)
if err != nil {
if strings.Contains(err.Error(), "not a dingtalk session key") {
// route to the platform that owns this key instead
slog.Warn("wrong platform for key; lookup owning platform", "key", sessionKey)
return handleWrongPlatform(sessionKey)
}
return err
} Prevention
- Namespace stored session keys by platform and route reconstruction by prefix.
- Never hand-build session keys; always capture them from the adapter.
- When exporting/importing sessions across platforms, filter keys by prefix first.
- Validate platform config (send/cron targets) references keys from the configured platform.
When it happens
Trigger: Calling ReconstructReplyCtx with a session key generated by a different platform adapter, or with an arbitrary/corrupted string (empty, renamed, or hand-built key lacking the 'dingtalk:' prefix).
Common situations: Storing session keys from mixed platforms in one database and replaying them to the wrong adapter; config pointing a cron/webhook at the wrong platform's session key; manual key construction after an upgrade changed the format.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- dingtalk: invalid session key format: %q
- dingtalk: invalid conversation type %q in session key: %q
- dingtalk: empty conversationId in session key: %q
- dingtalk: client_id and client_secret are required
- dingtalk: robot_code is required (or client_id)
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/45eeabea9d71c101.
Report an issue: GitHub.