Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6658 workflows add a first twenty piece email sender #6965

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Validate email
  • Loading branch information
martmull committed Sep 10, 2024
commit d030c01d9cfa4cfccfbc47a13aada33e04a65cb2
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';

import { WorkflowActionEmail } from 'twenty-emails';
import { render } from '@react-email/components';
import { JSDOM } from 'jsdom';
import DOMPurify from 'dompurify';
import { z } from 'zod';

import { WorkflowSystemAction } from 'src/modules/workflow/workflow-system-action/workflow-system-action.interface';
import { WorkflowSystemStep } from 'src/modules/workflow/common/types/workflow-step.type';
Expand All @@ -14,6 +15,7 @@ import { isDefined } from 'src/utils/is-defined';

@Injectable()
export class SendEmailAction implements WorkflowSystemAction {
private readonly logger = new Logger(SendEmailAction.name);
martmull marked this conversation as resolved.
Show resolved Hide resolved
constructor(
private readonly environmentService: EnvironmentService,
private readonly emailService: EmailService,
Expand All @@ -29,6 +31,16 @@ export class SendEmailAction implements WorkflowSystemAction {
[key: string]: string;
};
}): Promise<WorkflowStepResult> {
const emailSchema = z.string().trim().email('Invalid email');

const result = emailSchema.safeParse(payload.email);

if (!result.success) {
this.logger.warn(`Email '${payload.email}' invalid`);

return { data: { success: false } };
}

let mainText = step.settings.template;

if (isDefined(payload)) {
Expand Down Expand Up @@ -63,6 +75,6 @@ export class SendEmailAction implements WorkflowSystemAction {
html,
});

return { data: {} };
return { data: { success: true } };
}
}
Loading