mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:21:37 +00:00
feat: Add Line plugin (#1630)
* feat: add LINE plugin (#1630) (thanks @plum-dawg) * feat: complete LINE plugin (#1630) (thanks @plum-dawg) * chore: drop line plugin node_modules (#1630) (thanks @plum-dawg) * test: mock /context report in commands test (#1630) (thanks @plum-dawg) * test: limit macOS CI workers to avoid OOM (#1630) (thanks @plum-dawg) * test: reduce macOS CI vitest workers (#1630) (thanks @plum-dawg) --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
43
src/line/probe.ts
Normal file
43
src/line/probe.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { messagingApi } from "@line/bot-sdk";
|
||||
import type { LineProbeResult } from "./types.js";
|
||||
|
||||
export async function probeLineBot(
|
||||
channelAccessToken: string,
|
||||
timeoutMs = 5000,
|
||||
): Promise<LineProbeResult> {
|
||||
if (!channelAccessToken?.trim()) {
|
||||
return { ok: false, error: "Channel access token not configured" };
|
||||
}
|
||||
|
||||
const client = new messagingApi.MessagingApiClient({
|
||||
channelAccessToken: channelAccessToken.trim(),
|
||||
});
|
||||
|
||||
try {
|
||||
const profile = await withTimeout(client.getBotInfo(), timeoutMs);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
bot: {
|
||||
displayName: profile.displayName,
|
||||
userId: profile.userId,
|
||||
basicId: profile.basicId,
|
||||
pictureUrl: profile.pictureUrl,
|
||||
},
|
||||
};
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
return { ok: false, error: message };
|
||||
}
|
||||
}
|
||||
|
||||
function withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T> {
|
||||
if (!timeoutMs || timeoutMs <= 0) return promise;
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
const timeout = new Promise<T>((_, reject) => {
|
||||
timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
|
||||
});
|
||||
return Promise.race([promise, timeout]).finally(() => {
|
||||
if (timer) clearTimeout(timer);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user