Support variables file email attachment (#21613)
<!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/21613?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
import { FileFolder } from 'twenty-shared/types';
|
||||
|
||||
export const EMAIL_ATTACHMENT_FILE_FOLDERS = [
|
||||
FileFolder.Workflow,
|
||||
FileFolder.FilesField,
|
||||
FileFolder.EmailAttachment,
|
||||
];
|
||||
-3
@@ -1,7 +1,5 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { FileFolder } from 'twenty-shared/types';
|
||||
|
||||
import { EmailComposerService } from 'src/engine/core-modules/tool/tools/email-tool/email-composer.service';
|
||||
import { EmailToolInputZodSchema } from 'src/engine/core-modules/tool/tools/email-tool/email-tool.schema';
|
||||
import { EmailToolException } from 'src/engine/core-modules/tool/tools/email-tool/exceptions/email-tool.exception';
|
||||
@@ -34,7 +32,6 @@ export class DraftEmailTool implements Tool {
|
||||
const result = await this.emailComposerService.composeEmail(
|
||||
parameters,
|
||||
context,
|
||||
{ attachmentsFileFolder: FileFolder.Workflow },
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
|
||||
+3
-9
@@ -8,7 +8,6 @@ import { MAX_EMAIL_RECIPIENTS } from 'twenty-shared/constants';
|
||||
import {
|
||||
ConnectedAccountProvider,
|
||||
type EmailAttachment,
|
||||
FileFolder,
|
||||
} from 'twenty-shared/types';
|
||||
import { isDefined, isValidUuid } from 'twenty-shared/utils';
|
||||
import { In, IsNull, LessThanOrEqual, type Repository } from 'typeorm';
|
||||
@@ -16,6 +15,7 @@ import { z } from 'zod';
|
||||
|
||||
import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';
|
||||
import { FileService } from 'src/engine/core-modules/file/services/file.service';
|
||||
import { EMAIL_ATTACHMENT_FILE_FOLDERS } from 'src/engine/core-modules/tool/tools/email-tool/constants/email-attachment-file-folders.const';
|
||||
import {
|
||||
EmailToolException,
|
||||
EmailToolExceptionCode,
|
||||
@@ -185,7 +185,6 @@ export class EmailComposerService {
|
||||
private async getAttachments(
|
||||
files: Array<EmailAttachment>,
|
||||
workspaceId: string,
|
||||
fileFolder: FileFolder,
|
||||
): Promise<MessageAttachment[]> {
|
||||
if (files.length === 0) {
|
||||
return [];
|
||||
@@ -224,7 +223,7 @@ export class EmailComposerService {
|
||||
const fileStream = await this.fileService.getFileStreamById({
|
||||
fileId: fileMetadata.id,
|
||||
workspaceId,
|
||||
fileFolder,
|
||||
allowedFileFolders: EMAIL_ATTACHMENT_FILE_FOLDERS,
|
||||
});
|
||||
|
||||
if (fileStream === null) {
|
||||
@@ -312,7 +311,6 @@ export class EmailComposerService {
|
||||
async composeEmail(
|
||||
parameters: ComposeEmailParams,
|
||||
context: ToolExecutionContext,
|
||||
options: { attachmentsFileFolder: FileFolder },
|
||||
): Promise<EmailComposerResult> {
|
||||
const { workspaceId } = context;
|
||||
const { subject, body, files, inReplyTo } = parameters;
|
||||
@@ -390,11 +388,7 @@ export class EmailComposerService {
|
||||
);
|
||||
}
|
||||
|
||||
const attachments = await this.getAttachments(
|
||||
files || [],
|
||||
workspaceId,
|
||||
options.attachmentsFileFolder,
|
||||
);
|
||||
const attachments = await this.getAttachments(files || [], workspaceId);
|
||||
|
||||
const { JSDOM } = await import('jsdom');
|
||||
const window = new JSDOM('').window;
|
||||
|
||||
-3
@@ -1,7 +1,5 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { FileFolder } from 'twenty-shared/types';
|
||||
|
||||
import { EmailComposerService } from 'src/engine/core-modules/tool/tools/email-tool/email-composer.service';
|
||||
import { EmailToolInputZodSchema } from 'src/engine/core-modules/tool/tools/email-tool/email-tool.schema';
|
||||
import { EmailToolException } from 'src/engine/core-modules/tool/tools/email-tool/exceptions/email-tool.exception';
|
||||
@@ -33,7 +31,6 @@ export class SendEmailTool implements Tool {
|
||||
const result = await this.emailComposerService.composeEmail(
|
||||
parameters,
|
||||
context,
|
||||
{ attachmentsFileFolder: FileFolder.Workflow },
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
|
||||
Reference in New Issue
Block a user