From 2fe9a5786d7e896dd318d7b26e80b1fd24d8bf9b Mon Sep 17 00:00:00 2001 From: Montassar Ghanmy Date: Fri, 1 Dec 2023 08:57:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Updated=20email=20notifications=20t?= =?UTF-8?q?emplates=20(#287)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/custom-environment-variables.json | 12 +++--- tdrive/backend/node/package.json | 1 + .../platform/services/email-pusher/index.ts | 16 +++++-- .../templates/common/_structure.eta | 6 +-- .../email-pusher/templates/en/_structure.eta | 6 +-- .../templates/en/notification-digest.eta | 2 +- .../en/notification-document-shared.eta | 43 +++++++++++++++++++ ... notification-document-shared.subject.eta} | 0 ...notification-document-version-updated.eta} | 18 ++++---- ...ation-document-version-updated.subject.eta | 1 + .../email-pusher/templates/fr/_structure.eta | 6 +-- .../templates/fr/notification-digest.eta | 2 +- .../fr/notification-document-shared.eta | 43 +++++++++++++++++++ .../notification-document-shared.subject.eta | 1 + .../notification-document-version-updated.eta | 43 +++++++++++++++++++ ...ation-document-version-updated.subject.eta | 1 + .../platform/services/email-pusher/types.ts | 4 +- .../documents/services/engine/index.ts | 6 ++- 18 files changed, 179 insertions(+), 32 deletions(-) create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.eta rename tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/{notification-document.subject.eta => notification-document-shared.subject.eta} (100%) rename tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/{notification-document.eta => notification-document-version-updated.eta} (60%) create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.subject.eta create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.eta create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.subject.eta create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.eta create mode 100644 tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.subject.eta diff --git a/tdrive/backend/node/config/custom-environment-variables.json b/tdrive/backend/node/config/custom-environment-variables.json index b2e026cf..75146a0b 100644 --- a/tdrive/backend/node/config/custom-environment-variables.json +++ b/tdrive/backend/node/config/custom-environment-variables.json @@ -63,7 +63,6 @@ "useAuth": "SEARCH_ES_USE_AUTH", "username": "SEARCH_ES_USERNAME", "password": "SEARCH_ES_PASSWORD" - } }, "storage": { @@ -83,17 +82,18 @@ "secretKey": "STORAGE_S3_SECRET_KEY" } }, - "email-pusher":{ + "email-pusher": { "email_interface": "EMAIL_INTERFACE", - "endpoint":"EMAIL_ENDPOINT", - "api_key":"EMAIL_API_KEY", - "sender":"EMAIL_SENDER", + "endpoint": "EMAIL_ENDPOINT", + "api_key": "EMAIL_API_KEY", + "sender": "EMAIL_SENDER", "smtp_user": "EMAIL_SMTP_USER", "smtp_password": "EMAIL_SMTP_PASSWORD", "smtp_host": "EMAIL_SMTP_HOST", "smtp_port": "EMAIL_SMTP_PORT", "smtp_tls": "EMAIL_SMTP_SECURE", - "debug": "EMAIL_DEBUG" + "debug": "EMAIL_DEBUG", + "platform_url": "PLATFORM_URL" }, "message-queue": { "type": "PUBSUB_TYPE", diff --git a/tdrive/backend/node/package.json b/tdrive/backend/node/package.json index ebf090ca..aaecc10c 100644 --- a/tdrive/backend/node/package.json +++ b/tdrive/backend/node/package.json @@ -175,6 +175,7 @@ "reflect-metadata": "^0.1.13", "rxjs": "^6.6.3", "sharp": "^0.30.5", + "short-uuid": "^4.2.2", "socket.io": "^4.6.2", "socket.io-client": "^3.0.0", "unoconv-promise": "^1.0.8", diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/index.ts b/tdrive/backend/node/src/core/platform/services/email-pusher/index.ts index 9387c892..bae15102 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/index.ts +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/index.ts @@ -15,6 +15,7 @@ import { convert } from "html-to-text"; import path from "path"; import { existsSync } from "fs"; import axios from "axios"; +import short, { Translator } from "short-uuid"; export default class EmailPusherClass extends TdriveService @@ -29,6 +30,7 @@ export default class EmailPusherClass sender: string; transporter: any; debug: boolean; + platformUrl: string; api(): EmailPusherAPI { return this; @@ -39,6 +41,7 @@ export default class EmailPusherClass views: path.join(__dirname, "templates"), }); this.interface = this.configuration.get("email_interface", ""); + this.platformUrl = this.configuration.get("platform_url", ""); if (this.interface === "smtp") { const smtpConfig: SMTPClientConfigType = { host: this.configuration.get("smtp_host", ""), @@ -73,8 +76,12 @@ export default class EmailPusherClass ): Promise { try { language = ["en", "fr"].find(l => language.toLocaleLowerCase().includes(l)) || "en"; + const translator: Translator = short(); const templatePath = path.join(__dirname, "templates", language, `${template}.eta`); const subjectPath = path.join(__dirname, "templates", language, `${template}.subject.eta`); + const encodedCompanyId = translator.fromUUID(data.notifications[0].item.company_id); + const encodedFileId = translator.fromUUID(data.notifications[0].item.id); + const encodedUrl = `${this.platformUrl}/client/${encodedCompanyId}/v/shared_with_me/preview/${encodedFileId}`; if (!existsSync(templatePath)) { throw Error(`template not found: ${templatePath}`); @@ -83,8 +90,11 @@ export default class EmailPusherClass if (!existsSync(subjectPath)) { throw Error(`subject template not found: ${subjectPath}`); } - - const html = await Eta.renderFile(templatePath, data); + console.log("🚀 FILE LINK: ", encodedUrl); + const html = await Eta.renderFile(templatePath, { + ...data, + encodedUrl, + }); if (!html || !html.length) { throw Error("Failed to render template"); @@ -134,7 +144,7 @@ export default class EmailPusherClass try { this.logger.info("sending email via smtp interface."); const info = await this.transporter.sendMail({ - from: `"Sender Name" <${this.sender}>`, + from: `"Twake Drive" <${this.sender}>`, to: to, subject: subject, text: text_body, diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/common/_structure.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/common/_structure.eta index 79d7b43d..a0f71c8a 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/common/_structure.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/common/_structure.eta @@ -210,10 +210,8 @@ - headerImage + headerImage diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/_structure.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/_structure.eta index d7e393cb..06cf7e1f 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/_structure.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/_structure.eta @@ -5,8 +5,8 @@ privacy: "Privacy Policy", terms: "Terms of Service", links: { - help: "https://tdrive.app/", - privacy: "https://tdrive.app/en/privacy-policy/", - terms: "https://tdrive.app/en/terms-of-service/" + help: "#", + privacy: "#", + terms: "#" } })) %> \ No newline at end of file diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-digest.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-digest.eta index 8c74a8f4..d3fe306b 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-digest.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-digest.eta @@ -35,7 +35,7 @@ ` ` diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.eta new file mode 100644 index 00000000..dd2e483c --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.eta @@ -0,0 +1,43 @@ +<% layout('./_structure') %> +<% it.title = 'Missed notifications from company ' %> + +<%~ includeFile("../common/_body.eta", { + paragraphs: [ + ` + + + + + + +
+
+ You've got some updates on your Twake Drive! +
+
+ `, + ` + + + + + + +
+
+ ${it.sender.first_name} shared a ${it.notifications[0].item.is_directory ? "folder" : "file" } with you! ${it.notifications[0].item.is_directory ? "📁" : "📄" } +
+
+ + ${!it.notifications[0].item.is_directory ? `${it.notifications[0].item.name}.${it.notifications[0].item.extension}` : `${it.notifications[0].item.name}.${it.notifications[0].item.extension}`} + +
+
+ + ` + ] +}) %> \ No newline at end of file diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document.subject.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.subject.eta similarity index 100% rename from tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document.subject.eta rename to tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-shared.subject.eta diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.eta similarity index 60% rename from tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document.eta rename to tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.eta index 12a6d84b..83d3d555 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.eta @@ -1,5 +1,5 @@ <% layout('./_structure') %> -<% it.title = 'Missed notifications from company ' + it.company.name %> +<% it.title = 'Missed notifications from company ' %> <%~ includeFile("../common/_body.eta", { paragraphs: [ @@ -22,20 +22,20 @@
- A new document has been shared with you! 📄 + ${it.sender.first_name} updated this ${it.notifications[0].item.is_directory ? "folder" : "file" }! ${it.notifications[0].item.is_directory ? "📁" : "📄" } +
+
+ + ${!it.notifications[0].item.is_directory ? `${it.notifications[0].item.name}.${it.notifications[0].item.extension}` : `${it.notifications[0].item.name}.${it.notifications[0].item.extension}`} +
- `, - ...it.notifications.map(notification => - includeFile("./notification-document/notification.eta", notification) - ), - ` ` diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.subject.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.subject.eta new file mode 100644 index 00000000..098a3d20 --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/en/notification-document-version-updated.subject.eta @@ -0,0 +1 @@ +Missed notifications in your company <%= it.company.name %> diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/_structure.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/_structure.eta index c6dc00dd..a2da560f 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/_structure.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/_structure.eta @@ -5,8 +5,8 @@ privacy: "Confidentialité", terms: "CGU", links: { - help: "https://tdrive.app/", - privacy: "https://tdrive.app/fr/privacy-policy/", - terms: "https://tdrive.app/fr/terms-of-service/" + help: "#", + privacy: "#", + terms: "#" } })) %> \ No newline at end of file diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-digest.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-digest.eta index 01b6a4e1..9e53f550 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-digest.eta +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-digest.eta @@ -37,7 +37,7 @@ ` ` diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.eta new file mode 100644 index 00000000..7d01264c --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.eta @@ -0,0 +1,43 @@ +<% layout('./_structure') %> +<% it.title = 'Missed notifications from company ' %> + +<%~ includeFile("../common/_body.eta", { + paragraphs: [ + ` + + + + + + +
+
+ Vous avez des nouvelles concernant votre Twake Drive ! +
+
+ `, + ` + + + + + + +
+
+ ${it.sender.first_name} shared a ${it.notifications[0].item.is_directory ? "folder" : "file" } with you! ${it.notifications[0].item.is_directory ? "📁" : "📄" } +
+
+ + ${!it.notifications[0].item.is_directory ? `${it.notifications[0].item.name}.${it.notifications[0].item.extension}` : `${it.notifications[0].item.name}.${it.notifications[0].item.extension}`} + +
+
+ + ` + ] +}) %> \ No newline at end of file diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.subject.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.subject.eta new file mode 100644 index 00000000..a402f827 --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-shared.subject.eta @@ -0,0 +1 @@ +Notifications manquées dans votre entreprise <%= it.company.name %> diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.eta new file mode 100644 index 00000000..906b8ed1 --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.eta @@ -0,0 +1,43 @@ +<% layout('./_structure') %> +<% it.title = 'Missed notifications from company ' %> + +<%~ includeFile("../common/_body.eta", { + paragraphs: [ + ` + + + + + + +
+
+ Vous avez des nouvelles concernant votre Twake Drive ! +
+
+ `, + ` + + + + + + +
+
+ ${it.sender.first_name} updated this ${it.notifications[0].item.is_directory ? "folder" : "file" }! ${it.notifications[0].item.is_directory ? "📁" : "📄" } +
+
+ + ${!it.notifications[0].item.is_directory ? `${it.notifications[0].item.name}.${it.notifications[0].item.extension}` : `${it.notifications[0].item.name}.${it.notifications[0].item.extension}`} + +
+
+ + ` + ] +}) %> \ No newline at end of file diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.subject.eta b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.subject.eta new file mode 100644 index 00000000..a402f827 --- /dev/null +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/templates/fr/notification-document-version-updated.subject.eta @@ -0,0 +1 @@ +Notifications manquées dans votre entreprise <%= it.company.name %> diff --git a/tdrive/backend/node/src/core/platform/services/email-pusher/types.ts b/tdrive/backend/node/src/core/platform/services/email-pusher/types.ts index e244deb9..3682ad9d 100644 --- a/tdrive/backend/node/src/core/platform/services/email-pusher/types.ts +++ b/tdrive/backend/node/src/core/platform/services/email-pusher/types.ts @@ -18,7 +18,9 @@ export type EmailBuilderRenderedResult = { subject: string; }; -export type EmailBuilderTemplateName = "notification-digest" | "notification-document"; +export type EmailBuilderTemplateName = + | "notification-document-shared" + | "notification-document-version-updated"; export type EmailPusherPayload = { subject: string; diff --git a/tdrive/backend/node/src/services/documents/services/engine/index.ts b/tdrive/backend/node/src/services/documents/services/engine/index.ts index 6ea31e74..6257c813 100644 --- a/tdrive/backend/node/src/services/documents/services/engine/index.ts +++ b/tdrive/backend/node/src/services/documents/services/engine/index.ts @@ -16,9 +16,13 @@ export class DocumentsEngine implements Initializable { const company = await globalResolver.services.companies.getCompany({ id: e.context.company.id, }); + const emailTemplate = + event === DocumentEvents.DOCUMENT_SAHRED + ? "notification-document-shared" + : "notification-document-version-updated"; try { const { html, text, subject } = await globalResolver.platformServices.emailPusher.build( - "notification-document", + emailTemplate, receiver.language || "en", { sender,