mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-11 01:01:13 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import fs from "node:fs";
|
|
import type { ChannelLegacyStateMigrationPlan } from "openclaw/plugin-sdk/channel-contract";
|
|
import { resolveChannelAllowFromPath } from "openclaw/plugin-sdk/channel-pairing";
|
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
|
import { resolveDefaultTelegramAccountId } from "./accounts.js";
|
|
|
|
function fileExists(pathValue: string): boolean {
|
|
try {
|
|
return fs.existsSync(pathValue) && fs.statSync(pathValue).isFile();
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function detectTelegramLegacyStateMigrations(params: {
|
|
cfg: OpenClawConfig;
|
|
env: NodeJS.ProcessEnv;
|
|
}): ChannelLegacyStateMigrationPlan[] {
|
|
const legacyPath = resolveChannelAllowFromPath("telegram", params.env);
|
|
if (!fileExists(legacyPath)) {
|
|
return [];
|
|
}
|
|
const accountId = resolveDefaultTelegramAccountId(params.cfg);
|
|
const targetPath = resolveChannelAllowFromPath("telegram", params.env, accountId);
|
|
if (fileExists(targetPath)) {
|
|
return [];
|
|
}
|
|
return [
|
|
{
|
|
kind: "copy",
|
|
label: "Telegram pairing allowFrom",
|
|
sourcePath: legacyPath,
|
|
targetPath,
|
|
},
|
|
];
|
|
}
|