This repository hosts the API and processors for enabling notifications in various topcoder apps. Currently it is limited to provide this facility to the Connect application. Theoretcially, it is a generic framework and application which could be used for sending and consuming notificaitons by any other topcoder app. In very simple words to send notifications using this application:
tc-notifications (as a standard nodejs app) provides generic framework around notifications, it does not have config (used in step 3 of previous list) for specific apps. So, to have config for specific apps, we have to start the notification consumers per app e.g. for connect, we have a folder connect
which hosts start script to start notification consumers with connect specific configuration (events-config.js
). It also adds email notification service which sends emails for notifications as per notification settings (coming from common framework laid by tc-notifications) for the user.
events-config.js
(name is not important, we have to read this file in the start up script written in step 1) for app specific notificationsnpm i natives@1.1.6
to support the gulp build)Configuration for the notification server is at config/default.js
.
The following parameters can be set in config files or in env variables:
LOG_LEVEL
: the log levelPORT
: the notification server portDATABASE_URL
: URI to PostgreSQL databaseDATABASE_OPTIONS
: database connection optionsAUTH_SECRET
: TC auth secretVALID_ISSUERS
: TC auth valid issuersJWKS_URI
: TC auth JWKS URI (need only for local deployment)KAFKA_URL
: comma separated Kafka hostsKAFKA_GROUP_ID
: Kafka consumer group idKAFKA_CLIENT_CERT
: Kafka connection certificate, optional;
if not provided, then SSL connection is not used, direct insecure connection is used;
if provided, it can be either path to certificate file or certificate contentKAFKA_CLIENT_CERT_KEY
: Kafka connection private key, optional;
if not provided, then SSL connection is not used, direct insecure connection is used;
if provided, it can be either path to private key file or private key contentTC_API_V3_BASE_URL
: the TopCoder API V3 base URLTC_API_V4_BASE_URL
: the TopCoder API V4 base URLTC_API_V5_BASE_URL
: the TopCoder API V5 base URLAPI_CONTEXT_PATH
: path to serve API onAUTH0_URL
: auth0 URLAUTH0_AUDIENCE
: auth0 audienceTOKEN_CACHE_TIME
: time period of the cached tokenAUTH0_CLIENT_ID
: auth0 client idAUTH0_CLIENT_SECRET
: auth0 client secretAUTH0_PROXY_SERVER_URL
: auth0 proxy server URLKAFKA_CONSUMER_HANDLERS
: mapping from consumer topic to handlersENV
: used to construct email categoryENABLE_EMAILS
: whether to enable email notificationsENABLE_DEV_MODE
: whether to enable dev modeDEV_MODE_EMAIL
: recipient email used in dev modeDEFAULT_REPLY_EMAIL
: default reply emailConfiguration for the connect notification server is at connect/config.js
.
The following parameters can be set in config files or in env variables:
TC_API_V3_BASE_URL
: the TopCoder API V3 base URLTC_API_V4_BASE_URL
: the TopCoder API V4 base URLMESSAGE_API_BASE_URL
: the TopCoder message service API base URLCONNECT_MANAGER_ROLE_ID
: 8,CONNECT_COPILOT_ROLE_ID
: 4,ADMINISTRATOR_ROLE_ID
: 1/roles
endpoint. As soon as this endpoint is replaced with more suitable one, these variables has to be removed if no need anymore.TCWEBSERVICE_ID
- id of the BOT user which creates post with various events in discussionsAUTH0_URL
: auth0 URLAUTH0_AUDIENCE
: auth0 audienceTOKEN_CACHE_TIME
: time period of the cached tokenAUTH0_CLIENT_ID
: auth0 client idAUTH0_CLIENT_SECRET
: auth0 client secretENV
: environment variable (used to generate reply emails)AUTH_SECRET
: auth secret (used to sign reply emails)ENABLE_EMAILS
: if email service has to be enabledENABLE_DEV_MODE
: send all emails to the DEV_MODE_EMAIL
email addressDEV_MODE_EMAIL
: address to send all email when ENABLE_DEV_MODE
is enabledMENTION_EMAIL
: recipient email used for notifications.action.email.connect.project.post.mention
eventREPLY_EMAIL_PREFIX
: prefix of the genereated reply email addressREPLY_EMAIL_DOMAIN
: email domainDEFAULT_REPLY_EMAIL
: default reply to email address, for example no-reply@topcoder.comSLACK_URL
: slack api url to post messagesSLACK_BOT_TOKEN
: slack bot user OAuth tokenSLACK_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, the connection notification server should only use API exposed by the index.js.
JWT token can be generated using the script test/token.js, its usage: node test/token {user-id}
.
Then use the generated token to manage the user's notifications.
In the Postman bus API, the Post Connect event
will create a Kafka event of project id 1936;
In the Postman notification server API, the TC API - get project
will get details of project id 1936,
we can see the project has one member of user id 305384;
so we can run node test/token 305384
to generate a token to manage notifications of the user of id 305384.
The generated token is already configured in the Postman notification server API environment TOKEN variable. You may reuse it during review.
AUTH_SECRET
,VALID_ISSUERS
can get from tc-project-service configPORT=4000
because connect-app call this port by defaultTC_API_V4_BASE_URL=https://api.topcoder-dev.com/v4
TC_API_V3_BASE_URL=https://api.topcoder-dev.com/v3
KAFKA_URL
, KAFKA_CLIENT_CERT
and KAFKA_CLIENT_CERT_KEY
get from tc-bus-api readmetc-core-library-js
module, which skips verification of user token. Because we don't know Topcoder AUTH_SECRET
locally. So you can install this fork:
npm i https://github.com/maxceem/tc-core-library-js/tree/skip-validation
WARNING do not push package.json with this dependency as it skips users token validation.
npm i
npm run lint
npm run reset:db
npm start
http://localhost:4000
, it also starts Kafka consumer to listen for events and save unroll-ed notifications to dbheroku config:set KAFKA_CLIENT_CERT=path/to/certificate/file
heroku config:set KAFKA_CLIENT_CERT_KEY=path/to/private/key/file
heroku config:set KAFKA_GROUP_ID=some-group
etc.POST /events
/ Post event - XXX
tests,
you may run it multiple times to create multiple events in Kafka,
then you may watch the console output in the app, it should show info about handling the eventsSwagger API definition is provided at docs/swagger_api.yaml
,
you may check it at http://editor.swagger.io
.