-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Background
At the moment to send email or web notification we require to userId and/or email address as per the Kafka Message payload format https://gist.github.com/maxceem/bb2ad68d2f8a790f01e3326f9f8015eb#file-notification-action-create-js-L9-L48
Though sometimes service which sends notification doesn't know userId/email and have just a handle for example. We don't want to ask each service to implement functionality to retrieve userId/email. Instead of this, we would allow passing only of the user identifier like userId, userUUID, email or handle and tc-notificatoin would have to get any details about the user necessary for sending notifications by itself.
Task
-
For
emailtherecipientsarray should allow passing the next object:{ // only ONE of these fields is required (any of them can be passed) userId: 1212748193, userUUID: "12341234-1234-sdfsa-123fa-sadf", email: "[email protected]", handle: "maxceem" }
- to send email tc-notification needs to know
emailso we have to getemailif it's not passed byuserIdoruserUUIDorhandle. If we could not getemail- log error as we cannot send notification in such a case. - we also should get
userIdwhich is needed to check user settings. So we have to usehandle,emailoruserUUIDto getuserId. If user is not found, then still send notification to theemail, this would be needed in case if user is not registered yet. But if there is some other error while gettinguserId(not NOT FOUND), then don't send email and log error as we failed to getuserId. - The same logic should be supported for
ccof the email. Thoug as we don't need to check setting for the user, thenuserIdforccis not need to retrieve.
- to send email tc-notification needs to know
-
For
webnotification:- replace
userIdfield withrecipientswich would also be an array. And we would should send thiswebnotification toeachmember in therecipientsarray.recipientsarray should allow the same objects as for email:{ // only ONE of these fields is required (any of them can be passed) userId: 1212748193, userUUID: "12341234-1234-sdfsa-123fa-sadf", email: "[email protected]", handle: "maxceem" }
- to send
webnotification we needuserId, so we have to get it byuserUUIDoremailofhandledepend on what is provided. - if we could not get
userIdfor any reason - log error as we cannot create web notification withoutuserId.
- replace
API Endpoints
We have 2 kind of user ids in Topcoder which are provided by different services, though we keeping user in sync between them.
userIdis a numeric user id like13123123userUUIDis string UUID user id like1323423421-asdfas-123asdf-123
For example, TC-Notifications services use only userId, while TaaS API always uses userUUID.
Get userId
- Get
userIdbyuserUUID- https://github.com/topcoder-platform/taas-apis/blob/feature/notifications-scheduler/src/common/helper.js#L1065-L1095 (enrichcan befalse) - Get
userIdbyemail- https://github.com/topcoder-platform/tc-project-service/blob/feature/new-milestone-concept/src/util.js#L909-L947 - Get
userIdbyhandle- https://github.com/topcoder-platform/tc-project-service/blob/feature/new-milestone-concept/src/util.js#L584-L608
Get email
- Get
emailbyuserUUID- https://github.com/topcoder-platform/taas-apis/blob/feature/notifications-scheduler/src/common/helper.js#L1065-L1095 (enrichmust betrueto return emails ) - Get
emailbyuserId- https://github.com/topcoder-platform/tc-project-service/blob/feature/new-milestone-concept/src/util.js#L559-L579 - Get
emailbyhandle- https://github.com/topcoder-platform/tc-project-service/blob/feature/new-milestone-concept/src/util.js#L584-L608
API Notes
- For most cases, we have endpoints that can get several users at once. So we can organize code in such a way that we would call such endpoints only once for all users in
recipientsarray. (theoretically, we call it only once per Kafka message for all items in the payload, but it might be too many users at once, so calling it per notification object inside the payload array should be fine). - When getting something by
userUUIDwe would need to create a separate M2M token specially for u-bahn like in TaaS API https://github.com/topcoder-platform/taas-apis/blob/feature/notifications-scheduler/src/common/helper.js#L889-L894