mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:31:24 +00:00
fix(pairing): support legacy telegram allowFrom migration
This commit is contained in:
@@ -55,6 +55,11 @@ export type LegacyStateDetection = {
|
||||
targetDir: string;
|
||||
hasLegacy: boolean;
|
||||
};
|
||||
pairingAllowFrom: {
|
||||
legacyTelegramPath: string;
|
||||
targetTelegramPath: string;
|
||||
hasLegacyTelegram: boolean;
|
||||
};
|
||||
preview: string[];
|
||||
};
|
||||
|
||||
@@ -612,6 +617,13 @@ export async function detectLegacyStateMigrations(params: {
|
||||
const hasLegacyWhatsAppAuth =
|
||||
fileExists(path.join(oauthDir, "creds.json")) &&
|
||||
!fileExists(path.join(targetWhatsAppAuthDir, "creds.json"));
|
||||
const legacyTelegramAllowFromPath = path.join(oauthDir, "telegram-allowFrom.json");
|
||||
const targetTelegramAllowFromPath = path.join(
|
||||
oauthDir,
|
||||
`telegram-${DEFAULT_ACCOUNT_ID}-allowFrom.json`,
|
||||
);
|
||||
const hasLegacyTelegramAllowFrom =
|
||||
fileExists(legacyTelegramAllowFromPath) && !fileExists(targetTelegramAllowFromPath);
|
||||
|
||||
const preview: string[] = [];
|
||||
if (hasLegacySessions) {
|
||||
@@ -626,6 +638,11 @@ export async function detectLegacyStateMigrations(params: {
|
||||
if (hasLegacyWhatsAppAuth) {
|
||||
preview.push(`- WhatsApp auth: ${oauthDir} → ${targetWhatsAppAuthDir} (keep oauth.json)`);
|
||||
}
|
||||
if (hasLegacyTelegramAllowFrom) {
|
||||
preview.push(
|
||||
`- Telegram pairing allowFrom: ${legacyTelegramAllowFromPath} → ${targetTelegramAllowFromPath}`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
targetAgentId,
|
||||
@@ -651,6 +668,11 @@ export async function detectLegacyStateMigrations(params: {
|
||||
targetDir: targetWhatsAppAuthDir,
|
||||
hasLegacy: hasLegacyWhatsAppAuth,
|
||||
},
|
||||
pairingAllowFrom: {
|
||||
legacyTelegramPath: legacyTelegramAllowFromPath,
|
||||
targetTelegramPath: targetTelegramAllowFromPath,
|
||||
hasLegacyTelegram: hasLegacyTelegramAllowFrom,
|
||||
},
|
||||
preview,
|
||||
};
|
||||
}
|
||||
@@ -867,6 +889,28 @@ async function migrateLegacyWhatsAppAuth(
|
||||
return { changes, warnings };
|
||||
}
|
||||
|
||||
async function migrateLegacyTelegramPairingAllowFrom(
|
||||
detected: LegacyStateDetection,
|
||||
): Promise<{ changes: string[]; warnings: string[] }> {
|
||||
const changes: string[] = [];
|
||||
const warnings: string[] = [];
|
||||
if (!detected.pairingAllowFrom.hasLegacyTelegram) {
|
||||
return { changes, warnings };
|
||||
}
|
||||
|
||||
const legacyPath = detected.pairingAllowFrom.legacyTelegramPath;
|
||||
const targetPath = detected.pairingAllowFrom.targetTelegramPath;
|
||||
try {
|
||||
ensureDir(path.dirname(targetPath));
|
||||
fs.copyFileSync(legacyPath, targetPath);
|
||||
changes.push(`Copied Telegram pairing allowFrom → ${targetPath}`);
|
||||
} catch (err) {
|
||||
warnings.push(`Failed migrating Telegram pairing allowFrom (${legacyPath}): ${String(err)}`);
|
||||
}
|
||||
|
||||
return { changes, warnings };
|
||||
}
|
||||
|
||||
export async function runLegacyStateMigrations(params: {
|
||||
detected: LegacyStateDetection;
|
||||
now?: () => number;
|
||||
@@ -876,9 +920,20 @@ export async function runLegacyStateMigrations(params: {
|
||||
const sessions = await migrateLegacySessions(detected, now);
|
||||
const agentDir = await migrateLegacyAgentDir(detected, now);
|
||||
const whatsappAuth = await migrateLegacyWhatsAppAuth(detected);
|
||||
const telegramPairingAllowFrom = await migrateLegacyTelegramPairingAllowFrom(detected);
|
||||
return {
|
||||
changes: [...sessions.changes, ...agentDir.changes, ...whatsappAuth.changes],
|
||||
warnings: [...sessions.warnings, ...agentDir.warnings, ...whatsappAuth.warnings],
|
||||
changes: [
|
||||
...sessions.changes,
|
||||
...agentDir.changes,
|
||||
...whatsappAuth.changes,
|
||||
...telegramPairingAllowFrom.changes,
|
||||
],
|
||||
warnings: [
|
||||
...sessions.warnings,
|
||||
...agentDir.warnings,
|
||||
...whatsappAuth.warnings,
|
||||
...telegramPairingAllowFrom.warnings,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user