From 499853c9c7e1d41903a05b159e55999469392ab3 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Fri, 13 Apr 2018 16:04:18 +0530 Subject: [PATCH 1/4] swagger api changes for v5. --- docs/swagger_api.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/swagger_api.yaml b/docs/swagger_api.yaml index 4838664..d60fa0e 100644 --- a/docs/swagger_api.yaml +++ b/docs/swagger_api.yaml @@ -4,8 +4,9 @@ info: description: "TOPCODER EMAIL SERIES - EMAIL SERVER" version: "1.0.0" host: "localhost:4001" +basePath : "/v5/email" schemes: -- "http" +- "https" securityDefinitions: jwt: type: apiKey @@ -14,7 +15,7 @@ securityDefinitions: description: JWT Authentication. Provide API Key in the form 'Bearer <token>'. paths: - /templates/eventType/{name}: + /templates/{name}: get: description: get email template placholders name From 7450fa5b2589b1cc97f67f2c3b96c73d9ac3ff1c Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 25 Apr 2018 13:59:38 +0530 Subject: [PATCH 2/4] 'from' and multiple 'categories' support. --- connect/connectEmailServer.js | 3 +-- connect/service.js | 16 ++++++++++++---- test/emailServiceTest.js | 3 +-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/connect/connectEmailServer.js b/connect/connectEmailServer.js index 30bb293..5856b54 100644 --- a/connect/connectEmailServer.js +++ b/connect/connectEmailServer.js @@ -26,8 +26,7 @@ const handler = (topic, message, callback) => { return callback(null, { success: false, error: `Template not found for topic ${topic}` }); } - const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; - service.sendEmail(templateId, message.recipients, message.data, replyTo).then(() => { + service.sendEmail(templateId, message).then(() => { callback(null, { success: true }); }).catch((err) => { callback(null, { success: false, error: err }); diff --git a/connect/service.js b/connect/service.js index 10c860b..9a31e7e 100644 --- a/connect/service.js +++ b/connect/service.js @@ -9,16 +9,24 @@ const config = require('config'); // set api key for SendGrid email client sgMail.setApiKey(config.SENDGRID_API_KEY); -const sendEmail = (templateId, to, substitutions, replyTo) => // send email - sgMail.send({ +const sendEmail = (templateId, message) => { // send email + + const from = message.from ? message.from : config.EMAIL_FROM; + const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; + const substitutions = message.data ; + const categories = message.categories ? message.categories: []; + const to = message.recipients; + + return sgMail.send({ to, templateId, substitutions, - from: config.EMAIL_FROM, + from, substitutionWrappers: ['{{', '}}'], replyTo, + categories, }); - +} module.exports = { sendEmail, } diff --git a/test/emailServiceTest.js b/test/emailServiceTest.js index 2b25a0f..68d52a7 100644 --- a/test/emailServiceTest.js +++ b/test/emailServiceTest.js @@ -24,8 +24,7 @@ const defaultHandler = (topic, message, callback) => { } // send email - const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM; - service.sendEmail(templateId, message.recipients, message.data).then(() => { + service.sendEmail(templateId, message).then(() => { callback(null, { success: true }); finish(null); }).catch((err) => { From 92aa6b414b00f73b9316e8052a61ffbe6f032bf9 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 25 Apr 2018 15:08:00 +0530 Subject: [PATCH 3/4] adding support for 'cc' and 'bcc'. --- connect/service.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connect/service.js b/connect/service.js index 9a31e7e..4750b9b 100644 --- a/connect/service.js +++ b/connect/service.js @@ -16,6 +16,8 @@ const sendEmail = (templateId, message) => { // send email const substitutions = message.data ; const categories = message.categories ? message.categories: []; const to = message.recipients; + const cc = message.cc ? message.cc : []; + const bcc = message.bcc ? message.bcc : []; return sgMail.send({ to, @@ -25,6 +27,8 @@ const sendEmail = (templateId, message) => { // send email substitutionWrappers: ['{{', '}}'], replyTo, categories, + cc, + bcc, }); } module.exports = { From fd50c9eabac3db7d50892cc6d6b98957b8e57399 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Wed, 25 Apr 2018 17:18:19 +0530 Subject: [PATCH 4/4] clean-up --- docs/swagger_api.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swagger_api.yaml b/docs/swagger_api.yaml index d60fa0e..1a8c8a5 100644 --- a/docs/swagger_api.yaml +++ b/docs/swagger_api.yaml @@ -3,7 +3,7 @@ info: title: "TOPCODER EMAIL SERIES - EMAIL SERVER" description: "TOPCODER EMAIL SERIES - EMAIL SERVER" version: "1.0.0" -host: "localhost:4001" +host: "localhost:6100" basePath : "/v5/email" schemes: - "https"