You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Notification Type Prefix](#notification-type-prefix)
26
16
-[Contributing](#contributing)
27
17
-[Code of Conduct](#code-of-conduct)
28
18
-[Licensing](#licensing)
29
19
20
+
21
+
30
22
## Setup
31
23
32
24
To enable notifications, simply add this self-configuring plugin package to your project:
@@ -35,25 +27,34 @@ To enable notifications, simply add this self-configuring plugin package to your
35
27
npm add @cap-js/notifications
36
28
```
37
29
38
-
## Usage
39
-
40
30
In this guide, we use the [Incidents Management reference sample app](https://github.com/cap-js/incidents-app) as the base, to publish notifications.
41
31
42
-
### Update Notification Configuration
43
32
44
-
`cds add notifications` will add default configurations for notifications in the `package.json` file.
45
33
34
+
## Send Notifications
46
35
36
+
With that you can use the NotificationService as any other CAP Service like so in you event handlers:
47
37
48
-
#### Notification Types Path
38
+
```js
39
+
constalert=awaitcds.connect.to('notifications');
40
+
```
49
41
50
-
When you run `cds add notifications`, it will add `notificationstype.json` file with template for a notification type in the project root folder. You can add the notification types in the `notificationtype.json` file for sending the custom notification types.
42
+
You can use the following signature to send the simple notification with title and description
51
43
52
-
#### Notification Type Prefix
44
+
```js
45
+
alert.notify({
46
+
recipients: [ ...supporters() ],
47
+
priority:"HIGH",
48
+
title:"New high priority incident is assigned to you!",
49
+
description:"Incident titled 'Engine overheating' created by 'customer X' with priority high is assigned to you!"
50
+
});
51
+
```
53
52
54
-
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 `prefix` if required.
55
53
56
-
### Add Notification Types
54
+
55
+
## Use Notification Types
56
+
57
+
### 1. Add notification types
57
58
58
59
If you want to send custom notifications in your application, you can add the notification types in the `notificationtype.json` file.
59
60
@@ -62,56 +63,89 @@ Sample: If you want to send the notification when the new incident is reported,
title:"New high priority incident is assigned to you!",
105
-
description:"Incident titled 'Engine overheating' created by 'customer X' with priority high is assigned to you!"
106
-
});
87
+
awaitalert.notify ('IncidentResolved', {
88
+
recipients: [ customer.id ],
89
+
data: {
90
+
customer:customer.info,
91
+
title:incident.title,
92
+
user:cds.context.user.id,
93
+
}
94
+
})
107
95
```
108
96
109
-
#### Custom Notifications
97
+
98
+
99
+
## API Reference
100
+
101
+
102
+
103
+
***recipients** - List of the recipients, this argument is mandatory
104
+
***type** - Notification type key, this argument is mandatory
105
+
***priority** - Priority of the notification, this argument is optional, it defaults to NEUTRAL
106
+
***data** - A key-value pair that is used to fill a placeholder of the notification type template, this argument is optional
107
+
108
+
109
+
110
+
## Test-drive Locally
111
+
In local environment, when you publish notification, it is mocked to publish the nofication to the console.
112
+
113
+
<imgwidth="1300"alt="Notify to console"style="border-radius:0.5rem;padding:1rem;background:rgb(242424)"src="_assets/notifyToConsole.png">
114
+
115
+
## Run in Production
116
+
117
+
#### Notification Destination
118
+
119
+
As a pre-requisite to publish the notification, you need to have a [destination](https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/enabling-notifications-for-custom-apps-on-sap-btp-cloud-foundry#configure-the-destination-to-the-notifications-service) configured to publish the notification. In the `package.json` by default destination name `SAP_Notification` is added, you can modify the destination name that you are configuring.
120
+
121
+
#### Integrate with SAP Build Work Zone
122
+
123
+
Once application is deployed and [integrated with SAP Build Work Zone](https://github.com/cap-js/calesi/tree/main/samples/notifications), you can see the notification under fiori notifications icon!
When you run `cds add notifications`, it will add `notificationstype.json` file with template for a notification type in the project root folder. You can add the notification types in the `notificationtype.json` file for sending the custom notification types.
136
+
137
+
#### Custom Notification Type Prefix
138
+
139
+
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 `prefix` if required.
140
+
141
+
#### Low-level Notifications API
142
+
110
143
You can use these two signature to send the custom notification with pre-defined notification types.
111
144
112
145
##### With standard parameters
113
146
114
147
By using this approach you can post a notification by providing different parts of the notification object grouped in related units
***recipients** - List of the recipients, this argument is mandatory
162
-
***type** - Notification type key, this argument is mandatory
163
-
***priority** - Priority of the notification, this argument is optional, it defaults to NEUTRAL
164
-
***properties** - A key-value pair that is used to fill a placeholder of the notification type template, this argument is optional
165
-
***navigation** - All navigation related parameters, this argument is optional
166
-
***payload** - The rest parameters that can be passed, this argument is optional
194
+
167
195
168
196
##### Passing the whole notification object
169
197
170
198
By using this approach you need to pass the whole notification object as described in the API documentation
199
+
200
+
201
+
171
202
```js
172
203
alert.notify({
173
204
NotificationTypeKey:'IncidentCreated',
@@ -193,31 +224,14 @@ alert.notify({
193
224
});
194
225
```
195
226
196
-
### Sample Application with notifications
197
-
198
-
#### In Local Environment
199
-
In local environment, when you publish notification, it is mocked to publish the nofication to the console.
200
-
201
-
<imgwidth="1300"alt="Notify to console"style="border-radius:0.5rem;padding:1rem;background:rgb(242424)"src="_assets/notifyToConsole.png">
202
227
203
-
#### In Production Environment
204
-
205
-
##### Notification Destination
206
-
207
-
As a pre-requisite to publish the notification, you need to have a [destination](https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/enabling-notifications-for-custom-apps-on-sap-btp-cloud-foundry#configure-the-destination-to-the-notifications-service) configured to publish the notification. In the `package.json` by default destination name `SAP_Notification` is added, you can modify the destination name that you are configuring.
208
-
209
-
##### Integrate with SAP Build Work Zone
210
-
211
-
Once application is deployed and [integrated with SAP Build Work Zone](https://github.com/cap-js/calesi/tree/main/samples/notifications), you can see the notification under fiori notifications icon!
This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/change-tracking/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
218
232
219
233
220
-
###Code of Conduct
234
+
## Code of Conduct
221
235
222
236
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
0 commit comments