Skip to content

Decoupling sendgrid template id from Kafka topic #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ workflows:
context : org-global
filters:
branches:
only: ['dev']
only: ['dev', 'feature/decouple-sendgridtemplateid']
- "build-prod":
context : org-global
filters:
Expand Down
2 changes: 2 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ module.exports = {

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

PAYLOAD_SENDGRID_TEMPLATE_KEY: process.env.PAYLOAD_SENDGRID_TEMPLATE_KEY || 'sendgrid_template_id',

};
18 changes: 11 additions & 7 deletions connect/connectEmailServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const _ = require('lodash');
const config = require('config');
const emailServer = require('../index');
const service = require('./service');
const logger = require('../src/common/logger');

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

service.sendEmail(templateId, message).then(() => {
callback(null, { success: true });
}).catch((err) => {
callback(null, { success: false, error: err });
});
service.sendEmail(templateId, message).then(() => {
callback(null, { success: true });
}).catch((err) => {
logger.error("Error occurred in sendgrid api calling:", err);
callback(null, { success: false, error: err });
});

};

// init all events
Expand Down
Loading