Skip to content

Commit da7cc2b

Browse files
committed
fix(feishu): make manual setup the default
1 parent 2838eb4 commit da7cc2b

5 files changed

Lines changed: 188 additions & 31 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Docs: https://docs.openclaw.ai
5656

5757
### Fixes
5858

59+
- Feishu: make manual App ID/App Secret setup the default channel-binding path while keeping QR scan-to-create as an optional best-effort flow, and document the manual fallback for domestic Feishu mobile clients that do not react to the QR code. Fixes #80591. Thanks @wei-wei-zhao.
5960
- Gateway: scope `sessions.resolve` sessionId and label store loads to the requested agent so large unrelated agent stores are not parsed for scoped lookups. Fixes #51264. (#79474) Thanks @samzong.
6061
- Gateway: share serialized streaming event envelopes across eligible WebSocket and node subscribers while preserving per-client sequence numbers. (#80299) Thanks @samzong.
6162
- Browser: report Chrome MCP existing-session page readiness in browser status without letting status probes exceed the client timeout. Fixes #80268. (#80280) Thanks @ai-hpc.

‎docs/channels/feishu.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Requires OpenClaw 2026.4.25 or above. Run `openclaw --version` to check. Upgrade
2323
```bash
2424
openclaw channels login --channel feishu
2525
```
26-
Scan the QR code with your Feishu/Lark mobile app to create a Feishu/Lark bot automatically.
26+
Choose manual setup to paste an App ID and App Secret from Feishu Open Platform, or choose QR setup to create a bot automatically. If the domestic Feishu mobile app does not react to the QR code, rerun setup and choose manual setup.
2727
</Step>
2828

2929
<Step title="After setup completes, restart the gateway to apply the changes">
@@ -211,6 +211,13 @@ Feishu/Lark does not support native slash-command menus, so send these as plain
211211
5. Ensure the gateway is running: `openclaw gateway status`
212212
6. Check logs: `openclaw logs --follow`
213213

214+
### QR setup does not react in the Feishu mobile app
215+
216+
1. Rerun setup: `openclaw channels login --channel feishu`
217+
2. Choose manual setup
218+
3. In Feishu Open Platform, create a self-built app and copy its App ID and App Secret
219+
4. Paste those credentials into the setup wizard
220+
214221
### App Secret leaked
215222

216223
1. Reset the App Secret in Feishu Open Platform / Lark Developer

‎extensions/feishu/src/app-registration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export async function pollAppRegistration(params: {
167167
expireIn: number;
168168
initialDomain?: FeishuDomain;
169169
abortSignal?: AbortSignal;
170-
/** Registration type parameter: "ob_user" for user mode, "ob_app" for bot mode. */
170+
/** Registration type parameter. The CLI bot QR flow uses "ob_cli_app". */
171171
tp?: string;
172172
}): Promise<PollOutcome> {
173173
const { deviceCode, expireIn, initialDomain = "feishu", abortSignal, tp } = params;

‎extensions/feishu/src/setup-surface.test.ts‎

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ import {
88
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
99
import type { FeishuProbeResult } from "./types.js";
1010

11-
const { probeFeishuMock } = vi.hoisted(() => ({
11+
const {
12+
beginAppRegistrationMock,
13+
getAppOwnerOpenIdMock,
14+
initAppRegistrationMock,
15+
pollAppRegistrationMock,
16+
printQrCodeMock,
17+
probeFeishuMock,
18+
} = vi.hoisted(() => ({
19+
beginAppRegistrationMock: vi.fn(),
20+
getAppOwnerOpenIdMock: vi.fn(),
21+
initAppRegistrationMock: vi.fn(),
22+
pollAppRegistrationMock: vi.fn(),
23+
printQrCodeMock: vi.fn(),
1224
probeFeishuMock: vi.fn<() => Promise<FeishuProbeResult>>(async () => ({
1325
ok: false,
1426
error: "mocked",
@@ -20,13 +32,11 @@ vi.mock("./probe.js", () => ({
2032
}));
2133

2234
vi.mock("./app-registration.js", () => ({
23-
initAppRegistration: vi.fn(async () => {
24-
throw new Error("mocked: scan-to-create not available");
25-
}),
26-
beginAppRegistration: vi.fn(),
27-
pollAppRegistration: vi.fn(),
28-
printQrCode: vi.fn(async () => {}),
29-
getAppOwnerOpenId: vi.fn(async () => undefined),
35+
initAppRegistration: initAppRegistrationMock,
36+
beginAppRegistration: beginAppRegistrationMock,
37+
pollAppRegistration: pollAppRegistrationMock,
38+
printQrCode: printQrCodeMock,
39+
getAppOwnerOpenId: getAppOwnerOpenIdMock,
3040
}));
3141

3242
import { feishuPlugin } from "./channel.js";
@@ -86,6 +96,116 @@ describe("feishu setup wizard", () => {
8696
beforeEach(() => {
8797
probeFeishuMock.mockReset();
8898
probeFeishuMock.mockResolvedValue({ ok: false, error: "mocked" });
99+
initAppRegistrationMock.mockReset();
100+
initAppRegistrationMock.mockRejectedValue(new Error("mocked: scan-to-create not available"));
101+
beginAppRegistrationMock.mockReset();
102+
pollAppRegistrationMock.mockReset();
103+
printQrCodeMock.mockReset();
104+
printQrCodeMock.mockResolvedValue(undefined);
105+
getAppOwnerOpenIdMock.mockReset();
106+
getAppOwnerOpenIdMock.mockResolvedValue(undefined);
107+
});
108+
109+
it("uses manual credentials by default instead of starting scan-to-create", async () => {
110+
const text = vi.fn().mockResolvedValueOnce("cli_manual").mockResolvedValueOnce("secret_manual");
111+
const prompter = createTestWizardPrompter({ text });
112+
113+
const result = await runSetupWizardConfigure({
114+
configure: feishuConfigure,
115+
cfg: {} as never,
116+
prompter,
117+
runtime: createNonExitingRuntimeEnv(),
118+
});
119+
120+
expect(initAppRegistrationMock).not.toHaveBeenCalled();
121+
expect(beginAppRegistrationMock).not.toHaveBeenCalled();
122+
expect(result.cfg.channels?.feishu).toMatchObject({
123+
appId: "cli_manual",
124+
appSecret: "secret_manual",
125+
connectionMode: "websocket",
126+
domain: "feishu",
127+
});
128+
});
129+
130+
it("passes selected domain through scan-to-create and poll", async () => {
131+
initAppRegistrationMock.mockResolvedValueOnce(undefined);
132+
beginAppRegistrationMock.mockResolvedValueOnce({
133+
deviceCode: "device-code",
134+
qrUrl: "https://accounts.larksuite.com/qr",
135+
userCode: "user-code",
136+
interval: 1,
137+
expireIn: 10,
138+
});
139+
pollAppRegistrationMock.mockResolvedValueOnce({
140+
status: "success",
141+
result: {
142+
appId: "cli_lark",
143+
appSecret: "secret_lark",
144+
domain: "lark",
145+
openId: "ou_owner",
146+
},
147+
});
148+
const prompter = createTestWizardPrompter({
149+
select: vi
150+
.fn()
151+
.mockResolvedValueOnce("scan")
152+
.mockResolvedValueOnce("lark")
153+
.mockResolvedValueOnce("open") as never,
154+
});
155+
156+
const result = await runSetupWizardConfigure({
157+
configure: feishuConfigure,
158+
cfg: {} as never,
159+
prompter,
160+
runtime: createNonExitingRuntimeEnv(),
161+
});
162+
163+
expect(initAppRegistrationMock).toHaveBeenCalledWith("lark");
164+
expect(beginAppRegistrationMock).toHaveBeenCalledWith("lark");
165+
expect(pollAppRegistrationMock).toHaveBeenCalledWith(
166+
expect.objectContaining({
167+
deviceCode: "device-code",
168+
initialDomain: "lark",
169+
tp: "ob_cli_app",
170+
}),
171+
);
172+
expect(result.cfg.channels?.feishu).toMatchObject({
173+
appId: "cli_lark",
174+
appSecret: "secret_lark",
175+
domain: "lark",
176+
groupPolicy: "open",
177+
requireMention: true,
178+
});
179+
});
180+
181+
it("falls back to manual credentials when selected scan-to-create is unavailable", async () => {
182+
const text = vi
183+
.fn()
184+
.mockResolvedValueOnce("cli_from_fallback")
185+
.mockResolvedValueOnce("secret_from_fallback");
186+
const prompter = createTestWizardPrompter({
187+
text,
188+
select: vi
189+
.fn()
190+
.mockResolvedValueOnce("scan")
191+
.mockResolvedValueOnce("feishu")
192+
.mockResolvedValueOnce("allowlist") as never,
193+
});
194+
195+
const result = await runSetupWizardConfigure({
196+
configure: feishuConfigure,
197+
cfg: {} as never,
198+
prompter,
199+
runtime: createNonExitingRuntimeEnv(),
200+
});
201+
202+
expect(initAppRegistrationMock).toHaveBeenCalledWith("feishu");
203+
expect(beginAppRegistrationMock).not.toHaveBeenCalled();
204+
expect(result.cfg.channels?.feishu).toMatchObject({
205+
appId: "cli_from_fallback",
206+
appSecret: "secret_from_fallback",
207+
domain: "feishu",
208+
});
89209
});
90210

91211
it("prompts over SecretRef appId/appSecret config objects", async () => {

‎extensions/feishu/src/setup-surface.ts‎

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { AppRegistrationResult } from "./app-registration.js";
1717
import type { FeishuConfig, FeishuDomain } from "./types.js";
1818

1919
const channel = "feishu" as const;
20+
const SCAN_TO_CREATE_TP = "ob_cli_app";
2021

2122
// ---------------------------------------------------------------------------
2223
// Helpers
@@ -213,6 +214,7 @@ const feishuDmPolicy: ChannelSetupDmPolicy = {
213214
};
214215

215216
type WizardPrompter = Parameters<NonNullable<ChannelSetupWizard["finalize"]>>[0]["prompter"];
217+
type FeishuSetupMethod = "manual" | "scan";
216218

217219
// ---------------------------------------------------------------------------
218220
// Security policy helpers
@@ -245,11 +247,39 @@ function applyNewAppSecurityPolicy(
245247
// Scan-to-create flow
246248
// ---------------------------------------------------------------------------
247249

248-
async function runScanToCreate(prompter: WizardPrompter): Promise<AppRegistrationResult | null> {
250+
async function promptFeishuDomain(params: {
251+
prompter: WizardPrompter;
252+
initialValue?: FeishuDomain;
253+
}): Promise<FeishuDomain> {
254+
return (await params.prompter.select({
255+
message: "Which Feishu domain?",
256+
options: [
257+
{ value: "feishu", label: "Feishu (feishu.cn) - China" },
258+
{ value: "lark", label: "Lark (larksuite.com) - International" },
259+
],
260+
initialValue: params.initialValue ?? "feishu",
261+
})) as FeishuDomain;
262+
}
263+
264+
async function promptFeishuSetupMethod(prompter: WizardPrompter): Promise<FeishuSetupMethod> {
265+
return (await prompter.select({
266+
message: "How do you want to connect Feishu?",
267+
options: [
268+
{ value: "manual", label: "Enter App ID and App Secret manually" },
269+
{ value: "scan", label: "Scan a QR code to create a bot automatically" },
270+
],
271+
initialValue: "manual",
272+
})) as FeishuSetupMethod;
273+
}
274+
275+
async function runScanToCreate(
276+
prompter: WizardPrompter,
277+
domain: FeishuDomain,
278+
): Promise<AppRegistrationResult | null> {
249279
const { beginAppRegistration, initAppRegistration, pollAppRegistration, printQrCode } =
250280
await import("./app-registration.js");
251281
try {
252-
await initAppRegistration("feishu");
282+
await initAppRegistration(domain);
253283
} catch {
254284
await prompter.note(
255285
"Scan-to-create is not available in this environment. Falling back to manual input.",
@@ -258,9 +288,12 @@ async function runScanToCreate(prompter: WizardPrompter): Promise<AppRegistratio
258288
return null;
259289
}
260290

261-
const begin = await beginAppRegistration("feishu");
291+
const begin = await beginAppRegistration(domain);
262292

263-
await prompter.note("Scan the QR with Lark/Feishu on your phone.", "Feishu scan-to-create");
293+
await prompter.note(
294+
"Scan the QR with Lark/Feishu on your phone. If the mobile app does not react, rerun setup and choose manual input.",
295+
"Feishu scan-to-create",
296+
);
264297
await printQrCode(begin.qrUrl);
265298

266299
const progress = prompter.progress("Fetching configuration results...");
@@ -269,8 +302,8 @@ async function runScanToCreate(prompter: WizardPrompter): Promise<AppRegistratio
269302
deviceCode: begin.deviceCode,
270303
interval: begin.interval,
271304
expireIn: begin.expireIn,
272-
initialDomain: "feishu",
273-
tp: "ob_app",
305+
initialDomain: domain,
306+
tp: SCAN_TO_CREATE_TP,
274307
});
275308

276309
switch (outcome.status) {
@@ -314,8 +347,17 @@ async function runNewAppFlow(params: {
314347
let appSecretProbeValue: string | null = null;
315348
let scanDomain: FeishuDomain | undefined;
316349
let scanOpenId: string | undefined;
350+
const feishuCfg = next.channels?.feishu as FeishuConfig | undefined;
351+
const currentDomain = feishuCfg?.domain ?? "feishu";
352+
const setupMethod = await promptFeishuSetupMethod(prompter);
353+
const selectedDomain = await promptFeishuDomain({
354+
prompter,
355+
initialValue: currentDomain,
356+
});
357+
scanDomain = selectedDomain;
317358

318-
const scanResult = await runScanToCreate(prompter);
359+
const scanResult =
360+
setupMethod === "scan" ? await runScanToCreate(prompter, selectedDomain) : null;
319361
if (scanResult) {
320362
appId = scanResult.appId;
321363
appSecret = scanResult.appSecret;
@@ -324,21 +366,8 @@ async function runNewAppFlow(params: {
324366
scanOpenId = scanResult.openId;
325367
} else {
326368
// Fallback to manual input: collect domain, appId, appSecret.
327-
const feishuCfg = next.channels?.feishu as FeishuConfig | undefined;
328369
await noteFeishuCredentialHelp(prompter);
329370

330-
// Domain selection first (needed for API calls).
331-
const currentDomain = feishuCfg?.domain ?? "feishu";
332-
const domain = (await prompter.select({
333-
message: "Which Feishu domain?",
334-
options: [
335-
{ value: "feishu", label: "Feishu (feishu.cn) - China" },
336-
{ value: "lark", label: "Lark (larksuite.com) - International" },
337-
],
338-
initialValue: currentDomain,
339-
})) as FeishuDomain;
340-
scanDomain = domain;
341-
342371
appId = await promptFeishuAppId({
343372
prompter,
344373
initialValue: normalizeString(process.env.FEISHU_APP_ID),
@@ -369,7 +398,7 @@ async function runNewAppFlow(params: {
369398
scanOpenId = await getAppOwnerOpenId({
370399
appId,
371400
appSecret: appSecretProbeValue,
372-
domain: scanDomain,
401+
domain: selectedDomain,
373402
});
374403
}
375404
}

0 commit comments

Comments
 (0)