2025-11-25 02:16:54 +01:00
|
|
|
export type MsgContext = {
|
2025-11-26 00:53:53 +01:00
|
|
|
Body?: string;
|
|
|
|
|
From?: string;
|
|
|
|
|
To?: string;
|
2026-01-02 00:11:03 -06:00
|
|
|
SessionKey?: string;
|
2025-11-26 00:53:53 +01:00
|
|
|
MessageSid?: string;
|
2025-12-23 02:25:26 +01:00
|
|
|
ReplyToId?: string;
|
|
|
|
|
ReplyToBody?: string;
|
|
|
|
|
ReplyToSender?: string;
|
2025-11-26 00:53:53 +01:00
|
|
|
MediaPath?: string;
|
|
|
|
|
MediaUrl?: string;
|
|
|
|
|
MediaType?: string;
|
|
|
|
|
Transcript?: string;
|
2025-12-03 13:33:32 +00:00
|
|
|
ChatType?: string;
|
|
|
|
|
GroupSubject?: string;
|
2026-01-02 11:15:52 +01:00
|
|
|
GroupRoom?: string;
|
|
|
|
|
GroupSpace?: string;
|
2025-12-03 13:33:32 +00:00
|
|
|
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;
|
2025-11-25 02:16:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type TemplateContext = MsgContext & {
|
2025-11-26 00:53:53 +01:00
|
|
|
BodyStripped?: string;
|
|
|
|
|
SessionId?: string;
|
|
|
|
|
IsNewSession?: string;
|
2025-11-25 02:16:54 +01:00
|
|
|
};
|
|
|
|
|
|
2025-11-25 03:11:39 +01:00
|
|
|
// Simple {{Placeholder}} interpolation using inbound message context.
|
2025-12-06 00:49:46 +01:00
|
|
|
export function applyTemplate(str: string | undefined, ctx: TemplateContext) {
|
|
|
|
|
if (!str) return "";
|
2025-11-26 00:53:53 +01:00
|
|
|
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);
|
2025-11-26 00:53:53 +01:00
|
|
|
});
|
2025-11-25 02:16:54 +01:00
|
|
|
}
|