mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 00:13:28 +00:00
fix: persist resolved telegram delivery targets at runtime
This commit is contained in:
@@ -1,23 +1,7 @@
|
||||
import { normalizeTelegramLookupTarget } from "../../../telegram/targets.js";
|
||||
|
||||
export function normalizeTelegramMessagingTarget(raw: string): string | undefined {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
let normalized = trimmed;
|
||||
if (normalized.startsWith("telegram:")) {
|
||||
normalized = normalized.slice("telegram:".length).trim();
|
||||
} else if (normalized.startsWith("tg:")) {
|
||||
normalized = normalized.slice("tg:".length).trim();
|
||||
}
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
const tmeMatch =
|
||||
/^https?:\/\/t\.me\/([A-Za-z0-9_]+)$/i.exec(normalized) ??
|
||||
/^t\.me\/([A-Za-z0-9_]+)$/i.exec(normalized);
|
||||
if (tmeMatch?.[1]) {
|
||||
normalized = `@${tmeMatch[1]}`;
|
||||
}
|
||||
const normalized = normalizeTelegramLookupTarget(raw);
|
||||
if (!normalized) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -25,15 +9,5 @@ export function normalizeTelegramMessagingTarget(raw: string): string | undefine
|
||||
}
|
||||
|
||||
export function looksLikeTelegramTargetId(raw: string): boolean {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) {
|
||||
return false;
|
||||
}
|
||||
if (/^(telegram|tg):/i.test(trimmed)) {
|
||||
return true;
|
||||
}
|
||||
if (trimmed.startsWith("@")) {
|
||||
return true;
|
||||
}
|
||||
return /^-?\d{6,}$/.test(trimmed);
|
||||
return Boolean(normalizeTelegramLookupTarget(raw));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user