fix(automations): corrige erro de import dinamico no envio de email
Some checks failed
CI/CD Web + Desktop / Detect changes (push) Successful in 7s
Quality Checks / Lint, Test and Build (push) Failing after 2m45s
CI/CD Web + Desktop / Deploy (VPS Linux) (push) Successful in 3m41s
CI/CD Web + Desktop / Deploy Convex functions (push) Successful in 1m44s

- Move renderizacao do React Email para a action Node.js
- Passa props do email em vez do HTML ja renderizado
- Resolve erro "dynamic module import unsupported"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rever-tecnologia 2025-12-17 15:23:39 -03:00
parent bddce33217
commit b8170d0225
2 changed files with 50 additions and 5 deletions

View file

@ -14,7 +14,7 @@ import {
} from "./automationsEngine" } from "./automationsEngine"
import { getTemplateByKey, normalizeFormTemplateKey } from "./ticketFormTemplates" import { getTemplateByKey, normalizeFormTemplateKey } from "./ticketFormTemplates"
import { TICKET_FORM_CONFIG } from "./ticketForms.config" import { TICKET_FORM_CONFIG } from "./ticketForms.config"
import { renderAutomationEmailHtml, type AutomationEmailProps } from "./reactEmail" import type { AutomationEmailProps } from "./reactEmail"
import { buildBaseUrl } from "./url" import { buildBaseUrl } from "./url"
import { applyChecklistTemplateToItems, type TicketChecklistItem } from "./ticketChecklist" import { applyChecklistTemplateToItems, type TicketChecklistItem } from "./ticketChecklist"
@ -988,12 +988,25 @@ async function applyActions(
ctaLabel, ctaLabel,
ctaUrl, ctaUrl,
} }
const html = await renderAutomationEmailHtml(emailProps)
await schedulerRunAfter(1, api.ticketNotifications.sendAutomationEmail, { await schedulerRunAfter(1, api.ticketNotifications.sendAutomationEmail, {
to, to,
subject, 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({ applied.push({

View file

@ -485,9 +485,23 @@ export const sendAutomationEmail = action({
args: { args: {
to: v.array(v.string()), to: v.array(v.string()),
subject: 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() const smtp = buildSmtpConfig()
if (!smtp) { if (!smtp) {
console.warn("SMTP not configured; skipping automation email") console.warn("SMTP not configured; skipping automation email")
@ -503,6 +517,24 @@ export const sendAutomationEmail = action({
return { skipped: true, reason: "no_recipients" } 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) { for (const recipient of recipients) {
await sendSmtpMail(smtp, recipient, subject, html) await sendSmtpMail(smtp, recipient, subject, html)
} }