mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 21:10:54 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { normalizeTelegramLookupTarget, parseTelegramTarget } from "./targets.js";
|
|
|
|
const TELEGRAM_PREFIX_RE = /^(telegram|tg):/i;
|
|
|
|
function normalizeTelegramTargetBody(raw: string): string | undefined {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return undefined;
|
|
}
|
|
|
|
const prefixStripped = trimmed.replace(TELEGRAM_PREFIX_RE, "").trim();
|
|
if (!prefixStripped) {
|
|
return undefined;
|
|
}
|
|
|
|
const parsed = parseTelegramTarget(trimmed);
|
|
const normalizedChatId = normalizeTelegramLookupTarget(parsed.chatId);
|
|
if (!normalizedChatId) {
|
|
return undefined;
|
|
}
|
|
|
|
const keepLegacyGroupPrefix = /^group:/i.test(prefixStripped);
|
|
const hasTopicSuffix = /:topic:\d+$/i.test(prefixStripped);
|
|
const chatSegment = keepLegacyGroupPrefix ? `group:${normalizedChatId}` : normalizedChatId;
|
|
if (parsed.messageThreadId == null) {
|
|
return chatSegment;
|
|
}
|
|
const threadSuffix = hasTopicSuffix
|
|
? `:topic:${parsed.messageThreadId}`
|
|
: `:${parsed.messageThreadId}`;
|
|
return `${chatSegment}${threadSuffix}`;
|
|
}
|
|
|
|
export function normalizeTelegramMessagingTarget(raw: string): string | undefined {
|
|
const normalizedBody = normalizeTelegramTargetBody(raw);
|
|
if (!normalizedBody) {
|
|
return undefined;
|
|
}
|
|
return `telegram:${normalizedBody}`.toLowerCase();
|
|
}
|
|
|
|
export function looksLikeTelegramTargetId(raw: string): boolean {
|
|
return normalizeTelegramTargetBody(raw) !== undefined;
|
|
}
|