mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 09:40:41 +00:00
- Add `--thread-id` support to cron add/edit Telegram delivery. - Reject non-positive thread IDs and guard cron edit lookup pagination against non-progress/max-page loops. - Preserve existing delivery mode on thread-only cron edit patches. Carries forward #51581, #60373, and #60890. Co-authored-by: ChunHao Chen <crazycjh@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import {
|
|
normalizeLowercaseStringOrEmpty,
|
|
normalizeOptionalString,
|
|
} from "../../shared/string-coerce.js";
|
|
|
|
export function parseCronThreadIdOption(value: unknown): number | undefined {
|
|
const raw = normalizeOptionalString(value);
|
|
if (!raw) {
|
|
return undefined;
|
|
}
|
|
if (!/^\d+$/.test(raw)) {
|
|
throw new Error("--thread-id must be a positive integer Telegram topic thread id");
|
|
}
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
throw new Error("--thread-id must be a safe positive integer Telegram topic thread id");
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
export function normalizeCronSessionTargetOption(value: unknown): string | undefined {
|
|
const raw = normalizeOptionalString(value);
|
|
if (!raw) {
|
|
return undefined;
|
|
}
|
|
const lower = normalizeLowercaseStringOrEmpty(raw);
|
|
if (lower === "main" || lower === "isolated" || lower === "current") {
|
|
return lower;
|
|
}
|
|
if (lower.startsWith("session:")) {
|
|
const id = normalizeOptionalString(raw.slice(8));
|
|
return id ? `session:${id}` : undefined;
|
|
}
|
|
return undefined;
|
|
}
|