Skip to content

Commit c4c9a1e

Browse files
author
sachin-maheshwari
authored
Merge pull request #34 from topcoder-platform/dev
Decoupling sendgrid template id from Kafka topic
2 parents 204ad67 + ebf7950 commit c4c9a1e

File tree

5 files changed

+278
-174
lines changed

5 files changed

+278
-174
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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const _ = require('lodash');
99
const config = require('config');
1010
const emailServer = require('../index');
1111
const service = require('./service');
12+
const logger = require('../src/common/logger');
1213

1314
// set configuration for the server, see ../config/default.js for available config parameters
1415
// setConfig should be called before initDatabase and start functions
@@ -21,16 +22,19 @@ emailServer.setConfig({ LOG_LEVEL: 'debug' });
2122
// the message is JSON event message,
2223
// the callback is function(error, templateId), where templateId is the used SendGrid template id
2324
const handler = (topic, message, callback) => {
24-
const templateId = config.TEMPLATE_MAP[topic];
25-
if (templateId === undefined) {
25+
let templateId = config.TEMPLATE_MAP[topic];
26+
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId);
27+
if (!templateId) {
2628
return callback(null, { success: false, error: `Template not found for topic ${topic}` });
2729
}
2830

29-
service.sendEmail(templateId, message).then(() => {
30-
callback(null, { success: true });
31-
}).catch((err) => {
32-
callback(null, { success: false, error: err });
33-
});
31+
service.sendEmail(templateId, message).then(() => {
32+
callback(null, { success: true });
33+
}).catch((err) => {
34+
logger.error("Error occurred in sendgrid api calling:", err);
35+
callback(null, { success: false, error: err });
36+
});
37+
3438
};
3539

3640
// init all events

0 commit comments

Comments
 (0)