@soimy/dingtalk 3.5.3 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/onboarding.ts CHANGED
@@ -6,9 +6,13 @@ import type {
6
6
  WizardPrompter,
7
7
  } from "openclaw/plugin-sdk/setup";
8
8
  import { DEFAULT_ACCOUNT_ID, formatDocsLink, normalizeAccountId } from "openclaw/plugin-sdk/setup";
9
- import { DEFAULT_MESSAGE_CONTEXT_TTL_DAYS } from "./message-context-store.js";
9
+ import { listDingTalkAccountIds, resolveDingTalkAccount } from "./config.js";
10
+ import {
11
+ beginDeviceRegistration,
12
+ openUrlInBrowser,
13
+ RegistrationError,
14
+ } from "./device-registration.js";
10
15
  import type { DingTalkConfig, DingTalkChannelConfig } from "./types.js";
11
- import { listDingTalkAccountIds, resolveDingTalkAccount } from "./types.js";
12
16
 
13
17
  const channel = "dingtalk" as const;
14
18
 
@@ -16,13 +20,6 @@ function isConfigured(account: DingTalkConfig): boolean {
16
20
  return Boolean(account.clientId && account.clientSecret);
17
21
  }
18
22
 
19
- function parseList(value: string): string[] {
20
- return value
21
- .split(/[\n,;]+/g)
22
- .map((entry) => entry.trim())
23
- .filter(Boolean);
24
- }
25
-
26
23
  function applyAccountNameToChannelSection(params: {
27
24
  cfg: OpenClawConfig;
28
25
  channelKey: string;
@@ -52,33 +49,62 @@ async function promptDingTalkAccountId(options: {
52
49
  defaultAccountId: string;
53
50
  }): Promise<string> {
54
51
  const existingIds = options.listAccountIds(options.cfg);
55
- if (existingIds.length === 0) {
52
+ const hasDefault = existingIds.includes(options.defaultAccountId);
53
+ const namedIds = existingIds.filter((id) => id !== options.defaultAccountId);
54
+ const action = await options.prompter.select({
55
+ message: `Choose ${options.label} account`,
56
+ options: [
57
+ {
58
+ label: hasDefault ? "Configure default account" : "Add default account",
59
+ value: "default",
60
+ },
61
+ ...(namedIds.length > 0
62
+ ? [{ label: "Modify existing named account", value: "existing" }]
63
+ : []),
64
+ { label: "Add named account", value: "new" },
65
+ ],
66
+ initialValue: hasDefault ? "default" : namedIds.length > 0 ? "existing" : "default",
67
+ });
68
+
69
+ if (action === "default") {
56
70
  return options.defaultAccountId;
57
71
  }
58
- const useExisting = await options.prompter.confirm({
59
- message: `Use existing ${options.label} account?`,
60
- initialValue: true,
61
- });
62
- if (useExisting) {
63
- if (existingIds.includes(options.currentId)) {
64
- return options.currentId;
65
- }
72
+
73
+ if (action === "existing") {
66
74
  const selected = await options.prompter.select({
67
75
  message: `Select existing ${options.label} account`,
68
- options: existingIds.map((accountId) => ({
76
+ options: namedIds.map((accountId) => ({
69
77
  label: accountId,
70
78
  value: accountId,
71
79
  })),
72
- initialValue: existingIds[0],
80
+ initialValue: namedIds[0],
73
81
  });
74
82
  return normalizeAccountId(String(selected));
75
83
  }
76
- const newId = await options.prompter.text({
77
- message: `New ${options.label} account ID`,
78
- placeholder: options.defaultAccountId,
79
- initialValue: options.defaultAccountId,
80
- });
81
- return normalizeAccountId(String(newId));
84
+
85
+ while (true) {
86
+ const raw = await options.prompter.text({
87
+ message: `New ${options.label} account ID`,
88
+ placeholder: "work",
89
+ initialValue: "",
90
+ });
91
+ const normalized = normalizeAccountId(String(raw));
92
+ if (!normalized || normalized === options.defaultAccountId) {
93
+ await options.prompter.note(
94
+ "Enter a non-default account ID, for example: work",
95
+ "DingTalk account",
96
+ );
97
+ continue;
98
+ }
99
+ if (existingIds.includes(normalized)) {
100
+ await options.prompter.note(
101
+ `Account "${normalized}" already exists. Choose Modify existing named account to edit it.`,
102
+ "DingTalk account",
103
+ );
104
+ continue;
105
+ }
106
+ return normalized;
107
+ }
82
108
  }
83
109
 
84
110
  async function noteDingTalkHelp(prompter: WizardPrompter): Promise<void> {
@@ -96,6 +122,141 @@ async function noteDingTalkHelp(prompter: WizardPrompter): Promise<void> {
96
122
  );
97
123
  }
98
124
 
125
+ async function noteDmAllowlistGuidance(prompter: WizardPrompter): Promise<void> {
126
+ await prompter.note(
127
+ [
128
+ "DM allowlist requires DingTalk userId values.",
129
+ "Ask each target user to send a direct message to this bot.",
130
+ "The plugin will show the observed userId so an admin can add it to channels.dingtalk.allowFrom.",
131
+ ].join("\n"),
132
+ "DingTalk DM allowlist",
133
+ );
134
+ }
135
+
136
+ async function noteGroupAllowlistGuidance(prompter: WizardPrompter): Promise<void> {
137
+ await prompter.note(
138
+ [
139
+ "Group allowlist requires DingTalk conversationId values.",
140
+ "Ask a member to @mention this bot in the target group.",
141
+ "The plugin will show the observed group ID so an admin can configure channels.dingtalk.groups or related allowlist settings.",
142
+ ].join("\n"),
143
+ "DingTalk group allowlist",
144
+ );
145
+ }
146
+
147
+ async function noteDingTalkSetupComplete(prompter: WizardPrompter): Promise<void> {
148
+ await prompter.note(
149
+ [
150
+ "DingTalk configuration has been saved.",
151
+ "For named accounts, configuration lives under channels.dingtalk.accounts.",
152
+ "If you selected allowlist policies, ask the target user or group to message this bot first; the plugin will show IDs that an admin can add manually.",
153
+ "Advanced runtime settings can be edited in the config UI or openclaw.json.",
154
+ "Restart the gateway to apply changes:",
155
+ " openclaw gateway restart",
156
+ ].join("\n"),
157
+ "DingTalk setup complete",
158
+ );
159
+ }
160
+
161
+ function validateMinInteger(min: number) {
162
+ return (value: string): string | undefined => {
163
+ const raw = String(value ?? "").trim();
164
+ const num = Number(raw);
165
+ if (!raw) {
166
+ return "Required";
167
+ }
168
+ if (!Number.isInteger(num) || num < min) {
169
+ return `Must be an integer >= ${min}`;
170
+ }
171
+ return undefined;
172
+ };
173
+ }
174
+
175
+ type CardAdvancedConfig = Partial<
176
+ Pick<
177
+ DingTalkConfig,
178
+ "cardStreamingMode" | "cardStreamInterval" | "cardAtSender" | "cardStatusLine"
179
+ >
180
+ >;
181
+
182
+ async function promptCardAdvancedConfig(params: {
183
+ resolved: DingTalkConfig;
184
+ prompter: WizardPrompter;
185
+ }): Promise<CardAdvancedConfig> {
186
+ const { resolved, prompter } = params;
187
+ const cardStreamingMode = (await prompter.select({
188
+ message: "Card streaming mode",
189
+ options: [
190
+ { label: "Off - answer does not stream incrementally", value: "off" },
191
+ { label: "Answer - only answer streams incrementally", value: "answer" },
192
+ { label: "All - answer and thinking stream incrementally", value: "all" },
193
+ ],
194
+ initialValue: resolved.cardStreamingMode ?? (resolved.cardRealTimeStream ? "all" : "off"),
195
+ })) as DingTalkConfig["cardStreamingMode"];
196
+
197
+ const cardStreamInterval = Number(
198
+ String(
199
+ await prompter.text({
200
+ message: "Card stream interval (ms)",
201
+ placeholder: "1000",
202
+ initialValue: String(resolved.cardStreamInterval ?? 1000),
203
+ validate: validateMinInteger(200),
204
+ }),
205
+ ).trim(),
206
+ );
207
+
208
+ const cardAtSenderRaw = String(
209
+ await prompter.text({
210
+ message: "Card completion @mention text (optional)",
211
+ placeholder: "Reply complete",
212
+ initialValue: resolved.cardAtSender || undefined,
213
+ }),
214
+ ).trim();
215
+
216
+ const wantsStatusLine = await prompter.confirm({
217
+ message: "Customize AI card status line?",
218
+ initialValue: Boolean(resolved.cardStatusLine),
219
+ });
220
+
221
+ let cardStatusLine: DingTalkConfig["cardStatusLine"] | undefined;
222
+ if (wantsStatusLine) {
223
+ const current = resolved.cardStatusLine ?? {};
224
+ cardStatusLine = {
225
+ model: await prompter.confirm({
226
+ message: "Show model name?",
227
+ initialValue: current.model ?? true,
228
+ }),
229
+ effort: await prompter.confirm({
230
+ message: "Show thinking effort?",
231
+ initialValue: current.effort ?? true,
232
+ }),
233
+ agent: await prompter.confirm({
234
+ message: "Show agent name?",
235
+ initialValue: current.agent ?? true,
236
+ }),
237
+ taskTime: await prompter.confirm({
238
+ message: "Show task elapsed time?",
239
+ initialValue: current.taskTime ?? false,
240
+ }),
241
+ tokens: await prompter.confirm({
242
+ message: "Show token usage?",
243
+ initialValue: current.tokens ?? false,
244
+ }),
245
+ dapiUsage: await prompter.confirm({
246
+ message: "Show DingTalk API usage?",
247
+ initialValue: current.dapiUsage ?? false,
248
+ }),
249
+ };
250
+ }
251
+
252
+ return {
253
+ cardStreamingMode,
254
+ cardStreamInterval,
255
+ ...(cardAtSenderRaw ? { cardAtSender: cardAtSenderRaw } : {}),
256
+ ...(cardStatusLine ? { cardStatusLine } : {}),
257
+ };
258
+ }
259
+
99
260
  function applyAccountConfig(params: {
100
261
  cfg: OpenClawConfig;
101
262
  accountId: string;
@@ -128,6 +289,11 @@ function applyAccountConfig(params: {
128
289
  : {}),
129
290
  ...(input.messageType ? { messageType: input.messageType } : {}),
130
291
  ...(input.cardStreamingMode ? { cardStreamingMode: input.cardStreamingMode } : {}),
292
+ ...(typeof input.cardStreamInterval === "number"
293
+ ? { cardStreamInterval: input.cardStreamInterval }
294
+ : {}),
295
+ ...(input.cardAtSender ? { cardAtSender: input.cardAtSender } : {}),
296
+ ...(input.cardStatusLine ? { cardStatusLine: input.cardStatusLine } : {}),
131
297
  ...(typeof input.maxReconnectCycles === "number"
132
298
  ? { maxReconnectCycles: input.maxReconnectCycles }
133
299
  : {}),
@@ -193,18 +359,6 @@ function applyGenericSetupInput(params: {
193
359
  });
194
360
  }
195
361
 
196
- function validatePositiveInteger(value: string): string | undefined {
197
- const raw = String(value ?? "").trim();
198
- const num = Number(raw);
199
- if (!raw) {
200
- return "Required";
201
- }
202
- if (!Number.isInteger(num) || num < 1) {
203
- return "Must be an integer >= 1";
204
- }
205
- return undefined;
206
- }
207
-
208
362
  async function configureDingTalkAccount(params: {
209
363
  cfg: OpenClawConfig;
210
364
  accountId: string;
@@ -213,237 +367,171 @@ async function configureDingTalkAccount(params: {
213
367
  const { cfg, accountId, prompter } = params;
214
368
  const resolved = resolveDingTalkAccount(cfg, accountId);
215
369
 
216
- await noteDingTalkHelp(prompter);
217
-
218
- const clientId = await prompter.text({
219
- message: "Client ID (AppKey)",
220
- placeholder: "dingxxxxxxxx",
221
- initialValue: resolved.clientId ?? undefined,
222
- validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
223
- });
224
-
225
- const clientSecret = await prompter.text({
226
- message: "Client Secret (AppSecret)",
227
- placeholder: "xxx-xxx-xxx-xxx",
228
- initialValue: resolved.clientSecret ?? undefined,
229
- validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
230
- });
231
-
232
- const wantsCardMode = await prompter.confirm({
233
- message: "Enable AI interactive card mode? (for streaming AI responses)",
234
- initialValue: resolved.messageType === "card",
370
+ // ── Credential acquisition: auto-register or manual ────────────────────
371
+ const hasExistingCredentials = Boolean(resolved.clientId && resolved.clientSecret);
372
+ const credentialMethod = await prompter.select({
373
+ message: "How do you want to get DingTalk bot credentials?",
374
+ options: [
375
+ { label: "Auto-register an OpenClaw DingTalk bot", value: "auto" },
376
+ { label: "Enter an existing DingTalk bot Client ID / Client Secret", value: "manual" },
377
+ ],
378
+ initialValue: hasExistingCredentials ? "manual" : "auto",
235
379
  });
236
380
 
237
- let messageType: "markdown" | "card" = "markdown";
238
- let cardStreamingMode: DingTalkConfig["cardStreamingMode"];
239
-
240
- if (wantsCardMode) {
241
- await prompter.note(
242
- [
243
- "AI interactive card mode now uses the built-in DingTalk template contract.",
244
- "No manual Template ID or content field configuration is required.",
245
- "Legacy cardTemplateId/cardTemplateKey config is deprecated and ignored.",
246
- ].join("\n"),
247
- "Built-in AI Card Template",
248
- );
249
- messageType = "card";
250
- cardStreamingMode = (await prompter.select({
251
- message: "Card streaming mode",
252
- options: [
253
- { label: "Off - answer does not stream incrementally", value: "off" },
254
- { label: "Answer - only answer streams incrementally", value: "answer" },
255
- { label: "All - answer and thinking stream incrementally", value: "all" },
256
- ],
257
- initialValue: resolved.cardStreamingMode ?? (resolved.cardRealTimeStream ? "all" : "off"),
258
- })) as DingTalkConfig["cardStreamingMode"];
381
+ let clientId: string;
382
+ let clientSecret: string;
383
+
384
+ if (credentialMethod === "auto") {
385
+ try {
386
+ const session = await beginDeviceRegistration();
387
+
388
+ openUrlInBrowser(session.verificationUrl);
389
+
390
+ await prompter.note(
391
+ [
392
+ "Opened the authorization page in your browser.",
393
+ "Scan the authorization code in DingTalk to finish registration.",
394
+ "",
395
+ "If the browser did not open automatically, visit this link manually:",
396
+ session.verificationUrl,
397
+ ].join("\n"),
398
+ "DingTalk bot auto-registration",
399
+ );
400
+
401
+ let lastWaitingNote = 0;
402
+ const result = await session.waitForResult({
403
+ onWaiting: () => {
404
+ const now = Date.now();
405
+ if (now - lastWaitingNote >= 15_000) {
406
+ lastWaitingNote = now;
407
+ prompter
408
+ .note("Waiting for authorization. Please finish the scan in DingTalk...", "Polling")
409
+ .catch(() => {});
410
+ }
411
+ },
412
+ });
413
+ clientId = result.clientId;
414
+ clientSecret = result.clientSecret;
415
+
416
+ await prompter.note(
417
+ [
418
+ "Registration succeeded!",
419
+ `Client ID: ${clientId}`,
420
+ "Client Secret: [captured; see config file]",
421
+ ].join("\n"),
422
+ "Registration complete",
423
+ );
424
+ } catch (err) {
425
+ const message = err instanceof RegistrationError ? err.message : String(err);
426
+ await prompter.note(
427
+ [`Auto-registration failed: ${message}`, "", "Falling back to manual input."].join("\n"),
428
+ "Registration failed",
429
+ );
430
+ // Fall through to manual path
431
+ await noteDingTalkHelp(prompter);
432
+ clientId = String(
433
+ await prompter.text({
434
+ message: "Client ID (AppKey)",
435
+ placeholder: "dingxxxxxxxx",
436
+ initialValue: resolved.clientId ?? undefined,
437
+ validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
438
+ }),
439
+ ).trim();
440
+ clientSecret = String(
441
+ await prompter.text({
442
+ message: "Client Secret (AppSecret)",
443
+ placeholder: "xxx-xxx-xxx-xxx",
444
+ initialValue: resolved.clientSecret ?? undefined,
445
+ validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
446
+ }),
447
+ ).trim();
448
+ }
449
+ } else {
450
+ // Manual path — existing behavior
451
+ await noteDingTalkHelp(prompter);
452
+ clientId = String(
453
+ await prompter.text({
454
+ message: "Client ID (AppKey)",
455
+ placeholder: "dingxxxxxxxx",
456
+ initialValue: resolved.clientId ?? undefined,
457
+ validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
458
+ }),
459
+ ).trim();
460
+ clientSecret = String(
461
+ await prompter.text({
462
+ message: "Client Secret (AppSecret)",
463
+ placeholder: "xxx-xxx-xxx-xxx",
464
+ initialValue: resolved.clientSecret ?? undefined,
465
+ validate: (value: string) => (String(value ?? "").trim() ? undefined : "Required"),
466
+ }),
467
+ ).trim();
259
468
  }
260
469
 
261
- const dmPolicyValue = await prompter.select({
470
+ const dmPolicyValue = (await prompter.select({
262
471
  message: "Direct message policy",
263
472
  options: [
264
473
  { label: "Open - anyone can DM", value: "open" },
265
- { label: "Allowlist - only allowed users", value: "allowlist" },
474
+ { label: "Pairing - require OpenClaw pairing approval", value: "pairing" },
475
+ { label: "Allowlist - only manually allowed users", value: "allowlist" },
266
476
  ],
267
477
  initialValue: resolved.dmPolicy ?? "open",
268
- });
478
+ })) as "open" | "pairing" | "allowlist";
269
479
 
270
- let allowFrom: string[] | undefined;
271
480
  if (dmPolicyValue === "allowlist") {
272
- const entry = await prompter.text({
273
- message: "Allowed user IDs (comma-separated)",
274
- placeholder: "user1, user2",
275
- });
276
- const parsed = parseList(String(entry ?? ""));
277
- allowFrom = parsed.length > 0 ? parsed : undefined;
481
+ await noteDmAllowlistGuidance(prompter);
278
482
  }
279
483
 
280
- const mediaUrlAllowlistEntry = await prompter.text({
281
- message: "Media URL allowlist (comma-separated host/IP/CIDR, optional)",
282
- placeholder: "cdn.example.com, 192.168.1.23, 10.0.0.0/8",
283
- initialValue: (resolved.mediaUrlAllowlist || []).join(", ") || undefined,
284
- });
285
- const mediaUrlAllowlistParsed = parseList(String(mediaUrlAllowlistEntry ?? ""));
286
- const mediaUrlAllowlist = mediaUrlAllowlistParsed.length > 0 ? mediaUrlAllowlistParsed : undefined;
287
-
288
- const groupPolicyValue = await prompter.select({
484
+ const groupPolicyValue = (await prompter.select({
289
485
  message: "Group message policy",
290
486
  options: [
291
487
  { label: "Open - any group can use bot", value: "open" },
292
- { label: "Allowlist - only allowed groups", value: "allowlist" },
488
+ { label: "Allowlist - only manually configured groups", value: "allowlist" },
293
489
  { label: "Disabled - block all group messages", value: "disabled" },
294
490
  ],
295
491
  initialValue: resolved.groupPolicy ?? "open",
296
- });
492
+ })) as "open" | "allowlist" | "disabled";
297
493
 
298
494
  if (groupPolicyValue === "allowlist") {
299
- await prompter.note(
300
- [
301
- 'groupPolicy=allowlist requires "groups" config to specify allowed group IDs.',
302
- "After setup, manually add group conversationIds to your config:",
303
- "",
304
- ' "groups": { "cidXXX": {}, "cidYYY": { "systemPrompt": "..." } }',
305
- "",
306
- 'Groups not listed will be blocked. Use "*" as key to allow all groups.',
307
- ].join("\n"),
308
- );
495
+ await noteGroupAllowlistGuidance(prompter);
309
496
  }
310
497
 
311
- let groupAllowFrom: string[] | undefined;
312
- if (groupPolicyValue !== "disabled") {
313
- const groupAllowFromEntry = await prompter.text({
314
- message: "Group sender allowlist - user IDs allowed in groups (comma-separated, optional)",
315
- placeholder: "user1, user2",
316
- initialValue: (resolved.groupAllowFrom || []).join(", ") || undefined,
317
- });
318
- const parsedGroupAllowFrom = parseList(String(groupAllowFromEntry ?? ""));
319
- groupAllowFrom = parsedGroupAllowFrom.length > 0 ? parsedGroupAllowFrom : undefined;
320
- }
321
-
322
- await prompter.note(
323
- [
324
- "Enabling learned displayName target resolution has tradeoffs:",
325
- "- learned names come from observed inbound messages and can become stale",
326
- "- duplicate display names can resolve to the wrong group or user",
327
- '- current upstream target resolution does not provide requester authz, so "all" applies to every caller that can reach the send flow',
328
- "Use explicit IDs for sensitive or high-risk deliveries.",
329
- ].join("\n"),
330
- "displayName resolution risk",
331
- );
332
-
333
- const displayNameResolutionValue = await prompter.select({
334
- message: "Learned displayName target resolution",
498
+ const messageType = (await prompter.select({
499
+ message: "Reply message type",
335
500
  options: [
336
- {
337
- label: "Disabled - require explicit IDs",
338
- value: "disabled",
339
- },
340
- {
341
- label: "All - learned lookup for all callers (higher risk)",
342
- value: "all",
343
- },
501
+ { label: "Markdown - standard DingTalk messages", value: "markdown" },
502
+ { label: "AI Card - interactive card replies", value: "card" },
344
503
  ],
345
- initialValue: resolved.displayNameResolution ?? "disabled",
346
- });
504
+ initialValue: resolved.messageType ?? "markdown",
505
+ })) as "markdown" | "card";
347
506
 
348
- await prompter.note(
349
- [
350
- "Advanced host context visibility is available as channels.dingtalk.contextVisibility.",
351
- "Recommended advanced mode: allowlist_quote.",
352
- "Modes:",
353
- "- all: preserve the current host supplemental-context behavior",
354
- "- allowlist: keep only host allowlisted supplemental context",
355
- "- allowlist_quote: keep explicit quote/reply context while filtering extra context",
356
- "This is separate from displayNameResolution and should be set manually if needed.",
357
- resolved.contextVisibility
358
- ? `Current resolved value: ${resolved.contextVisibility}`
359
- : "Current resolved value: host default",
360
- ].join("\n"),
361
- "Advanced context visibility",
362
- );
363
-
364
- let maxReconnectCycles: number | undefined;
365
- const wantsReconnectLimits = await prompter.confirm({
366
- message: "Configure runtime reconnect cycle limit? (recommended)",
367
- initialValue: typeof resolved.maxReconnectCycles === "number",
507
+ const wantsAdvanced = await prompter.confirm({
508
+ message: "Configure advanced DingTalk options?",
509
+ initialValue: false,
368
510
  });
369
- if (wantsReconnectLimits) {
370
- const parsedCycles = Number(
371
- String(
372
- await prompter.text({
373
- message: "Max runtime reconnect cycles",
374
- placeholder: "10",
375
- initialValue: String(resolved.maxReconnectCycles ?? 10),
376
- validate: (value: string) => validatePositiveInteger(value),
377
- }),
378
- ).trim(),
379
- );
380
- maxReconnectCycles = Number.isInteger(parsedCycles) && parsedCycles > 0 ? parsedCycles : 10;
381
- }
382
-
383
- let mediaMaxMb: number | undefined;
384
- const wantsMediaMax = await prompter.confirm({
385
- message: "Configure inbound media max size in MB? (optional)",
386
- initialValue: typeof resolved.mediaMaxMb === "number",
387
- });
388
- if (wantsMediaMax) {
389
- const parsedMediaMax = Number(
390
- String(
391
- await prompter.text({
392
- message: "Max inbound media size (MB)",
393
- placeholder: "20",
394
- initialValue:
395
- typeof resolved.mediaMaxMb === "number" ? String(resolved.mediaMaxMb) : "20",
396
- validate: (value: string) => validatePositiveInteger(value),
397
- }),
398
- ).trim(),
399
- );
400
- mediaMaxMb = Number.isInteger(parsedMediaMax) && parsedMediaMax > 0 ? parsedMediaMax : 20;
401
- }
402
-
403
- let journalTTLDays: number | undefined;
404
- const wantsJournalTTL = await prompter.confirm({
405
- message: "Configure quote journal retention in days?",
406
- initialValue: typeof resolved.journalTTLDays === "number",
407
- });
408
- if (wantsJournalTTL) {
409
- const parsedJournalTTL = Number(
410
- String(
411
- await prompter.text({
412
- message: "Quote journal retention days",
413
- placeholder: String(DEFAULT_MESSAGE_CONTEXT_TTL_DAYS),
414
- initialValue:
415
- typeof resolved.journalTTLDays === "number"
416
- ? String(resolved.journalTTLDays)
417
- : String(DEFAULT_MESSAGE_CONTEXT_TTL_DAYS),
418
- validate: (value: string) => validatePositiveInteger(value),
419
- }),
420
- ).trim(),
511
+ let cardAdvanced: CardAdvancedConfig = {};
512
+ if (wantsAdvanced && messageType === "card") {
513
+ cardAdvanced = await promptCardAdvancedConfig({ resolved, prompter });
514
+ } else if (wantsAdvanced) {
515
+ await prompter.note(
516
+ "No markdown-specific advanced onboarding options are required. Other advanced settings can be edited in the config UI or openclaw.json.",
517
+ "DingTalk advanced options",
421
518
  );
422
- journalTTLDays =
423
- Number.isInteger(parsedJournalTTL) && parsedJournalTTL > 0
424
- ? parsedJournalTTL
425
- : DEFAULT_MESSAGE_CONTEXT_TTL_DAYS;
426
519
  }
427
520
 
428
- return applyAccountConfig({
521
+ const nextCfg = applyAccountConfig({
429
522
  cfg,
430
523
  accountId,
431
524
  input: {
432
525
  clientId: String(clientId).trim(),
433
526
  clientSecret: String(clientSecret).trim(),
434
- dmPolicy: dmPolicyValue as "open" | "allowlist",
435
- groupPolicy: groupPolicyValue as "open" | "allowlist" | "disabled",
436
- allowFrom,
437
- groupAllowFrom,
438
- displayNameResolution: displayNameResolutionValue as "disabled" | "all",
439
- mediaUrlAllowlist,
527
+ dmPolicy: dmPolicyValue,
528
+ groupPolicy: groupPolicyValue,
440
529
  messageType,
441
- cardStreamingMode,
442
- maxReconnectCycles,
443
- mediaMaxMb,
444
- journalTTLDays,
530
+ ...cardAdvanced,
445
531
  },
446
532
  });
533
+ await noteDingTalkSetupComplete(prompter);
534
+ return nextCfg;
447
535
  }
448
536
 
449
537
  export const dingtalkSetupAdapter: ChannelSetupAdapter = {
@@ -474,9 +562,10 @@ export const dingtalkSetupWizard: ChannelSetupWizard = {
474
562
  `DingTalk: ${configured ? "configured" : "needs setup"}`,
475
563
  ],
476
564
  resolveSelectionHint: ({ configured }) =>
477
- configured ? "configured" : "钉钉企业机器人",
565
+ configured ? "configured" : "DingTalk enterprise bot",
478
566
  resolveQuickstartScore: ({ configured }) => (configured ? 1 : 4),
479
567
  },
568
+ resolveShouldPromptAccountIds: () => true,
480
569
  resolveAccountIdForConfigure: async ({
481
570
  cfg,
482
571
  prompter,