openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
50 lines (49 loc) • 1.67 kB
JavaScript
//#region extensions/telegram/src/command-config.ts
const TELEGRAM_COMMAND_NAME_PATTERN = /^[a-z0-9_]{1,32}$/;
function normalizeTelegramCommandName(e) {
return e.trim().replace(/^\//, "").trim().toLowerCase().replace(/-/g, "_");
}
function normalizeTelegramCommandDescription(e) {
return e.trim();
}
function resolveTelegramCustomCommands(e) {
const t = Array.isArray(e.commands) ? e.commands : [];
const n = e.checkReserved !== false;
const r = e.checkDuplicates !== false;
const i = /* @__PURE__ */ new Set();
const a = [];
const o = [];
for (let s = 0; s < t.length; s += 1) {
const c = t[s];
const l = normalizeTelegramCommandName(c?.command ?? "");
const u = !l ? "Telegram custom command is missing a command name." : !TELEGRAM_COMMAND_NAME_PATTERN.test(l) ? `Telegram custom command "/${l}" is invalid (use a-z, 0-9, underscore; max 32 chars).` : n && e.reservedCommands?.has(l) ? `Telegram custom command "/${l}" conflicts with a native command.` : r && i.has(l) ? `Telegram custom command "/${l}" is duplicated.` : void 0;
if (u) {
o.push({
index: s,
field: "command",
message: u
});
continue;
}
const d = normalizeTelegramCommandDescription(c?.description ?? "");
if (!d) {
o.push({
index: s,
field: "description",
message: `Telegram custom command "/${l}" is missing a description.`
});
continue;
}
if (r) i.add(l);
a.push({
command: l,
description: d
});
}
return {
commands: a,
issues: o
};
}
//#endregion
export { resolveTelegramCustomCommands as i, normalizeTelegramCommandDescription as n, normalizeTelegramCommandName as r, TELEGRAM_COMMAND_NAME_PATTERN as t };