Skip to content
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ Notifications plugin configures `srv/notification-types.json` as default notific

To make notification types unique to the application, prefix is added to the type key. By default, `application name` is added as the prefix. You can update the `cds.env.requires.notifications.prefix` if required.

### Authentication Identifier

Depending on your Work Zone Notifications configuration, set `cds.env.requires.notifications.authenticationIdentifier` to `UserUUID` if the authenciation identifier in Work Zone is set to `User ID`. Notifications are then published with Recipient Key `GlobalUserId` instead of `RecipientId`. If not set, `RecipientId` is used. Note, that in order for E-Mail Notifications to be sent for notifications published with a User ID, a destination to the IDS needs to be configured for the lookup of the corresponding email address.

For the Work Zone Authentication Identifier configuration details refer to: [Work Zone Subaccount Settings](https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/subaccount-settings)

### Low-level Notifications API

You can use these two signature to send the custom notification with pre-defined notification types.
Expand Down
13 changes: 11 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ async function getNotificationDestination() {
return notificationDestination;
}

function getRecipientKey() {
const authenticationIdentifier = cds.env.requires.notifications?.authenticationIdentifier;
var recipientKey = 'RecipientId'; // Email
if (authenticationIdentifier === "UserUUID") {
recipientKey = 'GlobalUserId';
}
return recipientKey;
}

let prefix // be filled in below...
function getPrefix() {
if (!prefix) {
Expand Down Expand Up @@ -160,7 +169,7 @@ function buildDefaultNotification(
NotificationTypeVersion: "1",
Priority: priority,
Properties: properties,
Recipients: recipients.map((recipient) => ({ RecipientId: recipient }))
Recipients: recipients.map((recipient) => ({ [getRecipientKey()]: recipient }))
};
}

Expand All @@ -169,7 +178,7 @@ function buildCustomNotification(_) {

// Properties with simple API variants
NotificationTypeKey: getNotificationTypesKeyWithPrefix(_.NotificationTypeKey || _.type),
Recipients: _.Recipients || _.recipients?.map(id => ({ RecipientId: id })),
Recipients: _.Recipients || _.recipients?.map(id => ({ [getRecipientKey()]: id })),
Priority: _.Priority || _.priority || "NEUTRAL",
Properties: _.Properties || Object.entries(_.data).map(([k,v]) => ({
Key:k, Value:v, Language: "en", Type: typeof v, // IsSensitive: false
Expand Down