openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
23 lines (22 loc) • 887 B
JavaScript
//#region src/plugin-sdk/webhook-path.ts
/** Normalize webhook paths into the canonical registry form used by route lookup. */
function normalizeWebhookPath(raw) {
const trimmed = raw.trim();
if (!trimmed) return "/";
const withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
if (withSlash.length > 1 && withSlash.endsWith("/")) return withSlash.slice(0, -1);
return withSlash;
}
/** Resolve the effective webhook path from explicit path, URL, or default fallback. */
function resolveWebhookPath(params) {
const trimmedPath = params.webhookPath?.trim();
if (trimmedPath) return normalizeWebhookPath(trimmedPath);
if (params.webhookUrl?.trim()) try {
return normalizeWebhookPath(new URL(params.webhookUrl).pathname || "/");
} catch {
return null;
}
return params.defaultPath ?? null;
}
//#endregion
export { resolveWebhookPath as n, normalizeWebhookPath as t };