chenhg5/cc-connect · error

dingtalk: client_id and client_secret are required

Error message

dingtalk: client_id and client_secret are required

What it means

The DingTalk platform constructor (New) validates that the required credentials are present in the options map before building the Platform. It throws this error when either the 'client_id' or 'client_secret' option is empty or not a string, because without them no API calls (access tokens, message sending) can be authenticated.

Source

Thrown at platform/dingtalk/dingtalk.go:105

	reactionEmoji         string
	doneEmoji             string
	// AI Card configuration
	cardTemplateID  string
	cardTemplateKey string
	cardThrottleMs  int
	degradeUntil    time.Time
	degradeMu       sync.Mutex
}

func New(opts map[string]any) (core.Platform, error) {
	clientID, _ := opts["client_id"].(string)
	clientSecret, _ := opts["client_secret"].(string)
	robotCode, _ := opts["robot_code"].(string)
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("dingtalk", allowFrom)
	shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
	if clientID == "" || clientSecret == "" {
		return nil, fmt.Errorf("dingtalk: client_id and client_secret are required")
	}
	if robotCode == "" {
		robotCode = clientID // fallback to client_id if robot_code not specified
	}
	// Validate robot_code format (should not be empty after fallback)
	if robotCode == "" {
		return nil, fmt.Errorf("dingtalk: robot_code is required (or client_id)")
	}

	reactionEmoji, _ := opts["reaction_emoji"].(string)
	reactionEmoji = strings.TrimSpace(reactionEmoji)
	if reactionEmoji == "" {
		reactionEmoji = defaultReactionEmoji
	}
	if strings.EqualFold(reactionEmoji, "none") {
		reactionEmoji = ""
	}
	doneEmoji, _ := opts["done_emoji"].(string)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set both 'client_id' and 'client_secret' string options in your dingtalk config to valid AppKey/AppSecret values from the DingTalk open platform.
  2. Check that environment variables feeding these options are actually set and non-empty at startup.
  3. Verify the option keys are exactly 'client_id' and 'client_secret' and the values are plain Go strings, not other types.

Example fix

// before
p, err := dingtalk.New(map[string]any{"client_id": "", "client_secret": os.Getenv("DM_SECRET")})
// after
clientID := os.Getenv("DINGTALK_CLIENT_ID")
clientSecret := os.Getenv("DINGTALK_CLIENT_SECRET")
if clientID == "" || clientSecret == "" { log.Fatal("dingtalk credentials missing") }
p, err := dingtalk.New(map[string]any{"client_id": clientID, "client_secret": clientSecret})
Defensive patterns

Strategy: validation

Validate before calling

func validateDingtalkOpts(opts map[string]any) error {
    id, _ := opts["client_id"].(string)
    sec, _ := opts["client_secret"].(string)
    if id == "" || sec == "" {
        return fmt.Errorf("dingtalk: need non-empty client_id and client_secret (got id=%q, secret set=%t)", id, sec != "")
    }
    return nil
}

Type guard

func optString(opts map[string]any, key string) (string, bool) {
    s, ok := opts[key].(string)
    return s, ok && s != ""
}

Prevention

When it happens

Trigger: Calling dingtalk.New(opts) where opts lacks 'client_id'/'client_secret' keys, they are set to empty strings, or they hold non-string values (the type assertion `opts["client_id"].(string)` silently yields "" on wrong types).

Common situations: Config mistakes: copying a config.toml block and forgetting to fill in credentials; reading values from environment variables that are unset; passing YAML/JSON-decoded values where numbers or nested objects end up in place of strings; typos in option keys like 'clientId'.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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