Extract auto-reply helpers into modules
This commit is contained in:
20
src/auto-reply/templating.ts
Normal file
20
src/auto-reply/templating.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export type MsgContext = {
|
||||
Body?: string;
|
||||
From?: string;
|
||||
To?: string;
|
||||
MessageSid?: string;
|
||||
};
|
||||
|
||||
export type TemplateContext = MsgContext & {
|
||||
BodyStripped?: string;
|
||||
SessionId?: string;
|
||||
IsNewSession?: string;
|
||||
};
|
||||
|
||||
export function applyTemplate(str: string, ctx: TemplateContext) {
|
||||
// Simple {{Placeholder}} interpolation using inbound message context.
|
||||
return str.replace(/{{\s*(\w+)\s*}}/g, (_, key) => {
|
||||
const value = (ctx as Record<string, unknown>)[key];
|
||||
return value == null ? "" : String(value);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user