- SendEmail: real nodemailer transport with SMTP config, dynamic recipient resolution (static + ticket creator/owner lookup), Handlebars template support - Webhook: HTTP POST/any method with configurable headers and JSON body - FetchMetadata: external HTTP fetch, Handlebars URL/body templating, auto-adds result as comment/correspondence on ticket - RunScript: arbitrary async JS execution with helpers (addComment, createTransaction, updateTicket, touchTicket), ticket context, and Drizzle ORM access - SetCustomField: lookup by id/key/name, clear+insert value, record CustomFieldChange transaction - CreateTransaction: insert arbitrary transaction record - Add OnCustomFieldChange condition - Pass condition_config to evaluator in engine Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
868 B
TypeScript
40 lines
868 B
TypeScript
import Handlebars from 'handlebars';
|
|
|
|
export class TemplateRenderer {
|
|
render(
|
|
subjectTemplate: string,
|
|
bodyTemplate: string,
|
|
context: TemplateContext,
|
|
): { subject: string; body: string } {
|
|
const subjectCompiled = Handlebars.compile(subjectTemplate);
|
|
const bodyCompiled = Handlebars.compile(bodyTemplate);
|
|
return {
|
|
subject: subjectCompiled(context),
|
|
body: bodyCompiled(context),
|
|
};
|
|
}
|
|
}
|
|
|
|
export interface TemplateContext {
|
|
ticket: {
|
|
id: number;
|
|
subject: string;
|
|
status: string;
|
|
queue_id: string;
|
|
owner_id: string | null;
|
|
creator_id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
};
|
|
queue: {
|
|
name: string;
|
|
};
|
|
transaction: {
|
|
type: string;
|
|
field: string | null;
|
|
old_value: string | null;
|
|
new_value: string | null;
|
|
};
|
|
custom_fields: Record<string, string>;
|
|
}
|