diff --git a/convex/automations.ts b/convex/automations.ts index d6abc56..b3ad86b 100644 --- a/convex/automations.ts +++ b/convex/automations.ts @@ -14,7 +14,7 @@ import { } from "./automationsEngine" import { getTemplateByKey, normalizeFormTemplateKey } from "./ticketFormTemplates" import { TICKET_FORM_CONFIG } from "./ticketForms.config" -import { renderAutomationEmailHtml, type AutomationEmailProps } from "./reactEmail" +import type { AutomationEmailProps } from "./reactEmail" import { buildBaseUrl } from "./url" import { applyChecklistTemplateToItems, type TicketChecklistItem } from "./ticketChecklist" @@ -988,12 +988,25 @@ async function applyActions( ctaLabel, ctaUrl, } - const html = await renderAutomationEmailHtml(emailProps) await schedulerRunAfter(1, api.ticketNotifications.sendAutomationEmail, { to, subject, - html, + emailProps: { + title: emailProps.title, + message: emailProps.message, + ticket: { + reference: emailProps.ticket.reference, + subject: emailProps.ticket.subject, + status: emailProps.ticket.status ?? null, + priority: emailProps.ticket.priority ?? null, + companyName: emailProps.ticket.companyName ?? null, + requesterName: emailProps.ticket.requesterName ?? null, + assigneeName: emailProps.ticket.assigneeName ?? null, + }, + ctaLabel: emailProps.ctaLabel, + ctaUrl: emailProps.ctaUrl, + }, }) applied.push({ diff --git a/convex/ticketNotifications.ts b/convex/ticketNotifications.ts index 2116cfd..5b234fd 100644 --- a/convex/ticketNotifications.ts +++ b/convex/ticketNotifications.ts @@ -485,9 +485,23 @@ export const sendAutomationEmail = action({ args: { to: v.array(v.string()), subject: v.string(), - html: v.string(), + emailProps: v.object({ + title: v.string(), + message: v.string(), + ticket: v.object({ + reference: v.number(), + subject: v.string(), + status: v.optional(v.union(v.string(), v.null())), + priority: v.optional(v.union(v.string(), v.null())), + companyName: v.optional(v.union(v.string(), v.null())), + requesterName: v.optional(v.union(v.string(), v.null())), + assigneeName: v.optional(v.union(v.string(), v.null())), + }), + ctaLabel: v.string(), + ctaUrl: v.string(), + }), }, - handler: async (_ctx, { to, subject, html }) => { + handler: async (_ctx, { to, subject, emailProps }) => { const smtp = buildSmtpConfig() if (!smtp) { console.warn("SMTP not configured; skipping automation email") @@ -503,6 +517,24 @@ export const sendAutomationEmail = action({ return { skipped: true, reason: "no_recipients" } } + // Renderiza o HTML aqui (ambiente Node.js suporta imports dinĂ¢micos) + const { renderAutomationEmailHtml } = await import("./reactEmail") + const html = await renderAutomationEmailHtml({ + title: emailProps.title, + message: emailProps.message, + ticket: { + reference: emailProps.ticket.reference, + subject: emailProps.ticket.subject, + status: emailProps.ticket.status ?? null, + priority: emailProps.ticket.priority ?? null, + companyName: emailProps.ticket.companyName ?? null, + requesterName: emailProps.ticket.requesterName ?? null, + assigneeName: emailProps.ticket.assigneeName ?? null, + }, + ctaLabel: emailProps.ctaLabel, + ctaUrl: emailProps.ctaUrl, + }) + for (const recipient of recipients) { await sendSmtpMail(smtp, recipient, subject, html) }