Skip to content

Commit eb5dbe4

Browse files
author
Vikas Agarwal
committed
Clean handling of cdderbot initiated messages, they would be ignored without runtime error
1 parent 075e3b6 commit eb5dbe4

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

connect/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
ADMINISTRATOR_ROLE_ID: 1,
1818
// id of the BOT user which creates post with various events in discussions
1919
TCWEBSERVICE_ID: process.env.TCWEBSERVICE_ID || '22838965',
20+
CODERBOT_USER_ID: process.env.CODERBOT_USER_ID || 'CoderBot',
2021

2122
// Configuration for generating machine to machine auth0 token.
2223
// The token will be used for calling another internal API.

connect/connectNotificationServer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ notificationServer.setConfig({ LOG_LEVEL: 'debug' });
272272
// it is defined as: function(topic, message, callback),
273273
// the topic is topic name,
274274
// the message is JSON event message,
275+
// logger object used to log in parent thread
275276
// the callback is function(error, userIds), where userIds is an array of user ids to receive notifications
276-
const handler = (topic, message, callback) => {
277+
const handler = (topic, message, logger, callback) => {
277278
const projectId = message.projectId;
278279
if (!projectId) {
279280
return callback(new Error('Missing projectId in the event message.'));
@@ -286,7 +287,9 @@ const handler = (topic, message, callback) => {
286287

287288
// filter out `notifications.connect.project.topic.created` events send by bot
288289
// because they create too much clutter and duplicate info
289-
if (topic === BUS_API_EVENT.CONNECT.TOPIC.CREATED && message.userId.toString() === config.TCWEBSERVICE_ID) {
290+
const botIds = [config.TCWEBSERVICE_ID, config.CODERBOT_USER_ID];
291+
if (topic === BUS_API_EVENT.CONNECT.TOPIC.CREATED && botIds.contains(message.userId.toString())) {
292+
logger.info(`Ignoring, to avoid noise, Bot topic ${topic}`);
290293
return callback(null, []);
291294
}
292295

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function startKafkaConsumer(handlers, notificationServiceHandlers) {
4848
const messageJSON = busPayload.payload;
4949
const handlerAsync = Promise.promisify(handler);
5050
// use handler to create notification instances for each recipient
51-
return handlerAsync(topicName, messageJSON)
51+
return handlerAsync(topicName, messageJSON, logger)
5252
.then((notifications) => Promise.all(_.map(notifications, (notification) => {
5353
notification.contents = _.extend({}, messageJSON, notification.contents);
5454
// run other notification service handlers

0 commit comments

Comments
 (0)