mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 07:38:10 +00:00
refactor(feishu): split monitor startup and transport concerns
This commit is contained in:
51
extensions/feishu/src/monitor.startup.ts
Normal file
51
extensions/feishu/src/monitor.startup.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { RuntimeEnv } from "openclaw/plugin-sdk";
|
||||
import { probeFeishu } from "./probe.js";
|
||||
import type { ResolvedFeishuAccount } from "./types.js";
|
||||
|
||||
export const FEISHU_STARTUP_BOT_INFO_TIMEOUT_MS = 10_000;
|
||||
|
||||
type FetchBotOpenIdOptions = {
|
||||
runtime?: RuntimeEnv;
|
||||
abortSignal?: AbortSignal;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
function isTimeoutErrorMessage(message: string | undefined): boolean {
|
||||
return message?.toLowerCase().includes("timeout") || message?.toLowerCase().includes("timed out")
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
|
||||
function isAbortErrorMessage(message: string | undefined): boolean {
|
||||
return message?.toLowerCase().includes("aborted") ?? false;
|
||||
}
|
||||
|
||||
export async function fetchBotOpenIdForMonitor(
|
||||
account: ResolvedFeishuAccount,
|
||||
options: FetchBotOpenIdOptions = {},
|
||||
): Promise<string | undefined> {
|
||||
if (options.abortSignal?.aborted) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const timeoutMs = options.timeoutMs ?? FEISHU_STARTUP_BOT_INFO_TIMEOUT_MS;
|
||||
const result = await probeFeishu(account, {
|
||||
timeoutMs,
|
||||
abortSignal: options.abortSignal,
|
||||
});
|
||||
if (result.ok) {
|
||||
return result.botOpenId;
|
||||
}
|
||||
|
||||
if (options.abortSignal?.aborted || isAbortErrorMessage(result.error)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (isTimeoutErrorMessage(result.error)) {
|
||||
const error = options.runtime?.error ?? console.error;
|
||||
error(
|
||||
`feishu[${account.accountId}]: bot info probe timed out after ${timeoutMs}ms; continuing startup`,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user