Skip to content

Commit 9fee095

Browse files
authored
Merge pull request #213 from topcoder-platform/feature/universal-notifications
[DEV] Universal notifications
2 parents 4be3a30 + 0b3e602 commit 9fee095

20 files changed

+740
-266
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ The following parameters can be set in config files or in env variables:
103103
- `REPLY_EMAIL_PREFIX`: prefix of the genereated reply email address
104104
- `REPLY_EMAIL_DOMAIN`: email domain
105105
- `DEFAULT_REPLY_EMAIL`: default reply to email address, for example [email protected]
106+
- **Slack api**
107+
- `SLACK_URL`: slack api url to post messages
108+
- `SLACK_BOT_TOKEN`: slack bot user OAuth token
109+
- `SLACK_NOTIFY`: slack notification switch, set to 'true' to enable slack notifications.
106110

107111
Note that the above two configuration are separate because the common notification server config
108112
will be deployed to a NPM package, the connect notification server will use that NPM package,

config/default.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ module.exports = {
4747
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
4848
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
4949
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
50-
50+
// Slack configuration.
51+
SLACK: {
52+
URL: process.env.SLACK_URL || 'https://slack.com/api/chat.postMessage',
53+
BOT_TOKEN: process.env.SLACK_BOT_TOKEN,
54+
NOTIFY: process.env.SLACK_NOTIFY === 'true',
55+
},
5156
KAFKA_CONSUMER_RULESETS: {
5257
// key is Kafka topic name, value is array of ruleset which have key as
5358
// handler function name defined in src/processors/index.js
@@ -115,13 +120,16 @@ module.exports = {
115120
// },
116121
// },
117122
// ],
118-
// */ // issue - https://github.com/topcoder-platform/community-app/issues/4108
123+
// */ // issue - https://github.com/topcoder-platform/community-app/issues/4108
119124
'admin.notification.broadcast': [{
120-
handleBulkNotification: {}
121-
}
122-
]
123-
//'notifications.community.challenge.created': ['handleChallengeCreated'],
124-
//'notifications.community.challenge.phasewarning': ['handleChallengePhaseWarning'],
125+
handleBulkNotification: {},
126+
},
127+
],
128+
'notification.action.create': [{
129+
handleUniversalNotification: {},
130+
}],
131+
// 'notifications.community.challenge.created': ['handleChallengeCreated'],
132+
// 'notifications.community.challenge.phasewarning': ['handleChallengePhaseWarning'],
125133
},
126134

127135
// email notification service related variables

connect/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ module.exports = {
3636
DEFAULT_REPLY_EMAIL: process.env.DEFAULT_REPLY_EMAIL,
3737

3838
CONNECT_URL: process.env.CONNECT_URL || 'https://connect.topcoder-dev.com',
39-
ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || "https://accounts-auth0.topcoder-dev.com",
39+
ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || 'https://accounts-auth0.topcoder-dev.com',
4040
TC_CDN_URL: process.env.TC_CDN_URL,
4141
};

connect/connectNotificationServer.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
9292
_.forEach(notifications, (notification) => {
9393
const mentionedUser = _.find(users, { handle: notification.userHandle });
9494
notification.userId = mentionedUser ? mentionedUser.userId.toString() : null;
95-
if (!notification.userId && logger) {// such notifications would be discarded later after aggregation
95+
if (!notification.userId && logger) { // such notifications would be discarded later after aggregation
9696
logger.info(`Unable to find user with handle ${notification.userHandle}`);
9797
}
9898
});
@@ -102,12 +102,11 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
102102
logger.error(error);
103103
logger.info('Unable to send notification to mentioned user');
104104
}
105-
//resolves with empty notification which essentially means we are unable to send notification to mentioned user
105+
// resolves with empty notification which essentially means we are unable to send notification to mentioned user
106106
return Promise.resolve([]);
107107
});
108-
} else {
109-
return Promise.resolve([]);
110108
}
109+
return Promise.resolve([]);
111110
};
112111

113112
/**

constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ module.exports = {
33
SEARCH_USERS_PAGE_SIZE: 5,
44

55
SETTINGS_EMAIL_SERVICE_ID: 'email',
6+
SETTINGS_WEB_SERVICE_ID: 'web',
7+
SETTINGS_SLACK_SERVICE_ID: 'slack',
68
ACTIVE_USER_STATUSES: ['ACTIVE'],
79

810
BUS_API_EVENT: {
911
EMAIL: {
1012
GENERAL: 'connect.notification.email.project.notifications.generic',
13+
UNIVERSAL: 'external.action.email',
1114
},
1215
},
1316
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info": {
3+
"_postman_id": "ad14efc8-1fed-4914-8273-330754500801",
4+
"name": "TC-NOTIFICATIONS",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "list notifications",
10+
"request": {
11+
"method": "GET",
12+
"header": [
13+
{
14+
"key": "Authorization",
15+
"value": "Bearer {{TOKEN}}",
16+
"type": "text"
17+
}
18+
],
19+
"url": {
20+
"raw": "{{URL}}/list?limit=100",
21+
"host": [
22+
"{{URL}}"
23+
],
24+
"path": [
25+
"list"
26+
],
27+
"query": [
28+
{
29+
"key": "limit",
30+
"value": "100"
31+
}
32+
]
33+
}
34+
},
35+
"response": []
36+
}
37+
]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"id": "9d9c9e1b-6004-4bbe-9a98-55ad3a5838d7",
3+
"name": "tc-notifications",
4+
"values": [
5+
{
6+
"key": "URL",
7+
"value": "http://localhost:3000/v5/notifications",
8+
"enabled": true
9+
},
10+
{
11+
"key": "TOKEN",
12+
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjIxNDc0ODM2NDgsInVzZXJJZCI6IjQwMTUyODU2IiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.PKv0QrMCPf0-ZPjv4PGWT7eXne54m7i9YX9eq-fceMU",
13+
"enabled": true
14+
}
15+
],
16+
"_postman_variable_scope": "environment",
17+
"_postman_exported_at": "2021-07-24T21:01:35.787Z",
18+
"_postman_exported_using": "Postman/8.8.0"
19+
}

0 commit comments

Comments
 (0)