Skip to content

Commit a970435

Browse files
committed
1. Making sure team service doesn't send internal notifications
2. Sending the cron email notifications to topic notifications.action.create
1 parent 2d8680b commit a970435

File tree

5 files changed

+201
-145
lines changed

5 files changed

+201
-145
lines changed

config/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ module.exports = {
147147

148148
// the Kafka message topic for sending email
149149
EMAIL_TOPIC: process.env.EMAIL_TOPIC || 'external.action.email',
150+
// the Kafka message topic for creating notifications
151+
NOTIFICATIONS_CREATE_TOPIC: process.env.NOTIFICATIONS_CREATE_TOPIC || 'notifications.action.create',
150152
// the emails address for receiving the issue report
151153
// REPORT_ISSUE_EMAILS may contain comma-separated list of email which is converted to array
152154
REPORT_ISSUE_EMAILS: (process.env.REPORT_ISSUE_EMAILS || '').split(','),

config/email_template.config.js

Lines changed: 130 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -12,135 +12,139 @@ module.exports = {
1212
* - projectName: the project name. Example: "TaaS API Misc Updates"
1313
* - reportText: the body of reported issue. Example: "I have issue with ... \n ... Thank you in advance!"
1414
*/
15-
'team-issue-report': {
16-
subject: 'Issue Reported on TaaS Team {{projectName}} ({{projectId}}).',
17-
body: 'Project Name: {{projectName}}' + '\n' +
18-
'Project ID: {{projectId}}' + '\n' +
19-
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
20-
'\n' +
21-
'{{reportText}}',
22-
recipients: config.REPORT_ISSUE_EMAILS,
23-
sendgridTemplateId: config.REPORT_ISSUE_SENDGRID_TEMPLATE_ID
24-
},
15+
teamTemplates: {
16+
'team-issue-report': {
17+
subject: 'Issue Reported on TaaS Team {{projectName}} ({{projectId}}).',
18+
body: 'Project Name: {{projectName}}' + '\n' +
19+
'Project ID: {{projectId}}' + '\n' +
20+
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
21+
'\n' +
22+
'{{reportText}}',
23+
recipients: config.REPORT_ISSUE_EMAILS,
24+
sendgridTemplateId: config.REPORT_ISSUE_SENDGRID_TEMPLATE_ID
25+
},
2526

26-
/* Report issue for a particular member
27-
*
28-
* - userHandle: the user handle. Example: "bili_2021"
29-
* - projectId: the project ID. Example: 123412
30-
* - projectName: the project name. Example: "TaaS API Misc Updates"
31-
* - reportText: the body of reported issue. Example: "I have issue with ... \n ... Thank you in advance!"
32-
*/
33-
'member-issue-report': {
34-
subject: 'Issue Reported for member {{userHandle}} on TaaS Team {{projectName}} ({{projectId}}).',
35-
body: 'User Handle: {{userHandle}}' + '\n' +
36-
'Project Name: {{projectName}}' + '\n' +
37-
'Project ID: {{projectId}}' + '\n' +
38-
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
39-
'\n' +
40-
'{{reportText}}',
41-
recipients: config.REPORT_ISSUE_EMAILS,
42-
sendgridTemplateId: config.REPORT_ISSUE_SENDGRID_TEMPLATE_ID
43-
},
27+
/* Report issue for a particular member
28+
*
29+
* - userHandle: the user handle. Example: "bili_2021"
30+
* - projectId: the project ID. Example: 123412
31+
* - projectName: the project name. Example: "TaaS API Misc Updates"
32+
* - reportText: the body of reported issue. Example: "I have issue with ... \n ... Thank you in advance!"
33+
*/
34+
'member-issue-report': {
35+
subject: 'Issue Reported for member {{userHandle}} on TaaS Team {{projectName}} ({{projectId}}).',
36+
body: 'User Handle: {{userHandle}}' + '\n' +
37+
'Project Name: {{projectName}}' + '\n' +
38+
'Project ID: {{projectId}}' + '\n' +
39+
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
40+
'\n' +
41+
'{{reportText}}',
42+
recipients: config.REPORT_ISSUE_EMAILS,
43+
sendgridTemplateId: config.REPORT_ISSUE_SENDGRID_TEMPLATE_ID
44+
},
4445

45-
/* Request extension for a particular member
46-
*
47-
* - userHandle: the user handle. Example: "bili_2021"
48-
* - projectId: the project ID. Example: 123412
49-
* - projectName: the project name. Example: "TaaS API Misc Updates"
50-
* - text: comment for the request. Example: "I would like to keep working with this member for 2 months..."
51-
*/
52-
'extension-request': {
53-
subject: 'Extension Requested for member {{userHandle}} on TaaS Team {{projectName}} ({{projectId}}).',
54-
body: 'User Handle: {{userHandle}}' + '\n' +
55-
'Project Name: {{projectName}}' + '\n' +
56-
'Project ID: {{projectId}}' + '\n' +
57-
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
58-
'\n' +
59-
'{{text}}',
60-
recipients: config.REPORT_ISSUE_EMAILS,
61-
sendgridTemplateId: config.REQUEST_EXTENSION_SENDGRID_TEMPLATE_ID
62-
},
46+
/* Request extension for a particular member
47+
*
48+
* - userHandle: the user handle. Example: "bili_2021"
49+
* - projectId: the project ID. Example: 123412
50+
* - projectName: the project name. Example: "TaaS API Misc Updates"
51+
* - text: comment for the request. Example: "I would like to keep working with this member for 2 months..."
52+
*/
53+
'extension-request': {
54+
subject: 'Extension Requested for member {{userHandle}} on TaaS Team {{projectName}} ({{projectId}}).',
55+
body: 'User Handle: {{userHandle}}' + '\n' +
56+
'Project Name: {{projectName}}' + '\n' +
57+
'Project ID: {{projectId}}' + '\n' +
58+
`Project URL: ${config.TAAS_APP_URL}/{{projectId}}` + '\n' +
59+
'\n' +
60+
'{{text}}',
61+
recipients: config.REPORT_ISSUE_EMAILS,
62+
sendgridTemplateId: config.REQUEST_EXTENSION_SENDGRID_TEMPLATE_ID
63+
},
6364

64-
/* Request interview for a job candidate
65-
*
66-
* - interviewType: the x.ai interview type. Example: "interview-30"
67-
* - interviewRound: the round of the interview. Example: 2
68-
* - interviewDuration: duration of the interview, in minutes. Example: 30
69-
* - interviewerList: The list of interviewer email addresses. Example: "[email protected], [email protected]"
70-
* - candidateId: the id of the jobCandidate. Example: "cc562545-7b75-48bf-87e7-50b3c57e41b1"
71-
* - candidateName: Full name of candidate. Example: "John Doe"
72-
* - jobName: The title of the job. Example: "TaaS API Misc Updates"
73-
*
74-
* Template (defined in SendGrid):
75-
* Subject: '{{interviewType}} tech interview with {{candidateName}} for {{jobName}} is requested by the Customer'
76-
* Body:
77-
* 'Hello!
78-
* <br /><br />
79-
* Congratulations, you have been selected to participate in a Topcoder Gig Work Interview!
80-
* <br /><br />
81-
* Please monitor your email for a response to this where you can coordinate your availability.
82-
* <br /><br />
83-
* Interviewee: {{candidateName}}<br />
84-
* Interviewer(s): {{interviewerList}}<br />
85-
* Interview Length: {{interviewDuration}} minutes
86-
* <br /><br />
87-
* /{{interviewType}}
88-
* <br /><br />
89-
* Topcoder Info:<br />
90-
* Note: "id: {{candidateId}}, round: {{interviewRound}}"'
91-
*
92-
* Note, that the template should be defined in SendGrid.
93-
* The subject & body above (identical to actual SendGrid template) is for reference purposes.
94-
* We won't pass subject & body but only substitutions (replacements in template subject/body).
95-
*/
96-
'interview-invitation': {
97-
subject: '',
98-
body: '',
99-
from: config.INTERVIEW_INVITATION_SENDER_EMAIL,
100-
cc: config.INTERVIEW_INVITATION_CC_LIST,
101-
recipients: config.INTERVIEW_INVITATION_RECIPIENTS_LIST,
102-
sendgridTemplateId: config.INTERVIEW_INVITATION_SENDGRID_TEMPLATE_ID
103-
},
104-
'candidate-review': {
105-
subject: 'Topcoder - {{teamName}} has job candidates available for review',
106-
body: '',
107-
recipients: [],
108-
from: config.NOTIFICATION_SENDER_EMAIL,
109-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
110-
},
111-
'interview-coming-up-host': {
112-
subject: 'Topcoder - Interview Coming Up: {{jobTitle}} with {{guestFullName}}',
113-
body: '',
114-
recipients: [],
115-
from: config.NOTIFICATION_SENDER_EMAIL,
116-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
117-
},
118-
'interview-coming-up-guest': {
119-
subject: 'Topcoder - Interview Coming Up: {{jobTitle}} with {{hostFullName}}',
120-
body: '',
121-
recipients: [],
122-
from: config.NOTIFICATION_SENDER_EMAIL,
123-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
124-
},
125-
'interview-completed': {
126-
subject: 'Topcoder - Interview Awaits Resolution: {{jobTitle}} for {{guestFullName}}',
127-
body: '',
128-
recipients: [],
129-
from: config.NOTIFICATION_SENDER_EMAIL,
130-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
131-
},
132-
'post-interview-action': {
133-
subject: 'Topcoder - Candidate Action Required in {{teamName}} for {{numCandidates}} candidates',
134-
body: '',
135-
recipients: [],
136-
from: config.NOTIFICATION_SENDER_EMAIL,
137-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
65+
/* Request interview for a job candidate
66+
*
67+
* - interviewType: the x.ai interview type. Example: "interview-30"
68+
* - interviewRound: the round of the interview. Example: 2
69+
* - interviewDuration: duration of the interview, in minutes. Example: 30
70+
* - interviewerList: The list of interviewer email addresses. Example: "[email protected], [email protected]"
71+
* - candidateId: the id of the jobCandidate. Example: "cc562545-7b75-48bf-87e7-50b3c57e41b1"
72+
* - candidateName: Full name of candidate. Example: "John Doe"
73+
* - jobName: The title of the job. Example: "TaaS API Misc Updates"
74+
*
75+
* Template (defined in SendGrid):
76+
* Subject: '{{interviewType}} tech interview with {{candidateName}} for {{jobName}} is requested by the Customer'
77+
* Body:
78+
* 'Hello!
79+
* <br /><br />
80+
* Congratulations, you have been selected to participate in a Topcoder Gig Work Interview!
81+
* <br /><br />
82+
* Please monitor your email for a response to this where you can coordinate your availability.
83+
* <br /><br />
84+
* Interviewee: {{candidateName}}<br />
85+
* Interviewer(s): {{interviewerList}}<br />
86+
* Interview Length: {{interviewDuration}} minutes
87+
* <br /><br />
88+
* /{{interviewType}}
89+
* <br /><br />
90+
* Topcoder Info:<br />
91+
* Note: "id: {{candidateId}}, round: {{interviewRound}}"'
92+
*
93+
* Note, that the template should be defined in SendGrid.
94+
* The subject & body above (identical to actual SendGrid template) is for reference purposes.
95+
* We won't pass subject & body but only substitutions (replacements in template subject/body).
96+
*/
97+
'interview-invitation': {
98+
subject: '',
99+
body: '',
100+
from: config.INTERVIEW_INVITATION_SENDER_EMAIL,
101+
cc: config.INTERVIEW_INVITATION_CC_LIST,
102+
recipients: config.INTERVIEW_INVITATION_RECIPIENTS_LIST,
103+
sendgridTemplateId: config.INTERVIEW_INVITATION_SENDGRID_TEMPLATE_ID
104+
}
138105
},
139-
'resource-booking-expiration': {
140-
subject: 'Topcoder - Resource Booking Expiring in {{teamName}} for {{numResourceBookings}} resource bookings',
141-
body: '',
142-
recipients: [],
143-
from: config.NOTIFICATION_SENDER_EMAIL,
144-
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
106+
'cronEmailTemplates': {
107+
'candidate-review': {
108+
subject: 'Topcoder - {{teamName}} has job candidates available for review',
109+
body: '',
110+
recipients: [],
111+
from: config.NOTIFICATION_SENDER_EMAIL,
112+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
113+
},
114+
'interview-coming-up-host': {
115+
subject: 'Topcoder - Interview Coming Up: {{jobTitle}} with {{guestFullName}}',
116+
body: '',
117+
recipients: [],
118+
from: config.NOTIFICATION_SENDER_EMAIL,
119+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
120+
},
121+
'interview-coming-up-guest': {
122+
subject: 'Topcoder - Interview Coming Up: {{jobTitle}} with {{hostFullName}}',
123+
body: '',
124+
recipients: [],
125+
from: config.NOTIFICATION_SENDER_EMAIL,
126+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
127+
},
128+
'interview-completed': {
129+
subject: 'Topcoder - Interview Awaits Resolution: {{jobTitle}} for {{guestFullName}}',
130+
body: '',
131+
recipients: [],
132+
from: config.NOTIFICATION_SENDER_EMAIL,
133+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
134+
},
135+
'post-interview-action': {
136+
subject: 'Topcoder - Candidate Action Required in {{teamName}} for {{numCandidates}} candidates',
137+
body: '',
138+
recipients: [],
139+
from: config.NOTIFICATION_SENDER_EMAIL,
140+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
141+
},
142+
'resource-booking-expiration': {
143+
subject: 'Topcoder - Resource Booking Expiring in {{teamName}} for {{numResourceBookings}} resource bookings',
144+
body: '',
145+
recipients: [],
146+
from: config.NOTIFICATION_SENDER_EMAIL,
147+
sendgrid_template_id: config.NOTIFICATION_SENDGRID_TEMPLATE_ID
148+
}
145149
}
146150
}

src/common/helper.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const eventDispatcher = require('./eventDispatcher')
2222
const busApi = require('@topcoder-platform/topcoder-bus-api-wrapper')
2323
const moment = require('moment')
2424
const { PaymentStatusRules } = require('../../app-constants')
25+
const emailTemplateConfig = require('../../config/email_template.config')
2526

2627
const localLogger = {
2728
debug: (message) =>
@@ -2011,6 +2012,26 @@ async function getMembersSuggest (fragment) {
20112012
return res.body
20122013
}
20132014

2015+
/**
2016+
* Returns the email templates for given key
2017+
* @param key the type of email template ex: teamTemplates
2018+
* @returns the list of templates for the given key
2019+
*/
2020+
function getEmailTemplatesForKey (key) {
2021+
if (!_.has(emailTemplateConfig, key)) { return [] }
2022+
2023+
return _.mapValues(emailTemplateConfig[key], (template) => {
2024+
return {
2025+
subject: template.subject,
2026+
body: template.body,
2027+
from: template.from,
2028+
recipients: template.recipients,
2029+
cc: template.cc,
2030+
sendgridTemplateId: template.sendgridTemplateId
2031+
}
2032+
})
2033+
}
2034+
20142035
module.exports = {
20152036
getParamFromCliArgs,
20162037
promptUser,
@@ -2072,5 +2093,6 @@ module.exports = {
20722093
createProject,
20732094
getMemberGroups,
20742095
removeTextFormatting,
2075-
getMembersSuggest
2096+
getMembersSuggest,
2097+
getEmailTemplatesForKey
20762098
}

0 commit comments

Comments
 (0)