-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
33 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/twenty-emails/src/emails/workflow-action.email.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { BaseEmail } from 'src/components/BaseEmail'; | ||
import { Title } from 'src/components/Title'; | ||
import { MainText } from 'src/components/MainText'; | ||
import { CallToAction } from 'src/components/CallToAction'; | ||
|
||
type WorkflowActionEmailProps = { | ||
mainText?: string; | ||
title?: string; | ||
callToAction?: { | ||
value: string; | ||
href: string; | ||
}; | ||
}; | ||
export const WorkflowActionEmail = ({ | ||
mainText, | ||
title, | ||
callToAction, | ||
}: WorkflowActionEmailProps) => { | ||
return ( | ||
<BaseEmail> | ||
{title && <Title value={title} />} | ||
{mainText && <MainText>{mainText}</MainText>} | ||
{callToAction && ( | ||
<CallToAction value={callToAction.value} href={callToAction.href} /> | ||
)} | ||
</BaseEmail> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...s/twenty-server/src/modules/workflow/common/types/settings/workflow-base-settings.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type BaseWorkflowSettings = { | ||
errorHandlingOptions: { | ||
retryOnFailure: { | ||
value: boolean; | ||
}; | ||
continueOnFailure: { | ||
value: boolean; | ||
}; | ||
}; | ||
}; |
5 changes: 5 additions & 0 deletions
5
...s/twenty-server/src/modules/workflow/common/types/settings/workflow-code-settings.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BaseWorkflowSettings } from 'src/modules/workflow/common/types/settings/workflow-base-settings.type'; | ||
|
||
export type WorkflowCodeSettings = BaseWorkflowSettings & { | ||
serverlessFunctionId: string; | ||
}; |
19 changes: 19 additions & 0 deletions
19
...server/src/modules/workflow/common/types/settings/workflow-system-action-settings.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BaseWorkflowSettings } from 'src/modules/workflow/common/types/settings/workflow-base-settings.type'; | ||
import { WorkflowSystemActionType } from 'src/modules/workflow/common/types/workflow-system-action.type'; | ||
|
||
type BaseSystemActionSettings = BaseWorkflowSettings & { | ||
systemActionType: WorkflowSystemActionType; | ||
}; | ||
|
||
export type WorkflowSystemSendEmailActionSettings = BaseSystemActionSettings & { | ||
subject: string; | ||
template?: string; | ||
title?: string; | ||
callToAction?: { | ||
value: string; | ||
href: string; | ||
}; | ||
}; | ||
|
||
export type WorkflowSystemActionSettings = | ||
WorkflowSystemSendEmailActionSettings; |
20 changes: 0 additions & 20 deletions
20
packages/twenty-server/src/modules/workflow/common/types/workflow-settings.type.ts
This file was deleted.
Oops, something went wrong.
6 changes: 2 additions & 4 deletions
6
packages/twenty-server/src/modules/workflow/common/types/workflow-step.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 49 additions & 9 deletions
58
.../src/modules/workflow/workflow-system-action/workflow-system-actions/send-email-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,63 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { WorkflowActionEmail } from 'twenty-emails'; | ||
import { render } from '@react-email/components'; | ||
|
||
import { WorkflowSystemAction } from 'src/modules/workflow/workflow-system-action/workflow-system-action.interface'; | ||
import { WorkflowStep } from 'src/modules/workflow/common/types/workflow-step.type'; | ||
import { WorkflowSystemStep } from 'src/modules/workflow/common/types/workflow-step.type'; | ||
import { WorkflowStepResult } from 'src/modules/workflow/common/types/workflow-step-result.type'; | ||
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service'; | ||
import { EmailService } from 'src/engine/integrations/email/email.service'; | ||
import { isDefined } from 'src/utils/is-defined'; | ||
|
||
@Injectable() | ||
export class SendEmailAction implements WorkflowSystemAction { | ||
constructor( | ||
private readonly environmentService: EnvironmentService, | ||
private readonly emailService: EmailService, | ||
) {} | ||
|
||
async execute({ | ||
step, | ||
payload, | ||
}: { | ||
step: WorkflowStep; | ||
payload?: object; | ||
}): Promise<WorkflowStepResult> { | ||
return { | ||
data: { | ||
step, | ||
payload, | ||
}, | ||
step: WorkflowSystemStep; | ||
payload: { | ||
email: string; | ||
[key: string]: string; | ||
}; | ||
}): Promise<WorkflowStepResult> { | ||
let mainText = step.settings.template; | ||
|
||
if (isDefined(payload)) { | ||
Object.keys(payload).forEach( | ||
(key: string) => | ||
(mainText = mainText?.replace(`{{${key}}}`, payload[key])), | ||
); | ||
} | ||
|
||
const email = WorkflowActionEmail({ | ||
mainText: mainText, | ||
title: step.settings.title, | ||
callToAction: step.settings.callToAction, | ||
}); | ||
const html = render(email, { | ||
pretty: true, | ||
}); | ||
const text = render(email, { | ||
plainText: true, | ||
}); | ||
|
||
await this.emailService.send({ | ||
from: `${this.environmentService.get( | ||
'EMAIL_FROM_NAME', | ||
)} <${this.environmentService.get('EMAIL_FROM_ADDRESS')}>`, | ||
to: payload.email, | ||
subject: step.settings.subject, | ||
text, | ||
html, | ||
}); | ||
|
||
return { data: null }; | ||
} | ||
} |