refactor(telegram): share allowFrom normalization

This commit is contained in:
Peter Steinberger
2026-02-15 18:17:05 +00:00
parent dce3e4bd94
commit 7773c5410b
3 changed files with 19 additions and 24 deletions

View File

@@ -0,0 +1,11 @@
export function normalizeTelegramAllowFromEntry(raw: unknown): string {
const base = typeof raw === "string" ? raw : typeof raw === "number" ? String(raw) : "";
return base
.trim()
.replace(/^(telegram|tg):/i, "")
.trim();
}
export function isNumericTelegramUserId(raw: string): boolean {
return /^\d+$/.test(raw);
}

View File

@@ -3,6 +3,10 @@ import fs from "node:fs/promises";
import path from "node:path";
import type { OpenClawConfig } from "../config/config.js";
import type { DoctorOptions } from "./doctor-prompter.js";
import {
isNumericTelegramUserId,
normalizeTelegramAllowFromEntry,
} from "../channels/telegram/allow-from.js";
import { formatCliCommand } from "../cli/command-format.js";
import {
OpenClawSchema,
@@ -143,18 +147,6 @@ function noteOpencodeProviderOverrides(cfg: OpenClawConfig) {
note(lines.join("\n"), "OpenCode Zen");
}
function normalizeTelegramAllowFromEntry(raw: unknown): string {
const base = typeof raw === "string" ? raw : typeof raw === "number" ? String(raw) : "";
return base
.trim()
.replace(/^(telegram|tg):/i, "")
.trim();
}
function isNumericTelegramUserId(raw: string): boolean {
return /^\d+$/.test(raw);
}
type TelegramAllowFromUsernameHit = { path: string; entry: string };
function scanTelegramAllowFromUsernameEntries(cfg: OpenClawConfig): TelegramAllowFromUsernameHit[] {

View File

@@ -3,6 +3,10 @@ import type { ChannelId } from "../channels/plugins/types.js";
import type { OpenClawConfig } from "../config/config.js";
import type { SecurityAuditFinding, SecurityAuditSeverity } from "./audit.js";
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
import {
isNumericTelegramUserId,
normalizeTelegramAllowFromEntry,
} from "../channels/telegram/allow-from.js";
import { formatCliCommand } from "../cli/command-format.js";
import { resolveNativeCommandsEnabled, resolveNativeSkillsEnabled } from "../config/commands.js";
import { readChannelAllowFromStore } from "../pairing/pairing-store.js";
@@ -14,18 +18,6 @@ function normalizeAllowFromList(list: Array<string | number> | undefined | null)
return list.map((v) => String(v).trim()).filter(Boolean);
}
function normalizeTelegramAllowFromEntry(raw: unknown): string {
const base = typeof raw === "string" ? raw : typeof raw === "number" ? String(raw) : "";
return base
.trim()
.replace(/^(telegram|tg):/i, "")
.trim();
}
function isNumericTelegramUserId(raw: string): boolean {
return /^\d+$/.test(raw);
}
function classifyChannelWarningSeverity(message: string): SecurityAuditSeverity {
const s = message.toLowerCase();
if (