UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

50 lines (49 loc) • 2.01 kB
//#region extensions/telegram/src/command-config.ts const TELEGRAM_COMMAND_NAME_PATTERN = /^[a-z0-9_]{1,32}$/; function normalizeTelegramCommandName(value) { return value.trim().replace(/^\//, "").trim().toLowerCase().replace(/-/g, "_"); } function normalizeTelegramCommandDescription(value) { return value.trim(); } function resolveTelegramCustomCommands(params) { const entries = Array.isArray(params.commands) ? params.commands : []; const checkReserved = params.checkReserved !== false; const checkDuplicates = params.checkDuplicates !== false; const seen = /* @__PURE__ */ new Set(); const resolved = []; const issues = []; for (let index = 0; index < entries.length; index += 1) { const entry = entries[index]; const normalized = normalizeTelegramCommandName(entry?.command ?? ""); const commandIssue = !normalized ? "Telegram custom command is missing a command name." : !TELEGRAM_COMMAND_NAME_PATTERN.test(normalized) ? `Telegram custom command "/${normalized}" is invalid (use a-z, 0-9, underscore; max 32 chars).` : checkReserved && params.reservedCommands?.has(normalized) ? `Telegram custom command "/${normalized}" conflicts with a native command.` : checkDuplicates && seen.has(normalized) ? `Telegram custom command "/${normalized}" is duplicated.` : void 0; if (commandIssue) { issues.push({ index, field: "command", message: commandIssue }); continue; } const description = normalizeTelegramCommandDescription(entry?.description ?? ""); if (!description) { issues.push({ index, field: "description", message: `Telegram custom command "/${normalized}" is missing a description.` }); continue; } if (checkDuplicates) seen.add(normalized); resolved.push({ command: normalized, description }); } return { commands: resolved, issues }; } //#endregion export { resolveTelegramCustomCommands as i, normalizeTelegramCommandDescription as n, normalizeTelegramCommandName as r, TELEGRAM_COMMAND_NAME_PATTERN as t };