Skip to content

Commit a3315a5

Browse files
author
sachin-maheshwari
authored
Merge pull request #29 from topcoder-platform/feature/decouple-sendgridtemplateid
Allowing sendgrid template id in payload
2 parents 2b03031 + c488da7 commit a3315a5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ workflows:
8282
context : org-global
8383
filters:
8484
branches:
85-
only: ['dev']
85+
only: ['dev', 'feature/decouple-sendgridtemplateid']
8686
- "build-prod":
8787
context : org-global
8888
filters:

config/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ module.exports = {
4646

4747
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',
4848

49+
PAYLOAD_SENDGRID_TEMPLATE_KEY: process.env.PAYLOAD_SENDGRID_TEMPLATE_KEY || 'sendgrid_template_id',
50+
4951
};

connect/connectEmailServer.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ emailServer.setConfig({ LOG_LEVEL: 'debug' });
2222
// the message is JSON event message,
2323
// the callback is function(error, templateId), where templateId is the used SendGrid template id
2424
const handler = (topic, message, callback) => {
25-
const templateId = config.TEMPLATE_MAP[topic];
26-
if (templateId === undefined) {
25+
let templateId = config.TEMPLATE_MAP[topic];
26+
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId);
27+
if (!templateId) {
2728
return callback(null, { success: false, error: `Template not found for topic ${topic}` });
2829
}
2930

30-
try {
3131
service.sendEmail(templateId, message).then(() => {
3232
callback(null, { success: true });
3333
}).catch((err) => {
34+
logger.error("Error occurred in sendgrid api calling:", err);
3435
callback(null, { success: false, error: err });
3536
});
36-
} catch (error) {
37-
logger.error('Unknown Error: ', error);
38-
}
3937

4038
};
4139

0 commit comments

Comments
 (0)