mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 09:30:22 +00:00
refactor(extensions): split channel runtime helper seams
This commit is contained in:
@@ -1,8 +1,61 @@
|
||||
export {
|
||||
TELEGRAM_COMMAND_NAME_PATTERN,
|
||||
normalizeTelegramCommandDescription,
|
||||
normalizeTelegramCommandName,
|
||||
resolveTelegramCustomCommands,
|
||||
type TelegramCustomCommandInput,
|
||||
type TelegramCustomCommandIssue,
|
||||
} from "../config/telegram-command-config.js";
|
||||
import { getBundledChannelContractSurfaceModule } from "../channels/plugins/contract-surfaces.js";
|
||||
|
||||
export type TelegramCustomCommandInput = {
|
||||
command?: string | null;
|
||||
description?: string | null;
|
||||
};
|
||||
|
||||
export type TelegramCustomCommandIssue = {
|
||||
index: number;
|
||||
field: "command" | "description";
|
||||
message: string;
|
||||
};
|
||||
|
||||
type TelegramCommandConfigContract = {
|
||||
TELEGRAM_COMMAND_NAME_PATTERN: RegExp;
|
||||
normalizeTelegramCommandName: (value: string) => string;
|
||||
normalizeTelegramCommandDescription: (value: string) => string;
|
||||
resolveTelegramCustomCommands: (params: {
|
||||
commands?: TelegramCustomCommandInput[] | null;
|
||||
reservedCommands?: Set<string>;
|
||||
checkReserved?: boolean;
|
||||
checkDuplicates?: boolean;
|
||||
}) => {
|
||||
commands: Array<{ command: string; description: string }>;
|
||||
issues: TelegramCustomCommandIssue[];
|
||||
};
|
||||
};
|
||||
|
||||
function loadTelegramCommandConfigContract(): TelegramCommandConfigContract {
|
||||
const contract = getBundledChannelContractSurfaceModule<TelegramCommandConfigContract>({
|
||||
pluginId: "telegram",
|
||||
preferredBasename: "contract-surfaces.ts",
|
||||
});
|
||||
if (!contract) {
|
||||
throw new Error("telegram command config contract surface is unavailable");
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
export const TELEGRAM_COMMAND_NAME_PATTERN =
|
||||
loadTelegramCommandConfigContract().TELEGRAM_COMMAND_NAME_PATTERN;
|
||||
|
||||
export function normalizeTelegramCommandName(value: string): string {
|
||||
return loadTelegramCommandConfigContract().normalizeTelegramCommandName(value);
|
||||
}
|
||||
|
||||
export function normalizeTelegramCommandDescription(value: string): string {
|
||||
return loadTelegramCommandConfigContract().normalizeTelegramCommandDescription(value);
|
||||
}
|
||||
|
||||
export function resolveTelegramCustomCommands(params: {
|
||||
commands?: TelegramCustomCommandInput[] | null;
|
||||
reservedCommands?: Set<string>;
|
||||
checkReserved?: boolean;
|
||||
checkDuplicates?: boolean;
|
||||
}): {
|
||||
commands: Array<{ command: string; description: string }>;
|
||||
issues: TelegramCustomCommandIssue[];
|
||||
} {
|
||||
return loadTelegramCommandConfigContract().resolveTelegramCustomCommands(params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user