Files
openclaw/src/auto-reply/templating.ts

39 lines
951 B
TypeScript
Raw Normal View History

export type MsgContext = {
Body?: string;
From?: string;
To?: string;
2026-01-02 00:11:03 -06:00
SessionKey?: string;
MessageSid?: string;
ReplyToId?: string;
ReplyToBody?: string;
ReplyToSender?: string;
MediaPath?: string;
MediaUrl?: string;
MediaType?: string;
Transcript?: string;
ChatType?: string;
GroupSubject?: string;
GroupRoom?: string;
GroupSpace?: string;
GroupMembers?: string;
SenderName?: string;
SenderE164?: string;
2025-12-06 23:16:23 +01:00
Surface?: string;
2025-12-23 14:17:18 +00:00
WasMentioned?: boolean;
};
export type TemplateContext = MsgContext & {
BodyStripped?: string;
SessionId?: string;
IsNewSession?: string;
};
// Simple {{Placeholder}} interpolation using inbound message context.
export function applyTemplate(str: string | undefined, ctx: TemplateContext) {
if (!str) return "";
return str.replace(/{{\s*(\w+)\s*}}/g, (_, key) => {
2025-12-23 00:28:40 +00:00
const value = ctx[key as keyof TemplateContext];
2025-12-24 00:57:11 +00:00
return value == null ? "" : String(value);
});
}