openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
26 lines (25 loc) • 849 B
JavaScript
//#region src/auto-reply/reply/context-text.ts
/** Returns the first string field from a finalized message context. */
function resolveFirstContextText(ctx, keys) {
for (const key of keys) {
const value = ctx[key];
if (typeof value === "string") return value;
}
return "";
}
/** Resolves normalized text for slash/bang command parsing. */
function resolveCommandContextText(ctx) {
return resolveFirstContextText(ctx, [
"BodyForCommands",
"CommandBody",
"RawBody",
"Body"
]).trim();
}
/** Checks whether the inbound context carries an explicit command prefix. */
function hasExplicitCommandContextText(ctx) {
const text = resolveCommandContextText(ctx);
return text.startsWith("/") || text.startsWith("!");
}
//#endregion
export { resolveCommandContextText as n, resolveFirstContextText as r, hasExplicitCommandContextText as t };