@yanhaidao/wecom 2.3.260 → 2.3.270
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/README.md +10 -5
- package/changelog/v2.3.27.md +33 -0
- package/index.test.ts +5 -1
- package/package.json +17 -17
- package/src/app/index.ts +6 -3
- package/src/capability/mcp/tool.ts +7 -3
- package/src/channel.meta.test.ts +4 -0
- package/src/channel.ts +29 -59
- package/src/onboarding.test.ts +42 -24
- package/src/onboarding.ts +598 -553
- package/src/outbound.ts +17 -11
- package/src/transport/bot-ws/media.test.ts +8 -8
- package/src/transport/bot-ws/media.ts +51 -2
- package/src/transport/bot-ws/sdk-adapter.ts +6 -6
package/src/onboarding.ts
CHANGED
|
@@ -3,14 +3,21 @@
|
|
|
3
3
|
* 支持 Bot、Agent 和双模式同时启动的交互式配置流程
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
ChannelOnboardingAdapter,
|
|
8
|
-
OpenClawConfig,
|
|
9
|
-
WizardPrompter,
|
|
10
|
-
} from "openclaw/plugin-sdk";
|
|
11
6
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/routing";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
7
|
+
import type { ChannelSetupWizard, OpenClawConfig, WizardPrompter } from "openclaw/plugin-sdk/setup";
|
|
8
|
+
import {
|
|
9
|
+
listWecomAccountIds,
|
|
10
|
+
resolveDefaultWecomAccountId,
|
|
11
|
+
resolveWecomAccount,
|
|
12
|
+
resolveWecomAccounts,
|
|
13
|
+
} from "./config/index.js";
|
|
14
|
+
import type {
|
|
15
|
+
WecomConfig,
|
|
16
|
+
WecomBotConfig,
|
|
17
|
+
WecomAgentConfig,
|
|
18
|
+
WecomDmConfig,
|
|
19
|
+
WecomAccountConfig,
|
|
20
|
+
} from "./types/index.js";
|
|
14
21
|
|
|
15
22
|
const channel = "wecom" as const;
|
|
16
23
|
|
|
@@ -21,266 +28,271 @@ type WecomMode = "bot" | "agent" | "both";
|
|
|
21
28
|
// ============================================================
|
|
22
29
|
|
|
23
30
|
function getWecomConfig(cfg: OpenClawConfig): WecomConfig | undefined {
|
|
24
|
-
|
|
31
|
+
return cfg.channels?.wecom as WecomConfig | undefined;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
function setWecomEnabled(cfg: OpenClawConfig, enabled: boolean): OpenClawConfig {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return {
|
|
36
|
+
...cfg,
|
|
37
|
+
channels: {
|
|
38
|
+
...cfg.channels,
|
|
39
|
+
wecom: {
|
|
40
|
+
...(cfg.channels?.wecom ?? {}),
|
|
41
|
+
enabled,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
} as OpenClawConfig;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
function shouldUseAccountScopedConfig(wecom: WecomConfig | undefined, accountId: string): boolean {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
void wecom;
|
|
49
|
+
void accountId;
|
|
50
|
+
return true;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
function ensureMatrixAccounts(wecom: WecomConfig): WecomConfig {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
const accounts = wecom.accounts ?? {};
|
|
55
|
+
if (Object.keys(accounts).length > 0) {
|
|
56
|
+
return wecom;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!wecom.bot && !wecom.agent) {
|
|
60
|
+
return wecom;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { bot: legacyBot, agent: legacyAgent, ...rest } = wecom;
|
|
64
|
+
const defaultAccount: WecomAccountConfig = {
|
|
65
|
+
enabled: true,
|
|
66
|
+
...(legacyBot ? { bot: legacyBot } : {}),
|
|
67
|
+
...(legacyAgent ? { agent: legacyAgent } : {}),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...rest,
|
|
72
|
+
defaultAccount: rest.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
73
|
+
accounts: {
|
|
74
|
+
[DEFAULT_ACCOUNT_ID]: defaultAccount,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
function accountWebhookPath(kind: "bot" | "agent", accountId: string): string {
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const recommendedBase = kind === "bot" ? "/plugins/wecom/bot" : "/plugins/wecom/agent";
|
|
81
|
+
return `${recommendedBase}/${accountId}`;
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
function setWecomBotConfig(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
wecom: {
|
|
85
|
-
...wecom,
|
|
86
|
-
enabled: true,
|
|
87
|
-
bot: {
|
|
88
|
-
...wecom.bot,
|
|
89
|
-
...bot,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
} as OpenClawConfig;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
97
|
-
const accounts = matrixWecom.accounts ?? {};
|
|
98
|
-
const existingAccount = accounts[accountId] ?? {};
|
|
99
|
-
const existingBot = existingAccount.bot;
|
|
84
|
+
function setWecomBotConfig(
|
|
85
|
+
cfg: OpenClawConfig,
|
|
86
|
+
bot: WecomBotConfig,
|
|
87
|
+
accountId: string,
|
|
88
|
+
): OpenClawConfig {
|
|
89
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
90
|
+
if (!shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
100
91
|
return {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...existingAccount,
|
|
112
|
-
enabled: existingAccount.enabled ?? true,
|
|
113
|
-
bot: {
|
|
114
|
-
...existingBot,
|
|
115
|
-
...bot,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
92
|
+
...cfg,
|
|
93
|
+
channels: {
|
|
94
|
+
...cfg.channels,
|
|
95
|
+
wecom: {
|
|
96
|
+
...wecom,
|
|
97
|
+
enabled: true,
|
|
98
|
+
bot: {
|
|
99
|
+
...wecom.bot,
|
|
100
|
+
...bot,
|
|
101
|
+
},
|
|
120
102
|
},
|
|
103
|
+
},
|
|
121
104
|
} as OpenClawConfig;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
108
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
109
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
110
|
+
const existingBot = existingAccount.bot;
|
|
111
|
+
return {
|
|
112
|
+
...cfg,
|
|
113
|
+
channels: {
|
|
114
|
+
...cfg.channels,
|
|
115
|
+
wecom: {
|
|
116
|
+
...matrixWecom,
|
|
117
|
+
enabled: true,
|
|
118
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
119
|
+
accounts: {
|
|
120
|
+
...accounts,
|
|
121
|
+
[accountId]: {
|
|
122
|
+
...existingAccount,
|
|
123
|
+
enabled: existingAccount.enabled ?? true,
|
|
124
|
+
bot: {
|
|
125
|
+
...existingBot,
|
|
126
|
+
...bot,
|
|
136
127
|
},
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
} as OpenClawConfig;
|
|
133
|
+
}
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
function setWecomAgentConfig(
|
|
136
|
+
cfg: OpenClawConfig,
|
|
137
|
+
agent: WecomAgentConfig,
|
|
138
|
+
accountId: string,
|
|
139
|
+
): OpenClawConfig {
|
|
140
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
141
|
+
if (!shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
143
142
|
return {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
accounts: {
|
|
152
|
-
...accounts,
|
|
153
|
-
[accountId]: {
|
|
154
|
-
...existingAccount,
|
|
155
|
-
enabled: existingAccount.enabled ?? true,
|
|
156
|
-
agent,
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
143
|
+
...cfg,
|
|
144
|
+
channels: {
|
|
145
|
+
...cfg.channels,
|
|
146
|
+
wecom: {
|
|
147
|
+
...wecom,
|
|
148
|
+
enabled: true,
|
|
149
|
+
agent,
|
|
160
150
|
},
|
|
151
|
+
},
|
|
161
152
|
} as OpenClawConfig;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
156
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
157
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
158
|
+
return {
|
|
159
|
+
...cfg,
|
|
160
|
+
channels: {
|
|
161
|
+
...cfg.channels,
|
|
162
|
+
wecom: {
|
|
163
|
+
...matrixWecom,
|
|
164
|
+
enabled: true,
|
|
165
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
166
|
+
accounts: {
|
|
167
|
+
...accounts,
|
|
168
|
+
[accountId]: {
|
|
169
|
+
...existingAccount,
|
|
170
|
+
enabled: existingAccount.enabled ?? true,
|
|
171
|
+
agent,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
} as OpenClawConfig;
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
function setWecomDmPolicy(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
180
|
+
cfg: OpenClawConfig,
|
|
181
|
+
mode: "bot" | "agent",
|
|
182
|
+
dm: WecomDmConfig,
|
|
183
|
+
accountId: string,
|
|
169
184
|
): OpenClawConfig {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
},
|
|
183
|
-
}
|
|
184
|
-
: {
|
|
185
|
-
...existingAccount,
|
|
186
|
-
agent: {
|
|
187
|
-
...existingAccount.agent,
|
|
188
|
-
dm,
|
|
189
|
-
},
|
|
190
|
-
} as WecomAccountConfig;
|
|
191
|
-
return {
|
|
192
|
-
...cfg,
|
|
193
|
-
channels: {
|
|
194
|
-
...cfg.channels,
|
|
195
|
-
wecom: {
|
|
196
|
-
...matrixWecom,
|
|
197
|
-
enabled: true,
|
|
198
|
-
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
199
|
-
accounts: {
|
|
200
|
-
...accounts,
|
|
201
|
-
[accountId]: {
|
|
202
|
-
...nextAccount,
|
|
203
|
-
enabled: nextAccount.enabled ?? true,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
185
|
+
const wecom = getWecomConfig(cfg) ?? {};
|
|
186
|
+
if (shouldUseAccountScopedConfig(wecom, accountId)) {
|
|
187
|
+
const matrixWecom = ensureMatrixAccounts(wecom);
|
|
188
|
+
const accounts = matrixWecom.accounts ?? {};
|
|
189
|
+
const existingAccount = accounts[accountId] ?? {};
|
|
190
|
+
const nextAccount =
|
|
191
|
+
mode === "bot"
|
|
192
|
+
? {
|
|
193
|
+
...existingAccount,
|
|
194
|
+
bot: {
|
|
195
|
+
...existingAccount.bot,
|
|
196
|
+
dm,
|
|
207
197
|
},
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
channels: {
|
|
215
|
-
...cfg.channels,
|
|
216
|
-
wecom: {
|
|
217
|
-
...wecom,
|
|
218
|
-
bot: {
|
|
219
|
-
...wecom.bot,
|
|
220
|
-
dm,
|
|
221
|
-
},
|
|
222
|
-
},
|
|
198
|
+
}
|
|
199
|
+
: ({
|
|
200
|
+
...existingAccount,
|
|
201
|
+
agent: {
|
|
202
|
+
...existingAccount.agent,
|
|
203
|
+
dm,
|
|
223
204
|
},
|
|
224
|
-
|
|
225
|
-
}
|
|
205
|
+
} as WecomAccountConfig);
|
|
226
206
|
return {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
207
|
+
...cfg,
|
|
208
|
+
channels: {
|
|
209
|
+
...cfg.channels,
|
|
210
|
+
wecom: {
|
|
211
|
+
...matrixWecom,
|
|
212
|
+
enabled: true,
|
|
213
|
+
defaultAccount: matrixWecom.defaultAccount?.trim() || DEFAULT_ACCOUNT_ID,
|
|
214
|
+
accounts: {
|
|
215
|
+
...accounts,
|
|
216
|
+
[accountId]: {
|
|
217
|
+
...nextAccount,
|
|
218
|
+
enabled: nextAccount.enabled ?? true,
|
|
236
219
|
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
} as OpenClawConfig;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (mode === "bot") {
|
|
227
|
+
return {
|
|
228
|
+
...cfg,
|
|
229
|
+
channels: {
|
|
230
|
+
...cfg.channels,
|
|
231
|
+
wecom: {
|
|
232
|
+
...wecom,
|
|
233
|
+
bot: {
|
|
234
|
+
...wecom.bot,
|
|
235
|
+
dm,
|
|
236
|
+
},
|
|
237
237
|
},
|
|
238
|
+
},
|
|
238
239
|
} as OpenClawConfig;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
...cfg,
|
|
243
|
+
channels: {
|
|
244
|
+
...cfg.channels,
|
|
245
|
+
wecom: {
|
|
246
|
+
...wecom,
|
|
247
|
+
agent: {
|
|
248
|
+
...wecom.agent,
|
|
249
|
+
dm,
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
} as OpenClawConfig;
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
async function resolveOnboardingAccountId(params: {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
257
|
+
cfg: OpenClawConfig;
|
|
258
|
+
prompter: WizardPrompter;
|
|
259
|
+
accountOverride?: string;
|
|
260
|
+
shouldPromptAccountIds: boolean;
|
|
246
261
|
}): Promise<string> {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
accountId = normalized;
|
|
279
|
-
} else {
|
|
280
|
-
accountId = normalizeAccountId(choice);
|
|
281
|
-
}
|
|
262
|
+
const defaultAccountId = resolveDefaultWecomAccountId(params.cfg);
|
|
263
|
+
const override = params.accountOverride?.trim();
|
|
264
|
+
let accountId = override ? normalizeAccountId(override) : defaultAccountId;
|
|
265
|
+
if (!override && params.shouldPromptAccountIds) {
|
|
266
|
+
const existingIds = listWecomAccountIds(params.cfg);
|
|
267
|
+
const selectableIds = existingIds.includes(DEFAULT_ACCOUNT_ID)
|
|
268
|
+
? existingIds
|
|
269
|
+
: [DEFAULT_ACCOUNT_ID, ...existingIds];
|
|
270
|
+
const choice = await params.prompter.select({
|
|
271
|
+
message: "请选择企业微信接入标识(英文):",
|
|
272
|
+
options: [
|
|
273
|
+
...selectableIds.map((id) => ({
|
|
274
|
+
value: id,
|
|
275
|
+
label: id === DEFAULT_ACCOUNT_ID ? "default(默认标识)" : id,
|
|
276
|
+
})),
|
|
277
|
+
{ value: "__new__", label: "新增接入标识" },
|
|
278
|
+
],
|
|
279
|
+
initialValue: accountId,
|
|
280
|
+
});
|
|
281
|
+
if (choice === "__new__") {
|
|
282
|
+
const entered = await params.prompter.text({
|
|
283
|
+
message: "请输入新的企业微信接入标识(英文):",
|
|
284
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "接入标识不能为空"),
|
|
285
|
+
});
|
|
286
|
+
const normalized = normalizeAccountId(String(entered));
|
|
287
|
+
if (String(entered).trim() !== normalized) {
|
|
288
|
+
await params.prompter.note(`接入标识已规范化为:${normalized}`, "企业微信接入标识");
|
|
289
|
+
}
|
|
290
|
+
accountId = normalized;
|
|
291
|
+
} else {
|
|
292
|
+
accountId = normalizeAccountId(choice);
|
|
282
293
|
}
|
|
283
|
-
|
|
294
|
+
}
|
|
295
|
+
return accountId.trim() || DEFAULT_ACCOUNT_ID;
|
|
284
296
|
}
|
|
285
297
|
|
|
286
298
|
// ============================================================
|
|
@@ -288,20 +300,20 @@ async function resolveOnboardingAccountId(params: {
|
|
|
288
300
|
// ============================================================
|
|
289
301
|
|
|
290
302
|
async function showWelcome(prompter: WizardPrompter): Promise<void> {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
await prompter.note(
|
|
304
|
+
[
|
|
305
|
+
"🚀 欢迎使用企业微信(WeCom)接入向导",
|
|
306
|
+
"YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,适合直接落生产环境。",
|
|
307
|
+
"默认就是 Bot WebSocket 模式,配置简单,无需域名,普通用户也能快速接入。",
|
|
308
|
+
"支持主动发消息,定时任务、异常提醒、工作流通知都可直接落地。",
|
|
309
|
+
"同时支持「智能体 Bot」与「自建应用 Agent」双模式并行。",
|
|
310
|
+
"--------------------------------------------------",
|
|
311
|
+
"👨💻 作者: YanHaidao (微信: YanHaidao)",
|
|
312
|
+
"💬 交流: 有任何问题或建议,欢迎添加微信进入交流群。",
|
|
313
|
+
"--------------------------------------------------",
|
|
314
|
+
].join("\n"),
|
|
315
|
+
"WeCom (企业微信) 配置向导",
|
|
316
|
+
);
|
|
305
317
|
}
|
|
306
318
|
|
|
307
319
|
// ============================================================
|
|
@@ -309,28 +321,28 @@ async function showWelcome(prompter: WizardPrompter): Promise<void> {
|
|
|
309
321
|
// ============================================================
|
|
310
322
|
|
|
311
323
|
async function promptMode(prompter: WizardPrompter): Promise<WecomMode> {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
324
|
+
const choice = await prompter.select({
|
|
325
|
+
message: "请选择您要配置的接入模式:",
|
|
326
|
+
options: [
|
|
327
|
+
{
|
|
328
|
+
value: "bot",
|
|
329
|
+
label: "Bot 模式 (智能机器人)",
|
|
330
|
+
hint: "默认 WS,配置简单,无需域名,支持主动发消息和日常对话",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
value: "agent",
|
|
334
|
+
label: "Agent 模式 (自建应用)",
|
|
335
|
+
hint: "功能最全,支持 API 主动推送、发送文件/视频、交互卡片",
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
value: "both",
|
|
339
|
+
label: "双模式 (Bot + Agent 同时启用)",
|
|
340
|
+
hint: "Bot 默认 WS 易上手,Agent 负责应用回调、主动推送和媒体发送",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
initialValue: "bot",
|
|
344
|
+
});
|
|
345
|
+
return choice as WecomMode;
|
|
334
346
|
}
|
|
335
347
|
|
|
336
348
|
// ============================================================
|
|
@@ -338,63 +350,63 @@ async function promptMode(prompter: WizardPrompter): Promise<WecomMode> {
|
|
|
338
350
|
// ============================================================
|
|
339
351
|
|
|
340
352
|
async function configureBotMode(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
cfg: OpenClawConfig,
|
|
354
|
+
prompter: WizardPrompter,
|
|
355
|
+
accountId: string,
|
|
344
356
|
): Promise<OpenClawConfig> {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
357
|
+
const recommendedPath = accountWebhookPath("bot", accountId);
|
|
358
|
+
await prompter.note(
|
|
359
|
+
[
|
|
360
|
+
"正在配置 Bot 模式...",
|
|
361
|
+
"",
|
|
362
|
+
"✨ YanHaidao/wecom 是企业微信官方推荐三方插件,功能强大,能力完整。",
|
|
363
|
+
"✅ 默认就是 Bot WebSocket 模式,配置简单,无需域名。",
|
|
364
|
+
"✅ 支持主动发消息,定时任务、异常提醒、工作流通知都可满足。",
|
|
365
|
+
"",
|
|
366
|
+
"请在企微后台【管理工具 -> 智能机器人】开启 API 模式,并选择 WebSocket 接入。",
|
|
367
|
+
"如果您后续需要 Bot webhook,可在配置文件里手动补充 bot.webhook。",
|
|
368
|
+
`📎 如需手动启用 Bot webhook,推荐回调 URL: https://您的域名${recommendedPath}`,
|
|
369
|
+
].join("\n"),
|
|
370
|
+
"Bot 模式配置",
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const botId = String(
|
|
374
|
+
await prompter.text({
|
|
375
|
+
message: "请输入 BotId(机器人 ID):",
|
|
376
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "BotId 不能为空"),
|
|
377
|
+
}),
|
|
378
|
+
).trim();
|
|
379
|
+
|
|
380
|
+
const secret = String(
|
|
381
|
+
await prompter.text({
|
|
382
|
+
message: "请输入 Secret(机器人密钥):",
|
|
383
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "Secret 不能为空"),
|
|
384
|
+
}),
|
|
385
|
+
).trim();
|
|
386
|
+
|
|
387
|
+
const streamPlaceholder = await prompter.text({
|
|
388
|
+
message: "流式占位符 (可选):",
|
|
389
|
+
placeholder: "正在思考...",
|
|
390
|
+
initialValue: "正在思考...",
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const welcomeText = await prompter.text({
|
|
394
|
+
message: "欢迎语 (可选):",
|
|
395
|
+
placeholder: "你好!我是 AI 助手",
|
|
396
|
+
initialValue: "你好!我是 AI 助手",
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const botConfig: WecomBotConfig = {
|
|
400
|
+
primaryTransport: "ws",
|
|
401
|
+
ws: {
|
|
402
|
+
botId,
|
|
403
|
+
secret,
|
|
404
|
+
},
|
|
405
|
+
streamPlaceholderContent: streamPlaceholder?.trim() || undefined,
|
|
406
|
+
welcomeText: welcomeText?.trim() || undefined,
|
|
407
|
+
};
|
|
396
408
|
|
|
397
|
-
|
|
409
|
+
return setWecomBotConfig(cfg, botConfig, accountId);
|
|
398
410
|
}
|
|
399
411
|
|
|
400
412
|
// ============================================================
|
|
@@ -402,93 +414,93 @@ async function configureBotMode(
|
|
|
402
414
|
// ============================================================
|
|
403
415
|
|
|
404
416
|
async function configureAgentMode(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
417
|
+
cfg: OpenClawConfig,
|
|
418
|
+
prompter: WizardPrompter,
|
|
419
|
+
accountId: string,
|
|
408
420
|
): Promise<OpenClawConfig> {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
421
|
+
const recommendedPath = accountWebhookPath("agent", accountId);
|
|
422
|
+
await prompter.note(
|
|
423
|
+
[
|
|
424
|
+
"正在配置 Agent 模式...",
|
|
425
|
+
"",
|
|
426
|
+
"💡 操作指南: 请在企微后台【应用管理 -> 自建应用】创建应用。",
|
|
427
|
+
].join("\n"),
|
|
428
|
+
"Agent 模式配置",
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
const corpId = String(
|
|
432
|
+
await prompter.text({
|
|
433
|
+
message: "请输入 CorpID (企业ID):",
|
|
434
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "CorpID 不能为空"),
|
|
435
|
+
}),
|
|
436
|
+
).trim();
|
|
437
|
+
|
|
438
|
+
const agentIdStr = String(
|
|
439
|
+
await prompter.text({
|
|
440
|
+
message: "请输入 AgentID (应用ID):",
|
|
441
|
+
validate: (value: string | undefined) => {
|
|
442
|
+
const v = value?.trim() ?? "";
|
|
443
|
+
if (!v) return "AgentID 不能为空";
|
|
444
|
+
if (!/^\d+$/.test(v)) return "AgentID 应为数字";
|
|
445
|
+
return undefined;
|
|
446
|
+
},
|
|
447
|
+
}),
|
|
448
|
+
).trim();
|
|
449
|
+
const agentId = Number(agentIdStr);
|
|
450
|
+
|
|
451
|
+
const agentSecret = String(
|
|
452
|
+
await prompter.text({
|
|
453
|
+
message: "请输入应用 Secret:",
|
|
454
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "应用 Secret 不能为空"),
|
|
455
|
+
}),
|
|
456
|
+
).trim();
|
|
457
|
+
|
|
458
|
+
await prompter.note(
|
|
459
|
+
[
|
|
460
|
+
"💡 操作指南: 请在自建应用详情页进入【接收消息 -> 设置API接收】。",
|
|
461
|
+
`🔗 回调 URL (推荐): https://您的域名${recommendedPath}`,
|
|
462
|
+
"🧭 说明: Agent 同时承担 Callback ingress 与 API egress;回调路径由系统派生。",
|
|
463
|
+
"",
|
|
464
|
+
"请先在后台填入回调 URL,然后获取以下信息。",
|
|
465
|
+
].join("\n"),
|
|
466
|
+
"回调配置",
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
const token = String(
|
|
470
|
+
await prompter.text({
|
|
471
|
+
message: "请输入 Token (回调令牌):",
|
|
472
|
+
validate: (value: string | undefined) => (value?.trim() ? undefined : "Token 不能为空"),
|
|
473
|
+
}),
|
|
474
|
+
).trim();
|
|
475
|
+
|
|
476
|
+
const encodingAESKey = String(
|
|
477
|
+
await prompter.text({
|
|
478
|
+
message: "请输入 EncodingAESKey (回调加密密钥):",
|
|
479
|
+
validate: (value: string | undefined) => {
|
|
480
|
+
const v = value?.trim() ?? "";
|
|
481
|
+
if (!v) return "EncodingAESKey 不能为空";
|
|
482
|
+
if (v.length !== 43) return "EncodingAESKey 应为 43 个字符";
|
|
483
|
+
return undefined;
|
|
484
|
+
},
|
|
485
|
+
}),
|
|
486
|
+
).trim();
|
|
487
|
+
|
|
488
|
+
const welcomeText = await prompter.text({
|
|
489
|
+
message: "欢迎语 (可选):",
|
|
490
|
+
placeholder: "欢迎使用智能助手",
|
|
491
|
+
initialValue: "欢迎使用智能助手",
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
const agentConfig: WecomAgentConfig = {
|
|
495
|
+
corpId,
|
|
496
|
+
agentSecret,
|
|
497
|
+
agentId,
|
|
498
|
+
token,
|
|
499
|
+
encodingAESKey,
|
|
500
|
+
welcomeText: welcomeText?.trim() || undefined,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
return setWecomAgentConfig(cfg, agentConfig, accountId);
|
|
492
504
|
}
|
|
493
505
|
|
|
494
506
|
// ============================================================
|
|
@@ -496,164 +508,197 @@ async function configureAgentMode(
|
|
|
496
508
|
// ============================================================
|
|
497
509
|
|
|
498
510
|
async function promptDmPolicy(
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
511
|
+
cfg: OpenClawConfig,
|
|
512
|
+
prompter: WizardPrompter,
|
|
513
|
+
modes: ("bot" | "agent")[],
|
|
514
|
+
accountId: string,
|
|
503
515
|
): Promise<OpenClawConfig> {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
516
|
+
const policyChoice = await prompter.select({
|
|
517
|
+
message: "请选择私聊 (DM) 访问策略:",
|
|
518
|
+
options: [
|
|
519
|
+
{ value: "pairing", label: "配对模式", hint: "推荐:安全,未知用户需授权" },
|
|
520
|
+
{ value: "allowlist", label: "白名单模式", hint: "仅允许特定 UserID" },
|
|
521
|
+
{ value: "open", label: "开放模式", hint: "任何人可发起" },
|
|
522
|
+
{ value: "disabled", label: "禁用私聊", hint: "不接受私聊消息" },
|
|
523
|
+
],
|
|
524
|
+
initialValue: "open",
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const policy = policyChoice as "pairing" | "allowlist" | "open" | "disabled";
|
|
528
|
+
let allowFrom: string[] | undefined;
|
|
529
|
+
|
|
530
|
+
if (policy === "allowlist") {
|
|
531
|
+
const allowFromStr = String(
|
|
532
|
+
await prompter.text({
|
|
533
|
+
message: "请输入白名单 UserID (多个用逗号分隔):",
|
|
534
|
+
placeholder: "user1,user2",
|
|
535
|
+
validate: (value: string | undefined) =>
|
|
536
|
+
value?.trim() ? undefined : "请输入至少一个 UserID",
|
|
537
|
+
}),
|
|
538
|
+
).trim();
|
|
539
|
+
allowFrom = allowFromStr
|
|
540
|
+
.split(",")
|
|
541
|
+
.map((s) => s.trim())
|
|
542
|
+
.filter(Boolean);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const dm: WecomDmConfig = { policy, allowFrom };
|
|
546
|
+
|
|
547
|
+
let result = cfg;
|
|
548
|
+
for (const mode of modes) {
|
|
549
|
+
result = setWecomDmPolicy(result, mode, dm, accountId);
|
|
550
|
+
}
|
|
551
|
+
return result;
|
|
536
552
|
}
|
|
537
553
|
|
|
538
554
|
// ============================================================
|
|
539
555
|
// 配置汇总
|
|
540
556
|
// ============================================================
|
|
541
557
|
|
|
542
|
-
async function showSummary(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
+
async function showSummary(
|
|
559
|
+
cfg: OpenClawConfig,
|
|
560
|
+
prompter: WizardPrompter,
|
|
561
|
+
accountId: string,
|
|
562
|
+
): Promise<void> {
|
|
563
|
+
const account = resolveWecomAccount({ cfg, accountId });
|
|
564
|
+
const lines: string[] = ["✅ 配置已保存!", ""];
|
|
565
|
+
|
|
566
|
+
if (account.bot?.configured) {
|
|
567
|
+
lines.push("📱 Bot 模式: 已配置");
|
|
568
|
+
lines.push(
|
|
569
|
+
` 接入方式: ${account.bot.primaryTransport === "ws" ? "WebSocket 长连接" : "Webhook 回调"}`,
|
|
570
|
+
);
|
|
571
|
+
if (account.bot.primaryTransport === "ws") {
|
|
572
|
+
lines.push(" WS 优势: 无需域名,长链接模式创建机器人门槛更低");
|
|
573
|
+
lines.push(" 主动消息: 支持定时任务、异常提醒等主动发消息场景");
|
|
574
|
+
if (account.bot.webhookConfigured) {
|
|
575
|
+
lines.push(
|
|
576
|
+
` 可选回调模式: 已手动配置,推荐回调地址为 https://您的域名${accountWebhookPath("bot", accountId)}`,
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
} else {
|
|
580
|
+
lines.push(` 回调地址: https://您的域名${accountWebhookPath("bot", accountId)}`);
|
|
558
581
|
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (account.agent?.configured) {
|
|
585
|
+
lines.push("🏢 Agent 模式: 已配置");
|
|
586
|
+
lines.push(` 回调地址: https://您的域名${accountWebhookPath("agent", accountId)}`);
|
|
587
|
+
lines.push(" 出站能力: Agent API(主动发送 / 补送 / 媒体)");
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
lines.push(` 接入标识: ${accountId}`);
|
|
591
|
+
lines.push(" 运维检查: openclaw channels status --deep");
|
|
592
|
+
lines.push(" 关键日志: [wecom-runtime] [wecom-ws] [wecom-http] [wecom-agent-delivery]");
|
|
593
|
+
|
|
594
|
+
lines.push("");
|
|
595
|
+
if (account.agent?.configured) {
|
|
596
|
+
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Agent 回调 URL,");
|
|
597
|
+
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
598
|
+
} else if (account.bot?.primaryTransport === "webhook") {
|
|
599
|
+
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Bot 回调 URL,");
|
|
600
|
+
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
await prompter.note(lines.join("\n"), "配置完成");
|
|
604
|
+
}
|
|
559
605
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
lines.push(" 出站能力: Agent API(主动发送 / 补送 / 媒体)");
|
|
564
|
-
}
|
|
606
|
+
// ============================================================
|
|
607
|
+
// Setup Wizard
|
|
608
|
+
// ============================================================
|
|
565
609
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Agent 回调 URL,");
|
|
573
|
-
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
574
|
-
} else if (account.bot?.primaryTransport === "webhook") {
|
|
575
|
-
lines.push("⚠️ 请确保您已在企微后台填写了正确的 Bot 回调 URL,");
|
|
576
|
-
lines.push(" 并点击了后台的『保存』按钮完成验证。");
|
|
577
|
-
}
|
|
610
|
+
type WecomSetupStatus = {
|
|
611
|
+
configured: boolean;
|
|
612
|
+
statusLines: string[];
|
|
613
|
+
selectionHint: string;
|
|
614
|
+
quickstartScore: number;
|
|
615
|
+
};
|
|
578
616
|
|
|
579
|
-
|
|
617
|
+
async function getWecomSetupStatus(cfg: OpenClawConfig): Promise<WecomSetupStatus> {
|
|
618
|
+
const resolved = resolveWecomAccounts(cfg);
|
|
619
|
+
const accounts = Object.values(resolved.accounts).filter((account) => account.enabled !== false);
|
|
620
|
+
const botConfigured = accounts.some((account) => Boolean(account.bot?.configured));
|
|
621
|
+
const agentConfigured = accounts.some((account) => Boolean(account.agent?.configured));
|
|
622
|
+
const configured = accounts.some((account) => account.configured);
|
|
623
|
+
|
|
624
|
+
const statusParts: string[] = [];
|
|
625
|
+
if (botConfigured) statusParts.push("Bot ✓");
|
|
626
|
+
if (agentConfigured) statusParts.push("Agent ✓");
|
|
627
|
+
const accountSuffix = accounts.length > 1 ? ` · ${accounts.length} accounts` : "";
|
|
628
|
+
const statusSummary = statusParts.length > 0 ? statusParts.join(" + ") : "已配置";
|
|
629
|
+
|
|
630
|
+
return {
|
|
631
|
+
configured,
|
|
632
|
+
statusLines: [
|
|
633
|
+
`WeCom (企业微信): ${configured ? `${statusSummary}${accountSuffix}` : "需要配置"}`,
|
|
634
|
+
],
|
|
635
|
+
selectionHint: configured
|
|
636
|
+
? `configured · ${statusSummary}${accountSuffix}`
|
|
637
|
+
: "官方推荐 · 功能强大 · 上手简单",
|
|
638
|
+
quickstartScore: configured ? 1 : 8,
|
|
639
|
+
};
|
|
580
640
|
}
|
|
581
641
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
642
|
+
async function runWecomSetupFlow(params: {
|
|
643
|
+
cfg: OpenClawConfig;
|
|
644
|
+
prompter: WizardPrompter;
|
|
645
|
+
accountId: string;
|
|
646
|
+
}): Promise<OpenClawConfig> {
|
|
647
|
+
const mode = await promptMode(params.prompter);
|
|
648
|
+
|
|
649
|
+
let next = params.cfg;
|
|
650
|
+
const configuredModes: ("bot" | "agent")[] = [];
|
|
651
|
+
|
|
652
|
+
if (mode === "bot" || mode === "both") {
|
|
653
|
+
next = await configureBotMode(next, params.prompter, params.accountId);
|
|
654
|
+
configuredModes.push("bot");
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (mode === "agent" || mode === "both") {
|
|
658
|
+
next = await configureAgentMode(next, params.prompter, params.accountId);
|
|
659
|
+
configuredModes.push("agent");
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
next = await promptDmPolicy(next, params.prompter, configuredModes, params.accountId);
|
|
663
|
+
next = setWecomEnabled(next, true);
|
|
664
|
+
await showSummary(next, params.prompter, params.accountId);
|
|
665
|
+
return next;
|
|
666
|
+
}
|
|
585
667
|
|
|
586
|
-
export const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
// 2. 账号选择
|
|
623
|
-
const accountId = await resolveOnboardingAccountId({
|
|
624
|
-
cfg,
|
|
625
|
-
prompter,
|
|
626
|
-
accountOverride: accountOverrides.wecom,
|
|
627
|
-
shouldPromptAccountIds,
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
// 3. 模式选择
|
|
631
|
-
const mode = await promptMode(prompter);
|
|
632
|
-
|
|
633
|
-
let next = cfg;
|
|
634
|
-
const configuredModes: ("bot" | "agent")[] = [];
|
|
635
|
-
|
|
636
|
-
// 4. 配置 Bot
|
|
637
|
-
if (mode === "bot" || mode === "both") {
|
|
638
|
-
next = await configureBotMode(next, prompter, accountId);
|
|
639
|
-
configuredModes.push("bot");
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// 5. 配置 Agent
|
|
643
|
-
if (mode === "agent" || mode === "both") {
|
|
644
|
-
next = await configureAgentMode(next, prompter, accountId);
|
|
645
|
-
configuredModes.push("agent");
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// 6. DM 策略
|
|
649
|
-
next = await promptDmPolicy(next, prompter, configuredModes, accountId);
|
|
650
|
-
|
|
651
|
-
// 7. 启用通道
|
|
652
|
-
next = setWecomEnabled(next, true);
|
|
653
|
-
|
|
654
|
-
// 8. 汇总
|
|
655
|
-
await showSummary(next, prompter, accountId);
|
|
656
|
-
|
|
657
|
-
return { cfg: next, accountId };
|
|
658
|
-
},
|
|
668
|
+
export const wecomSetupWizard: ChannelSetupWizard = {
|
|
669
|
+
channel,
|
|
670
|
+
status: {
|
|
671
|
+
configuredLabel: "已配置",
|
|
672
|
+
unconfiguredLabel: "需要配置",
|
|
673
|
+
configuredHint: "configured",
|
|
674
|
+
unconfiguredHint: "官方推荐 · 功能强大 · 上手简单",
|
|
675
|
+
configuredScore: 1,
|
|
676
|
+
unconfiguredScore: 8,
|
|
677
|
+
resolveConfigured: async ({ cfg }) => (await getWecomSetupStatus(cfg)).configured,
|
|
678
|
+
resolveStatusLines: async ({ cfg }) => (await getWecomSetupStatus(cfg)).statusLines,
|
|
679
|
+
resolveSelectionHint: async ({ cfg }) => (await getWecomSetupStatus(cfg)).selectionHint,
|
|
680
|
+
resolveQuickstartScore: async ({ cfg }) => (await getWecomSetupStatus(cfg)).quickstartScore,
|
|
681
|
+
},
|
|
682
|
+
resolveAccountIdForConfigure: async ({
|
|
683
|
+
cfg,
|
|
684
|
+
prompter,
|
|
685
|
+
accountOverride,
|
|
686
|
+
shouldPromptAccountIds,
|
|
687
|
+
}) => {
|
|
688
|
+
await showWelcome(prompter);
|
|
689
|
+
return await resolveOnboardingAccountId({
|
|
690
|
+
cfg,
|
|
691
|
+
prompter,
|
|
692
|
+
accountOverride,
|
|
693
|
+
shouldPromptAccountIds,
|
|
694
|
+
});
|
|
695
|
+
},
|
|
696
|
+
credentials: [],
|
|
697
|
+
finalize: async ({ cfg, accountId, prompter }) => ({
|
|
698
|
+
cfg: await runWecomSetupFlow({
|
|
699
|
+
cfg,
|
|
700
|
+
prompter,
|
|
701
|
+
accountId,
|
|
702
|
+
}),
|
|
703
|
+
}),
|
|
659
704
|
};
|