feat: add draft email workflow action (#17793)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
+2
@@ -51,6 +51,8 @@ export class WorkflowActionFactory {
|
||||
return this.logicFunctionWorkflowAction;
|
||||
case WorkflowActionType.SEND_EMAIL:
|
||||
return this.toolExecutorWorkflowAction;
|
||||
case WorkflowActionType.DRAFT_EMAIL:
|
||||
return this.toolExecutorWorkflowAction;
|
||||
case WorkflowActionType.CREATE_RECORD:
|
||||
return this.createRecordWorkflowAction;
|
||||
case WorkflowActionType.UPSERT_RECORD:
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
type WorkflowAction,
|
||||
WorkflowActionType,
|
||||
type WorkflowDraftEmailAction,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||
|
||||
export const isWorkflowDraftEmailAction = (
|
||||
action: WorkflowAction,
|
||||
): action is WorkflowDraftEmailAction => {
|
||||
return action.type === WorkflowActionType.DRAFT_EMAIL;
|
||||
};
|
||||
+12
-6
@@ -4,8 +4,9 @@ import { resolveInput, resolveRichTextVariables } from 'twenty-shared/utils';
|
||||
|
||||
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface';
|
||||
|
||||
import { DraftEmailTool } from 'src/engine/core-modules/tool/tools/email-tool/draft-email-tool';
|
||||
import { HttpTool } from 'src/engine/core-modules/tool/tools/http-tool/http-tool';
|
||||
import { SendEmailTool } from 'src/engine/core-modules/tool/tools/send-email-tool/send-email-tool';
|
||||
import { SendEmailTool } from 'src/engine/core-modules/tool/tools/email-tool/send-email-tool';
|
||||
import { type ToolInput } from 'src/engine/core-modules/tool/types/tool-input.type';
|
||||
import { type Tool } from 'src/engine/core-modules/tool/types/tool.type';
|
||||
import { type WorkflowActionInput } from 'src/modules/workflow/workflow-executor/types/workflow-action-input';
|
||||
@@ -20,10 +21,12 @@ export class ToolExecutorWorkflowAction implements WorkflowAction {
|
||||
constructor(
|
||||
private readonly httpTool: HttpTool,
|
||||
private readonly sendEmailTool: SendEmailTool,
|
||||
private readonly draftEmailTool: DraftEmailTool,
|
||||
) {
|
||||
this.toolsByActionType = new Map<WorkflowActionType, Tool>([
|
||||
[WorkflowActionType.HTTP_REQUEST, this.httpTool],
|
||||
[WorkflowActionType.SEND_EMAIL, this.sendEmailTool],
|
||||
[WorkflowActionType.DRAFT_EMAIL, this.draftEmailTool],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -47,13 +50,16 @@ export class ToolExecutorWorkflowAction implements WorkflowAction {
|
||||
|
||||
let toolInput = step.settings.input;
|
||||
|
||||
if (step.type === WorkflowActionType.SEND_EMAIL) {
|
||||
const sendEmailInput = toolInput as WorkflowSendEmailActionInput;
|
||||
if (
|
||||
step.type === WorkflowActionType.SEND_EMAIL ||
|
||||
step.type === WorkflowActionType.DRAFT_EMAIL
|
||||
) {
|
||||
const emailInput = toolInput as WorkflowSendEmailActionInput;
|
||||
|
||||
if (sendEmailInput.body) {
|
||||
if (emailInput.body) {
|
||||
toolInput = {
|
||||
...sendEmailInput,
|
||||
body: resolveRichTextVariables(sendEmailInput.body, context),
|
||||
...emailInput,
|
||||
body: resolveRichTextVariables(emailInput.body, context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -2,6 +2,7 @@ export enum WorkflowActionType {
|
||||
CODE = 'CODE',
|
||||
LOGIC_FUNCTION = 'LOGIC_FUNCTION',
|
||||
SEND_EMAIL = 'SEND_EMAIL',
|
||||
DRAFT_EMAIL = 'DRAFT_EMAIL',
|
||||
CREATE_RECORD = 'CREATE_RECORD',
|
||||
UPDATE_RECORD = 'UPDATE_RECORD',
|
||||
DELETE_RECORD = 'DELETE_RECORD',
|
||||
|
||||
+6
@@ -51,6 +51,11 @@ export type WorkflowSendEmailAction = BaseWorkflowAction & {
|
||||
settings: WorkflowSendEmailActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowDraftEmailAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.DRAFT_EMAIL;
|
||||
settings: WorkflowSendEmailActionSettings;
|
||||
};
|
||||
|
||||
export type WorkflowCreateRecordAction = BaseWorkflowAction & {
|
||||
type: WorkflowActionType.CREATE_RECORD;
|
||||
settings: WorkflowCreateRecordActionSettings;
|
||||
@@ -119,6 +124,7 @@ export type WorkflowAction =
|
||||
| WorkflowCodeAction
|
||||
| WorkflowLogicFunctionAction
|
||||
| WorkflowSendEmailAction
|
||||
| WorkflowDraftEmailAction
|
||||
| WorkflowCreateRecordAction
|
||||
| WorkflowUpdateRecordAction
|
||||
| WorkflowDeleteRecordAction
|
||||
|
||||
Reference in New Issue
Block a user