Skip to content

[DEV] Universal notifications #213

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 2 commits into from
Aug 4, 2021
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ The following parameters can be set in config files or in env variables:
- `REPLY_EMAIL_PREFIX`: prefix of the genereated reply email address
- `REPLY_EMAIL_DOMAIN`: email domain
- `DEFAULT_REPLY_EMAIL`: default reply to email address, for example [email protected]
- **Slack api**
- `SLACK_URL`: slack api url to post messages
- `SLACK_BOT_TOKEN`: slack bot user OAuth token
- `SLACK_NOTIFY`: slack notification switch, set to 'true' to enable slack notifications.

Note that the above two configuration are separate because the common notification server config
will be deployed to a NPM package, the connect notification server will use that NPM package,
Expand Down
22 changes: 15 additions & 7 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ module.exports = {
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,

// Slack configuration.
SLACK: {
URL: process.env.SLACK_URL || 'https://slack.com/api/chat.postMessage',
BOT_TOKEN: process.env.SLACK_BOT_TOKEN,
NOTIFY: process.env.SLACK_NOTIFY === 'true',
},
KAFKA_CONSUMER_RULESETS: {
// key is Kafka topic name, value is array of ruleset which have key as
// handler function name defined in src/processors/index.js
Expand Down Expand Up @@ -115,13 +120,16 @@ module.exports = {
// },
// },
// ],
// */ // issue - https://github.com/topcoder-platform/community-app/issues/4108
// */ // issue - https://github.com/topcoder-platform/community-app/issues/4108
'admin.notification.broadcast': [{
handleBulkNotification: {}
}
]
//'notifications.community.challenge.created': ['handleChallengeCreated'],
//'notifications.community.challenge.phasewarning': ['handleChallengePhaseWarning'],
handleBulkNotification: {},
},
],
'notification.action.create': [{
handleUniversalNotification: {},
}],
// 'notifications.community.challenge.created': ['handleChallengeCreated'],
// 'notifications.community.challenge.phasewarning': ['handleChallengePhaseWarning'],
},

// email notification service related variables
Expand Down
2 changes: 1 addition & 1 deletion connect/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ module.exports = {
DEFAULT_REPLY_EMAIL: process.env.DEFAULT_REPLY_EMAIL,

CONNECT_URL: process.env.CONNECT_URL || 'https://connect.topcoder-dev.com',
ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || "https://accounts-auth0.topcoder-dev.com",
ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || 'https://accounts-auth0.topcoder-dev.com',
TC_CDN_URL: process.env.TC_CDN_URL,
};
7 changes: 3 additions & 4 deletions connect/connectNotificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
_.forEach(notifications, (notification) => {
const mentionedUser = _.find(users, { handle: notification.userHandle });
notification.userId = mentionedUser ? mentionedUser.userId.toString() : null;
if (!notification.userId && logger) {// such notifications would be discarded later after aggregation
if (!notification.userId && logger) { // such notifications would be discarded later after aggregation
logger.info(`Unable to find user with handle ${notification.userHandle}`);
}
});
Expand All @@ -102,12 +102,11 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
logger.error(error);
logger.info('Unable to send notification to mentioned user');
}
//resolves with empty notification which essentially means we are unable to send notification to mentioned user
// resolves with empty notification which essentially means we are unable to send notification to mentioned user
return Promise.resolve([]);
});
} else {
return Promise.resolve([]);
}
return Promise.resolve([]);
};

/**
Expand Down
3 changes: 3 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ module.exports = {
SEARCH_USERS_PAGE_SIZE: 5,

SETTINGS_EMAIL_SERVICE_ID: 'email',
SETTINGS_WEB_SERVICE_ID: 'web',
SETTINGS_SLACK_SERVICE_ID: 'slack',
ACTIVE_USER_STATUSES: ['ACTIVE'],

BUS_API_EVENT: {
EMAIL: {
GENERAL: 'connect.notification.email.project.notifications.generic',
UNIVERSAL: 'external.action.email',
},
},
};
38 changes: 38 additions & 0 deletions docs/tc-notifications.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"info": {
"_postman_id": "ad14efc8-1fed-4914-8273-330754500801",
"name": "TC-NOTIFICATIONS",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "list notifications",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "{{URL}}/list?limit=100",
"host": [
"{{URL}}"
],
"path": [
"list"
],
"query": [
{
"key": "limit",
"value": "100"
}
]
}
},
"response": []
}
]
}
19 changes: 19 additions & 0 deletions docs/tc-notifications.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "9d9c9e1b-6004-4bbe-9a98-55ad3a5838d7",
"name": "tc-notifications",
"values": [
{
"key": "URL",
"value": "http://localhost:3000/v5/notifications",
"enabled": true
},
{
"key": "TOKEN",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjIxNDc0ODM2NDgsInVzZXJJZCI6IjQwMTUyODU2IiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.PKv0QrMCPf0-ZPjv4PGWT7eXne54m7i9YX9eq-fceMU",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2021-07-24T21:01:35.787Z",
"_postman_exported_using": "Postman/8.8.0"
}
Loading