feat: move workflow emails to smtp (#20293)
Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
20 files changed
+423
-158
No files matched your search
@@ -48,4 +48,8 @@ export class InternalTasker implements Tasker {
|
||||
const count = await Task.cleanup();
|
||||
console.info(`Cleaned up ${count} tasks`);
|
||||
}
|
||||
async cancel(id: string): Promise<string> {
|
||||
const task = await Task.cancel(id);
|
||||
return task.id;
|
||||
}
|
||||
}
|
||||
@@ -40,9 +40,9 @@ export class Task {
|
||||
static async create(
|
||||
type: TaskTypes,
|
||||
payload: string,
|
||||
options: { scheduledAt?: Date; maxAttempts?: number } = {}
|
||||
options: { scheduledAt?: Date; maxAttempts?: number; referenceUid?: string } = {}
|
||||
) {
|
||||
const { scheduledAt, maxAttempts } = options;
|
||||
const { scheduledAt, maxAttempts, referenceUid } = options;
|
||||
console.info("Creating task", { type, payload, scheduledAt, maxAttempts });
|
||||
const newTask = await db.task.create({
|
||||
data: {
|
||||
@@ -50,6 +50,7 @@ export class Task {
|
||||
type,
|
||||
scheduledAt,
|
||||
maxAttempts,
|
||||
referenceUid,
|
||||
},
|
||||
});
|
||||
return newTask.id;
|
||||
|
||||
@@ -18,6 +18,7 @@ type TaskPayloads = {
|
||||
typeof import("./tasks/translateEventTypeData").ZTranslateEventDataPayloadSchema
|
||||
>;
|
||||
createCRMEvent: z.infer<typeof import("./tasks/crm/schema").createCRMEventSchema>;
|
||||
sendWorkflowEmails: z.infer<typeof import("./tasks/sendWorkflowEmails").ZSendWorkflowEmailsSchema>;
|
||||
scanWorkflowBody: z.infer<typeof import("./tasks/scanWorkflowBody").scanWorkflowBodySchema>;
|
||||
};
|
||||
export type TaskTypes = keyof TaskPayloads;
|
||||
@@ -25,11 +26,12 @@ export type TaskHandler = (payload: string) => Promise<void>;
|
||||
export type TaskerCreate = <TaskKey extends keyof TaskPayloads>(
|
||||
type: TaskKey,
|
||||
payload: TaskPayloads[TaskKey],
|
||||
options?: { scheduledAt?: Date; maxAttempts?: number }
|
||||
options?: { scheduledAt?: Date; maxAttempts?: number; referenceUid?: string }
|
||||
) => Promise<string>;
|
||||
export interface Tasker {
|
||||
/** Create a new task with the given type and payload. */
|
||||
create: TaskerCreate;
|
||||
processQueue(): Promise<void>;
|
||||
cleanup(): Promise<void>;
|
||||
cancel(id: string): Promise<string>;
|
||||
}
|
||||
@@ -22,6 +22,7 @@ const tasks: Record<TaskTypes, () => Promise<TaskHandler>> = {
|
||||
translateEventTypeData: () =>
|
||||
import("./translateEventTypeData").then((module) => module.translateEventTypeData),
|
||||
createCRMEvent: () => import("./crm/createCRMEvent").then((module) => module.createCRMEvent),
|
||||
sendWorkflowEmails: () => import("./sendWorkflowEmails").then((module) => module.sendWorkflowEmails),
|
||||
scanWorkflowBody: () => import("./scanWorkflowBody").then((module) => module.scanWorkflowBody),
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { sendCustomWorkflowEmail } from "@calcom/emails";
|
||||
|
||||
export const ZSendWorkflowEmailsSchema = z.object({
|
||||
to: z.array(z.string()),
|
||||
subject: z.string(),
|
||||
html: z.string(),
|
||||
replyTo: z.string(),
|
||||
sender: z.string().nullable().optional(),
|
||||
attachments: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
content: z.string(),
|
||||
filename: z.string(),
|
||||
})
|
||||
.passthrough()
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export async function sendWorkflowEmails(payload: string): Promise<void> {
|
||||
const mailData = ZSendWorkflowEmailsSchema.parse(JSON.parse(payload));
|
||||
|
||||
await Promise.all(
|
||||
mailData.to.map((to) =>
|
||||
sendCustomWorkflowEmail({
|
||||
...mailData,
|
||||
to,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user