@azure/notification-hubs 1.0.0-beta.5 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -113
- package/dist/index.cjs +625 -602
- package/dist/index.cjs.map +1 -1
- package/dist-esm/src/api/beginSubmitNotificationHubJob.js +131 -0
- package/dist-esm/src/api/beginSubmitNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/cancelScheduledNotification.js +1 -1
- package/dist-esm/src/api/cancelScheduledNotification.js.map +1 -0
- package/dist-esm/src/{client → api}/createOrUpdateInstallation.js +1 -1
- package/dist-esm/src/api/createOrUpdateInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/createOrUpdateRegistration.js +1 -1
- package/dist-esm/src/api/createOrUpdateRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/createRegistration.js +1 -1
- package/dist-esm/src/api/createRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/createRegistrationId.js +1 -1
- package/dist-esm/src/api/createRegistrationId.js.map +1 -0
- package/dist-esm/src/{client → api}/deleteInstallation.js +1 -1
- package/dist-esm/src/api/deleteInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/deleteRegistration.js +1 -1
- package/dist-esm/src/api/deleteRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/getFeedbackContainerUrl.js +1 -1
- package/dist-esm/src/api/getFeedbackContainerUrl.js.map +1 -0
- package/dist-esm/src/{client → api}/getInstallation.js +1 -1
- package/dist-esm/src/api/getInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/getNotificationHubJob.js +1 -1
- package/dist-esm/src/api/getNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/getNotificationOutcomeDetails.js +1 -1
- package/dist-esm/src/api/getNotificationOutcomeDetails.js.map +1 -0
- package/dist-esm/src/{client → api}/getRegistration.js +1 -1
- package/dist-esm/src/api/getRegistration.js.map +1 -0
- package/dist-esm/src/{client → api}/index.js +24 -2
- package/dist-esm/src/api/index.js.map +1 -0
- package/dist-esm/src/{client → api}/internal/_client.js +1 -1
- package/dist-esm/src/api/internal/_client.js.map +1 -0
- package/dist-esm/src/{client → api}/internal/_createOrUpdateRegistrationDescription.js +0 -0
- package/dist-esm/src/api/internal/_createOrUpdateRegistrationDescription.js.map +1 -0
- package/dist-esm/src/{client/listRegistrations.js → api/internal/_listRegistrations.js} +6 -38
- package/dist-esm/src/api/internal/_listRegistrations.js.map +1 -0
- package/dist-esm/src/{client → api}/listNotificationHubJobs.js +1 -1
- package/dist-esm/src/api/listNotificationHubJobs.js.map +1 -0
- package/dist-esm/src/api/listRegistrations.js +35 -0
- package/dist-esm/src/api/listRegistrations.js.map +1 -0
- package/dist-esm/src/api/listRegistrationsByChannel.js +58 -0
- package/dist-esm/src/api/listRegistrationsByChannel.js.map +1 -0
- package/dist-esm/src/{client → api}/listRegistrationsByTag.js +1 -1
- package/dist-esm/src/api/listRegistrationsByTag.js.map +1 -0
- package/dist-esm/src/api/scheduleNotification.js +31 -0
- package/dist-esm/src/api/scheduleNotification.js.map +1 -0
- package/dist-esm/src/api/sendNotification.js +63 -0
- package/dist-esm/src/api/sendNotification.js.map +1 -0
- package/dist-esm/src/{client → api}/submitNotificationHubJob.js +1 -1
- package/dist-esm/src/api/submitNotificationHubJob.js.map +1 -0
- package/dist-esm/src/{client → api}/updateInstallation.js +1 -1
- package/dist-esm/src/api/updateInstallation.js.map +1 -0
- package/dist-esm/src/{client → api}/updateRegistration.js +1 -1
- package/dist-esm/src/api/updateRegistration.js.map +1 -0
- package/dist-esm/src/index.js +3 -2
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models/index.js +12 -0
- package/dist-esm/src/models/index.js.map +1 -0
- package/dist-esm/src/models/installation.js.map +1 -1
- package/dist-esm/src/models/notification.js.map +1 -1
- package/dist-esm/src/models/notificationBodyBuilder.js +48 -0
- package/dist-esm/src/models/notificationBodyBuilder.js.map +1 -0
- package/dist-esm/src/models/notificationDetails.js.map +1 -1
- package/dist-esm/src/models/notificationHubJob.js.map +1 -1
- package/dist-esm/src/models/options.js.map +1 -1
- package/dist-esm/src/models/registration.js +12 -12
- package/dist-esm/src/models/registration.js.map +1 -1
- package/dist-esm/src/models/tagExpressionBuilder.js +11 -0
- package/dist-esm/src/models/tagExpressionBuilder.js.map +1 -0
- package/dist-esm/src/notificationHubsClient.js +49 -68
- package/dist-esm/src/notificationHubsClient.js.map +1 -1
- package/dist-esm/src/serializers/notificationDetailsSerializer.js +2 -1
- package/dist-esm/src/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist-esm/src/serializers/notificationHubJobSerializer.js +3 -1
- package/dist-esm/src/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js +2 -2
- package/dist-esm/src/serializers/notificationOutcomeSerializer.js.map +1 -1
- package/dist-esm/src/serializers/registrationSerializer.js +16 -16
- package/dist-esm/src/serializers/registrationSerializer.js.map +1 -1
- package/dist-esm/src/utils/constants.js +1 -1
- package/dist-esm/src/utils/constants.js.map +1 -1
- package/dist-esm/src/utils/notificationUtils.js +19 -0
- package/dist-esm/src/utils/notificationUtils.js.map +1 -0
- package/dist-esm/src/utils/optionUtils.js +20 -0
- package/dist-esm/src/utils/optionUtils.js.map +1 -0
- package/package.json +14 -17
- package/types/3.1/notification-hubs.d.ts +468 -281
- package/types/latest/notification-hubs.d.ts +500 -286
- package/types/latest/tsdoc-metadata.json +1 -1
- package/types/src/api/beginSubmitNotificationHubJob.d.ts +12 -0
- package/types/src/api/beginSubmitNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/cancelScheduledNotification.d.ts +0 -0
- package/types/src/api/cancelScheduledNotification.d.ts.map +1 -0
- package/types/src/{client → api}/createOrUpdateInstallation.d.ts +0 -0
- package/types/src/api/createOrUpdateInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/createOrUpdateRegistration.d.ts +0 -0
- package/types/src/api/createOrUpdateRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/createRegistration.d.ts +0 -0
- package/types/src/api/createRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/createRegistrationId.d.ts +0 -0
- package/types/src/api/createRegistrationId.d.ts.map +1 -0
- package/types/src/{client → api}/deleteInstallation.d.ts +0 -0
- package/types/src/api/deleteInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/deleteRegistration.d.ts +0 -0
- package/types/src/api/deleteRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/getFeedbackContainerUrl.d.ts +0 -0
- package/types/src/api/getFeedbackContainerUrl.d.ts.map +1 -0
- package/types/src/{client → api}/getInstallation.d.ts +0 -0
- package/types/src/api/getInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/getNotificationHubJob.d.ts +0 -0
- package/types/src/api/getNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/getNotificationOutcomeDetails.d.ts +0 -0
- package/types/src/api/getNotificationOutcomeDetails.d.ts.map +1 -0
- package/types/src/{client → api}/getRegistration.d.ts +0 -0
- package/types/src/api/getRegistration.d.ts.map +1 -0
- package/types/src/{client → api}/index.d.ts +23 -1
- package/types/src/api/index.d.ts.map +1 -0
- package/types/src/{client → api}/internal/_client.d.ts +0 -0
- package/types/src/api/internal/_client.d.ts.map +1 -0
- package/types/src/{client → api}/internal/_createOrUpdateRegistrationDescription.d.ts +0 -0
- package/types/src/api/internal/_createOrUpdateRegistrationDescription.d.ts.map +1 -0
- package/types/src/api/internal/_listRegistrations.d.ts +6 -0
- package/types/src/api/internal/_listRegistrations.d.ts.map +1 -0
- package/types/src/{client → api}/listNotificationHubJobs.d.ts +0 -0
- package/types/src/api/listNotificationHubJobs.d.ts.map +1 -0
- package/types/src/{client → api}/listRegistrations.d.ts +3 -3
- package/types/src/api/listRegistrations.d.ts.map +1 -0
- package/types/src/api/listRegistrationsByChannel.d.ts +13 -0
- package/types/src/api/listRegistrationsByChannel.d.ts.map +1 -0
- package/types/src/{client → api}/listRegistrationsByTag.d.ts +0 -0
- package/types/src/api/listRegistrationsByTag.d.ts.map +1 -0
- package/types/src/{client → api}/scheduleNotification.d.ts +3 -5
- package/types/src/api/scheduleNotification.d.ts.map +1 -0
- package/types/src/{client → api}/sendNotification.d.ts +3 -5
- package/types/src/api/sendNotification.d.ts.map +1 -0
- package/types/src/{client → api}/submitNotificationHubJob.d.ts +0 -0
- package/types/src/api/submitNotificationHubJob.d.ts.map +1 -0
- package/types/src/{client → api}/updateInstallation.d.ts +0 -0
- package/types/src/api/updateInstallation.d.ts.map +1 -0
- package/types/src/{client → api}/updateRegistration.d.ts +0 -0
- package/types/src/api/updateRegistration.d.ts.map +1 -0
- package/types/src/index.d.ts +3 -2
- package/types/src/index.d.ts.map +1 -1
- package/types/src/models/index.d.ts +10 -0
- package/types/src/models/index.d.ts.map +1 -0
- package/types/src/models/installation.d.ts +12 -11
- package/types/src/models/installation.d.ts.map +1 -1
- package/types/src/models/notification.d.ts +10 -18
- package/types/src/models/notification.d.ts.map +1 -1
- package/types/src/models/{notificationBuilder.d.ts → notificationBodyBuilder.d.ts} +62 -64
- package/types/src/models/notificationBodyBuilder.d.ts.map +1 -0
- package/types/src/models/notificationDetails.d.ts +9 -9
- package/types/src/models/notificationDetails.d.ts.map +1 -1
- package/types/src/models/notificationHubJob.d.ts +5 -0
- package/types/src/models/notificationHubJob.d.ts.map +1 -1
- package/types/src/models/options.d.ts +36 -2
- package/types/src/models/options.d.ts.map +1 -1
- package/types/src/models/registration.d.ts +235 -69
- package/types/src/models/registration.d.ts.map +1 -1
- package/types/src/models/tagExpressionBuilder.d.ts +7 -0
- package/types/src/models/tagExpressionBuilder.d.ts.map +1 -0
- package/types/src/notificationHubsClient.d.ts +25 -41
- package/types/src/notificationHubsClient.d.ts.map +1 -1
- package/types/src/serializers/registrationSerializer.d.ts +14 -14
- package/types/src/serializers/registrationSerializer.d.ts.map +1 -1
- package/types/src/utils/notificationUtils.d.ts +6 -0
- package/types/src/utils/notificationUtils.d.ts.map +1 -0
- package/types/src/utils/optionUtils.d.ts +14 -0
- package/types/src/utils/optionUtils.d.ts.map +1 -0
- package/dist-esm/src/client/cancelScheduledNotification.js.map +0 -1
- package/dist-esm/src/client/createOrUpdateInstallation.js.map +0 -1
- package/dist-esm/src/client/createOrUpdateRegistration.js.map +0 -1
- package/dist-esm/src/client/createRegistration.js.map +0 -1
- package/dist-esm/src/client/createRegistrationId.js.map +0 -1
- package/dist-esm/src/client/deleteInstallation.js.map +0 -1
- package/dist-esm/src/client/deleteRegistration.js.map +0 -1
- package/dist-esm/src/client/getFeedbackContainerUrl.js.map +0 -1
- package/dist-esm/src/client/getInstallation.js.map +0 -1
- package/dist-esm/src/client/getNotificationHubJob.js.map +0 -1
- package/dist-esm/src/client/getNotificationOutcomeDetails.js.map +0 -1
- package/dist-esm/src/client/getRegistration.js.map +0 -1
- package/dist-esm/src/client/index.js.map +0 -1
- package/dist-esm/src/client/internal/_client.js.map +0 -1
- package/dist-esm/src/client/internal/_createOrUpdateRegistrationDescription.js.map +0 -1
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js +0 -38
- package/dist-esm/src/client/internal/_scheduleNotificationPayload.js.map +0 -1
- package/dist-esm/src/client/internal/_sendNotificationPayload.js +0 -51
- package/dist-esm/src/client/internal/_sendNotificationPayload.js.map +0 -1
- package/dist-esm/src/client/listNotificationHubJobs.js.map +0 -1
- package/dist-esm/src/client/listRegistrations.js.map +0 -1
- package/dist-esm/src/client/listRegistrationsByTag.js.map +0 -1
- package/dist-esm/src/client/scheduleBroadcastNotification.js +0 -17
- package/dist-esm/src/client/scheduleBroadcastNotification.js.map +0 -1
- package/dist-esm/src/client/scheduleNotification.js +0 -18
- package/dist-esm/src/client/scheduleNotification.js.map +0 -1
- package/dist-esm/src/client/sendBroadcastNotification.js +0 -15
- package/dist-esm/src/client/sendBroadcastNotification.js.map +0 -1
- package/dist-esm/src/client/sendDirectNotification.js +0 -15
- package/dist-esm/src/client/sendDirectNotification.js.map +0 -1
- package/dist-esm/src/client/sendNotification.js +0 -16
- package/dist-esm/src/client/sendNotification.js.map +0 -1
- package/dist-esm/src/client/submitNotificationHubJob.js.map +0 -1
- package/dist-esm/src/client/updateInstallation.js.map +0 -1
- package/dist-esm/src/client/updateRegistration.js.map +0 -1
- package/dist-esm/src/models/notificationBuilder.js +0 -169
- package/dist-esm/src/models/notificationBuilder.js.map +0 -1
- package/dist-esm/src/utils/retryPolicy.js +0 -144
- package/dist-esm/src/utils/retryPolicy.js.map +0 -1
- package/types/src/client/cancelScheduledNotification.d.ts.map +0 -1
- package/types/src/client/createOrUpdateInstallation.d.ts.map +0 -1
- package/types/src/client/createOrUpdateRegistration.d.ts.map +0 -1
- package/types/src/client/createRegistration.d.ts.map +0 -1
- package/types/src/client/createRegistrationId.d.ts.map +0 -1
- package/types/src/client/deleteInstallation.d.ts.map +0 -1
- package/types/src/client/deleteRegistration.d.ts.map +0 -1
- package/types/src/client/getFeedbackContainerUrl.d.ts.map +0 -1
- package/types/src/client/getInstallation.d.ts.map +0 -1
- package/types/src/client/getNotificationHubJob.d.ts.map +0 -1
- package/types/src/client/getNotificationOutcomeDetails.d.ts.map +0 -1
- package/types/src/client/getRegistration.d.ts.map +0 -1
- package/types/src/client/index.d.ts.map +0 -1
- package/types/src/client/internal/_client.d.ts.map +0 -1
- package/types/src/client/internal/_createOrUpdateRegistrationDescription.d.ts.map +0 -1
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts +0 -9
- package/types/src/client/internal/_scheduleNotificationPayload.d.ts.map +0 -1
- package/types/src/client/internal/_sendNotificationPayload.d.ts +0 -10
- package/types/src/client/internal/_sendNotificationPayload.d.ts.map +0 -1
- package/types/src/client/listNotificationHubJobs.d.ts.map +0 -1
- package/types/src/client/listRegistrations.d.ts.map +0 -1
- package/types/src/client/listRegistrationsByTag.d.ts.map +0 -1
- package/types/src/client/scheduleBroadcastNotification.d.ts +0 -16
- package/types/src/client/scheduleBroadcastNotification.d.ts.map +0 -1
- package/types/src/client/scheduleNotification.d.ts.map +0 -1
- package/types/src/client/sendBroadcastNotification.d.ts +0 -14
- package/types/src/client/sendBroadcastNotification.d.ts.map +0 -1
- package/types/src/client/sendDirectNotification.d.ts +0 -15
- package/types/src/client/sendDirectNotification.d.ts.map +0 -1
- package/types/src/client/sendNotification.d.ts.map +0 -1
- package/types/src/client/submitNotificationHubJob.d.ts.map +0 -1
- package/types/src/client/updateInstallation.d.ts.map +0 -1
- package/types/src/client/updateRegistration.d.ts.map +0 -1
- package/types/src/models/notificationBuilder.d.ts.map +0 -1
- package/types/src/utils/retryPolicy.d.ts +0 -72
- package/types/src/utils/retryPolicy.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Key links:
|
|
|
20
20
|
|
|
21
21
|
### Currently supported environments
|
|
22
22
|
|
|
23
|
-
- [LTS versions of Node.js](https://
|
|
23
|
+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
|
24
24
|
- Latest versions of Safari, Chrome, Edge, and Firefox.
|
|
25
25
|
|
|
26
26
|
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
|
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
createAppleInstallation
|
|
58
58
|
} from "@azure/notification-hubs";
|
|
59
59
|
|
|
60
|
-
const client = new
|
|
60
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
61
61
|
|
|
62
62
|
const installation = createAppleInstallation({
|
|
63
63
|
installationId: "<installation-id>",
|
|
@@ -70,24 +70,17 @@ const result = await client.createOrUpdateInstallation(installation);
|
|
|
70
70
|
|
|
71
71
|
The modular approach allows the developer to pick and choose which functions to import as each method is exposed individually. This approach uses subpath-exports with ES-Modules to expose the methods via direct imports. With the individual exports, this creates a better tree-shaking experience and smaller bundle sizes that the developer can take advantage of.
|
|
72
72
|
|
|
73
|
-
Note that creating a client is exposed through the `"@azure/notification-hubs/
|
|
73
|
+
Note that creating a client is exposed through the `"@azure/notification-hubs/api"` subpath and all client methods are exposed through the `"@azure/notification-hubs/api"` subpath. Each function exported takes the `client` as the first parameter and the rest of the parameters remain unchanged.
|
|
74
74
|
|
|
75
75
|
The following subpaths are exposed:
|
|
76
76
|
|
|
77
|
-
- `@azure/notification-hubs/
|
|
78
|
-
- `@azure/notification-hubs/
|
|
79
|
-
- `@azure/notification-hubs/models/installation` - The installation models and factory methods.
|
|
80
|
-
- `@azure/notification-hubs/models/notification` - The notification models and factory methods.
|
|
81
|
-
- `@azure/notification-hubs/models/notificationBuilder` - The notification builder models and factory methods.
|
|
82
|
-
- `@azure/notification-hubs/models/options` - The method options such as `SendOperationOptions`.
|
|
83
|
-
- `@azure/notification-hubs/models/registration` - The registration models and factory methods.
|
|
77
|
+
- `@azure/notification-hubs/api` - The main entry point for the client via `createClientContext` and client methods such as `getInstallation` or `sendNotification`
|
|
78
|
+
- `@azure/notification-hubs/models` - The Notification Hubs models and factory methods.
|
|
84
79
|
|
|
85
80
|
The above code snippet then becomes the following:
|
|
86
81
|
|
|
87
82
|
```typescript
|
|
88
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
89
|
-
import { createAppleInstallation } from "@azure/notification-hubs/models/installation";
|
|
90
|
-
import { createOrUpdateInstallation } from "@azure/notification-hubs/client/createOrUpdateInstallation";
|
|
83
|
+
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
|
|
91
84
|
|
|
92
85
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
93
86
|
|
|
@@ -102,22 +95,22 @@ const result = await createOrUpdateInstallation(context, installation);
|
|
|
102
95
|
|
|
103
96
|
### Authenticate the client
|
|
104
97
|
|
|
105
|
-
Interaction with an Azure Notification Hub starts with the `
|
|
98
|
+
Interaction with an Azure Notification Hub starts with the `NotificationHubsClient` which supports [Shared Access Signature connection strings](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-security). This includes the following permission levels: **Listen**, **Manage**, **Send**.
|
|
106
99
|
|
|
107
100
|
Listen allows for a client to register itself via the Registration and Installations API. Send allows for the client to send notifications to devices using the send APIs. Finally, Manage allows the user to do Registration and Installation management, such as queries.
|
|
108
101
|
|
|
109
|
-
A new `
|
|
102
|
+
A new `NotificationHubsClient` client can be created using the constructor with the connection string and Notification Hub name.
|
|
110
103
|
|
|
111
104
|
```typescript
|
|
112
|
-
import {
|
|
105
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
113
106
|
|
|
114
|
-
const client = new
|
|
107
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
115
108
|
```
|
|
116
109
|
|
|
117
|
-
Using the modular approach, the `createClientContext` can be imported via the `"@azure/notification-hubs/
|
|
110
|
+
Using the modular approach, the `createClientContext` can be imported via the `"@azure/notification-hubs/api"` subpath.
|
|
118
111
|
|
|
119
112
|
```typescript
|
|
120
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
113
|
+
import { createClientContext } from "@azure/notification-hubs/api";
|
|
121
114
|
|
|
122
115
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
123
116
|
```
|
|
@@ -145,10 +138,10 @@ Installations are a newer and native JSON approach to device management that con
|
|
|
145
138
|
Installations can be created through the `createOrUpdateInstallation` method such as the following:
|
|
146
139
|
|
|
147
140
|
```typescript
|
|
148
|
-
import {
|
|
141
|
+
import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
|
|
149
142
|
import { v4 as uuid } from "uuid";
|
|
150
143
|
|
|
151
|
-
const client = new
|
|
144
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
152
145
|
|
|
153
146
|
// Create an installation for APNs
|
|
154
147
|
let installation = createAppleInstallation({
|
|
@@ -163,9 +156,8 @@ installation = await client.createOrUpdateInstallation(installation);
|
|
|
163
156
|
Using the modular approach, the code would be as follows:
|
|
164
157
|
|
|
165
158
|
```typescript
|
|
166
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
167
|
-
import { createAppleInstallation } from "@azure/notification-hubs/models
|
|
168
|
-
import { createOrUpdateInstallation } from "@azure/notification-hubs/client/createOrUpdateInstallation";
|
|
159
|
+
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
|
|
160
|
+
import { createAppleInstallation } from "@azure/notification-hubs/models";
|
|
169
161
|
import { v4 as uuid } from "uuid";
|
|
170
162
|
|
|
171
163
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
@@ -183,9 +175,9 @@ installation = await createOrUpdateInstallation(context, installation);
|
|
|
183
175
|
An update to an installation can be made through the JSON Patch schema such as adding a tag and a user ID using the `updateInstallation` method.
|
|
184
176
|
|
|
185
177
|
```typescript
|
|
186
|
-
import {
|
|
178
|
+
import { NotificationHubsClient, JsonPatch } from "@azure/notification-hubs";
|
|
187
179
|
|
|
188
|
-
const client = new
|
|
180
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
189
181
|
|
|
190
182
|
const installationId = "<unique installation ID>";
|
|
191
183
|
|
|
@@ -200,9 +192,8 @@ const installation = await client.updateInstallation(installationId, updates);
|
|
|
200
192
|
Using the modular approach, the code would be as follows:
|
|
201
193
|
|
|
202
194
|
```typescript
|
|
203
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
204
|
-
import { JsonPatch, createAppleInstallation } from "@azure/notification-hubs/models
|
|
205
|
-
import { updateInstallation } from "@azure/notification-hubs/client/updateInstallation";
|
|
195
|
+
import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
|
|
196
|
+
import { JsonPatch, createAppleInstallation } from "@azure/notification-hubs/models";
|
|
206
197
|
|
|
207
198
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
208
199
|
|
|
@@ -219,9 +210,9 @@ const installation = await updateInstallation(context, installationId, updates);
|
|
|
219
210
|
To retrieve an existing installation, use the `getInstallation` method with your existing unique installation ID.
|
|
220
211
|
|
|
221
212
|
```typescript
|
|
222
|
-
import {
|
|
213
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
223
214
|
|
|
224
|
-
const client = new
|
|
215
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
225
216
|
|
|
226
217
|
const installationId = "<unique installation ID>";
|
|
227
218
|
|
|
@@ -231,8 +222,7 @@ const installation = client.getInstallation(installationId);
|
|
|
231
222
|
Using the modular approach, the code would be as follows:
|
|
232
223
|
|
|
233
224
|
```typescript
|
|
234
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
235
|
-
import { getInstallation } from "@azure/notification-hubs/client/getInstallation";
|
|
225
|
+
import { createClientContext, getInstallation } from "@azure/notification-hubs/api";
|
|
236
226
|
|
|
237
227
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
238
228
|
|
|
@@ -249,11 +239,11 @@ An installation may be created in one of two ways, first by getting a registrati
|
|
|
249
239
|
|
|
250
240
|
```typescript
|
|
251
241
|
import {
|
|
252
|
-
|
|
242
|
+
NotificationHubsClient,
|
|
253
243
|
createAppleRegistrationDescription,
|
|
254
244
|
} from "@azure/notification-hubs";
|
|
255
245
|
|
|
256
|
-
const client = new
|
|
246
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
257
247
|
|
|
258
248
|
let registration = createAppleRegistrationDescription({
|
|
259
249
|
deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
|
|
@@ -268,9 +258,8 @@ console.log(`New Registration ID: ${registration.registrationId}`);
|
|
|
268
258
|
Using the modular approach, the code would be as follows:
|
|
269
259
|
|
|
270
260
|
```typescript
|
|
271
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
272
|
-
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models
|
|
273
|
-
import { createRegistration } from "@azure/notification-hubs/client/createRegistration";
|
|
261
|
+
import { createClientContext, createRegistration } from "@azure/notification-hubs/api";
|
|
262
|
+
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models";
|
|
274
263
|
|
|
275
264
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
276
265
|
|
|
@@ -287,9 +276,9 @@ console.log(`New Registration ID: ${registration.registrationId}`);
|
|
|
287
276
|
Updates can be done via the `updateRegistration` method but unlike installations, does not support incremental updates. Querying for an existing registration can be done with the `getRegistration` method.
|
|
288
277
|
|
|
289
278
|
```typescript
|
|
290
|
-
import {
|
|
279
|
+
import { NotificationHubsClient } from "@azure/notification-hubs";
|
|
291
280
|
|
|
292
|
-
const client = new
|
|
281
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
293
282
|
|
|
294
283
|
const registrationId = "<unique Registration ID>";
|
|
295
284
|
|
|
@@ -303,9 +292,11 @@ registration = await client.updateRegistration(registration);
|
|
|
303
292
|
Using the modular approach, the code would be as follows:
|
|
304
293
|
|
|
305
294
|
```typescript
|
|
306
|
-
import {
|
|
307
|
-
|
|
308
|
-
|
|
295
|
+
import {
|
|
296
|
+
createClientContext,
|
|
297
|
+
getRegistration,
|
|
298
|
+
updateRegistration
|
|
299
|
+
} from "@azure/notification-hubs/api";
|
|
309
300
|
|
|
310
301
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
311
302
|
|
|
@@ -318,12 +309,12 @@ registration.tags.push("likes_sports");
|
|
|
318
309
|
registration = await updateRegistration(context, registration);
|
|
319
310
|
```
|
|
320
311
|
|
|
321
|
-
Registrations, unlike installations, can be queried to get all registrations, matching registrations to a condition, or by tags. Registrations can be queried using the `listRegistrations` and `listRegistrationsByTag` method.
|
|
312
|
+
Registrations, unlike installations, can be queried to get all registrations, matching registrations to a condition, or by tags. Registrations can be queried using the `listRegistrations`, `listRegistrationsByChannel` and `listRegistrationsByTag` method. All methods support limiting via the `top` option and support asynchronous paging.
|
|
322
313
|
|
|
323
314
|
```typescript
|
|
324
|
-
import {
|
|
315
|
+
import { NotificationHubsClient } from "@azure/notification-hubs/api";
|
|
325
316
|
|
|
326
|
-
const client = new
|
|
317
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
327
318
|
|
|
328
319
|
const registrations = await client.listRegistrationsByTag("likes_hockey");
|
|
329
320
|
|
|
@@ -339,8 +330,7 @@ for await (const pages of registrations.byPage()) {
|
|
|
339
330
|
Using the modular approach, the code would be as follows:
|
|
340
331
|
|
|
341
332
|
```typescript
|
|
342
|
-
import { createClientContext } from "@azure/notification-hubs/
|
|
343
|
-
import { listRegistrationsByTag } from "@azure/notification-hubs/client/listRegistrationsByTag";
|
|
333
|
+
import { createClientContext, listRegistrationsByTag } from "@azure/notification-hubs/api";
|
|
344
334
|
|
|
345
335
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
346
336
|
|
|
@@ -359,19 +349,18 @@ for await (const pages of registrations.byPage()) {
|
|
|
359
349
|
|
|
360
350
|
Notification Hubs supports sending notifications to devices either directly using the unique PNS provided identifier, using tags for audience send, or a general broadcast to all devices. Using the Standard SKU and above, [scheduled send](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-send-push-notifications-scheduled) allows the user to schedule notifications up to seven days in advance. All send operations return a Tracking ID and Correlation ID which can be used for Notification Hubs support cases. With the Standard SKU and above, a Notification ID is also returned which can be used to get notification telemetry via the `getNotificationOutcomeDetails` method.
|
|
361
351
|
|
|
362
|
-
For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `sendNotification`
|
|
352
|
+
For debugging purposes, the `enableTestSend` options can be set to `true` which gets immediate feedback from the PNS on the `sendNotification` method, however, is not supported in production scenarios. This is not supported on the scheduled send methods.
|
|
363
353
|
|
|
364
|
-
Raw JSON or XML strings can be sent to the send or scheduled send methods, or the notification builders can be used which helps construct messages per PNS such as APNs, Firebase, Baidu, ADM and WNS. These builders will build the native message format
|
|
354
|
+
Raw JSON or XML strings can be sent to the send or scheduled send methods, or the notification builders can be used which helps construct messages per PNS such as APNs, Firebase, Baidu, ADM and WNS. These builders will build the native message format so there is no guessing about which fields are available for each PNS.
|
|
365
355
|
|
|
366
356
|
```typescript
|
|
367
357
|
// Using the class-based approach
|
|
368
|
-
import {
|
|
358
|
+
import { createAppleNotificationBody } from "@azure/notification-hubs";
|
|
369
359
|
|
|
370
360
|
// Using the modular approach
|
|
371
|
-
import {
|
|
372
|
-
|
|
361
|
+
import { createAppleNotification, createAppleNotificationBody } from "@azure/notification-hubs/models";
|
|
373
362
|
|
|
374
|
-
const
|
|
363
|
+
const apnsBody = createAppleNotificationBody({
|
|
375
364
|
alert: {
|
|
376
365
|
title: "Notification Title",
|
|
377
366
|
subtitle: "Notification Subtitle",
|
|
@@ -382,20 +371,22 @@ const apnsMessage = buildAppleNativeMessage({
|
|
|
382
371
|
});
|
|
383
372
|
|
|
384
373
|
// Send the message using the modular approach
|
|
374
|
+
const notification = createAppleNotification({
|
|
375
|
+
body: apnsBody
|
|
376
|
+
})
|
|
385
377
|
|
|
386
|
-
const result = await
|
|
378
|
+
const result = await sendNotification(context, notification);
|
|
387
379
|
```
|
|
388
380
|
|
|
389
381
|
#### Broadcast Send
|
|
390
382
|
|
|
391
|
-
Notification Hubs can be used to send notifications to all registered devices per platform using broadcast send through the `
|
|
383
|
+
Notification Hubs can be used to send notifications to all registered devices per platform using broadcast send through the `sendNotification` method.
|
|
392
384
|
|
|
393
385
|
```typescript
|
|
394
386
|
import {
|
|
395
|
-
|
|
396
|
-
SendOperationOptions,
|
|
387
|
+
NotificationHubsClient,
|
|
397
388
|
createAppleNotification,
|
|
398
|
-
} from "@azure/notification-hubs/
|
|
389
|
+
} from "@azure/notification-hubs/api";
|
|
399
390
|
|
|
400
391
|
const context = createClientContext(connectionString, hubName);
|
|
401
392
|
|
|
@@ -409,9 +400,7 @@ const message = createAppleNotification({
|
|
|
409
400
|
},
|
|
410
401
|
});
|
|
411
402
|
|
|
412
|
-
|
|
413
|
-
const sendOptions: SendOperationOptions = { enableTestSend: false };
|
|
414
|
-
const result = await client.sendBroadcastNotification(message, sendOptions);
|
|
403
|
+
const result = await client.sendNotification(message);
|
|
415
404
|
|
|
416
405
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
417
406
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -425,10 +414,8 @@ if (result.notificationId) {
|
|
|
425
414
|
Using the modular approach, the code would be as follows:
|
|
426
415
|
|
|
427
416
|
```typescript
|
|
428
|
-
import {
|
|
429
|
-
import {
|
|
430
|
-
import { createAppleNotification } from "@azure/notification-hubs/models/notification";
|
|
431
|
-
import { sendBroadcastNotification } from "@azure/notification-hubs/client/sendBroadcastNotification";
|
|
417
|
+
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
|
|
418
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
432
419
|
|
|
433
420
|
const context = createClientContext(connectionString, hubName);
|
|
434
421
|
|
|
@@ -442,9 +429,7 @@ const message = createAppleNotification({
|
|
|
442
429
|
},
|
|
443
430
|
});
|
|
444
431
|
|
|
445
|
-
|
|
446
|
-
const sendOptions: SendOperationOptions = { enableTestSend: false };
|
|
447
|
-
const result = await sendBroadcastNotification(context, message, sendOptions);
|
|
432
|
+
const result = await sendNotification(context, message);
|
|
448
433
|
|
|
449
434
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
450
435
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -457,18 +442,17 @@ if (result.notificationId) {
|
|
|
457
442
|
|
|
458
443
|
#### Direct Send
|
|
459
444
|
|
|
460
|
-
To send directly a device, the user can send using the platform provided unique identifier such as APNs device token by calling the `
|
|
445
|
+
To send directly a device, the user can send using the platform provided unique identifier such as APNs device token by calling the `sendNotification` method with a `deviceHandle` parameter.
|
|
461
446
|
|
|
462
447
|
```typescript
|
|
463
448
|
import {
|
|
464
|
-
|
|
465
|
-
SendOperationOptions,
|
|
449
|
+
NotificationHubsClient,
|
|
466
450
|
createAppleNotification,
|
|
467
451
|
} from "@azure/notification-hubs";
|
|
468
452
|
|
|
469
|
-
const client = new
|
|
453
|
+
const client = new NotificationHubsClient(connectionString, hubName);
|
|
470
454
|
|
|
471
|
-
const
|
|
455
|
+
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
|
472
456
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
473
457
|
|
|
474
458
|
const message = createAppleNotification({
|
|
@@ -479,7 +463,7 @@ const message = createAppleNotification({
|
|
|
479
463
|
},
|
|
480
464
|
});
|
|
481
465
|
|
|
482
|
-
const result = await client.
|
|
466
|
+
const result = await client.sendNotification(message, { deviceHandle });
|
|
483
467
|
|
|
484
468
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
485
469
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -493,14 +477,12 @@ if (result.notificationId) {
|
|
|
493
477
|
Using the modular approach, the code would be as follows:
|
|
494
478
|
|
|
495
479
|
```typescript
|
|
496
|
-
import {
|
|
497
|
-
import {
|
|
498
|
-
import { createAppleNotification } from "@azure/notification-hubs/models/notification";
|
|
499
|
-
import { sendDirectNotification } from "@azure/notification-hubs/client/sendDirectNotification";
|
|
480
|
+
import { createClientContext, sendDirectNotification } from "@azure/notification-hubs/api";
|
|
481
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
500
482
|
|
|
501
483
|
const context = createClientContext(connectionString, hubName);
|
|
502
484
|
|
|
503
|
-
const
|
|
485
|
+
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
|
|
504
486
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
505
487
|
|
|
506
488
|
const message = createAppleNotification({
|
|
@@ -511,7 +493,7 @@ const message = createAppleNotification({
|
|
|
511
493
|
},
|
|
512
494
|
});
|
|
513
495
|
|
|
514
|
-
const result = await
|
|
496
|
+
const result = await sendNotification(context, message, { deviceHandle });
|
|
515
497
|
|
|
516
498
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
517
499
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -526,19 +508,36 @@ if (result.notificationId) {
|
|
|
526
508
|
|
|
527
509
|
In addition to targeting a single device, a user can target multiple devices using tags. These tags can be supplied as a list of tags, which then creates a tag expression to match registered devices, or via a tag expression which can then use Boolean logic to target the right audience. For more information about tags and tags expressions, see [Routing and Tag Expressions](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-tags-segment-push-message).
|
|
528
510
|
|
|
511
|
+
If you wish to create a tag expression from an array of tags, there is a Tag Expression Builder available with the `createTagExpression` method which is exposed at the top level import or `@azure/notification-hubs/models/tagExpressionBuilder` modular import which creates an "or tag expression" from the tags.
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
// Top level import
|
|
515
|
+
import { createTagExpression } from "@azure/notification-hubs";
|
|
516
|
+
|
|
517
|
+
// Modular import
|
|
518
|
+
import { createTagExpression } from "@azure/notification-hubs/models";
|
|
519
|
+
|
|
520
|
+
const tags = ["likes_football", "likes_hockey"];
|
|
521
|
+
const tagExpression = createTagExpression(tags);
|
|
522
|
+
|
|
523
|
+
console.log(tagExpression);
|
|
524
|
+
// likes_football||likes_hockey
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Tag expression messages can be sent using the following code:
|
|
528
|
+
|
|
529
529
|
```typescript
|
|
530
530
|
import {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
createAppleMessage,
|
|
531
|
+
NotificationHubsClient,
|
|
532
|
+
createAppleNotification,
|
|
534
533
|
} from "@azure/notification-hubs";
|
|
535
534
|
|
|
536
|
-
const client = new
|
|
535
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
537
536
|
|
|
538
537
|
const tagExpression = "likes_hockey && likes_football";
|
|
539
538
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
540
539
|
|
|
541
|
-
const
|
|
540
|
+
const notification = createAppleNotification({
|
|
542
541
|
body: messageBody,
|
|
543
542
|
headers: {
|
|
544
543
|
"apns-priority": "10",
|
|
@@ -546,10 +545,7 @@ const message = createAppleMessage({
|
|
|
546
545
|
},
|
|
547
546
|
});
|
|
548
547
|
|
|
549
|
-
|
|
550
|
-
// Not required but can set test send to true for debugging purposes.
|
|
551
|
-
const sendOptions: SendOperationOptions = { enableTestSend: false };
|
|
552
|
-
const result = await client.sendNotification(tagExpression, message, sendOptions);
|
|
548
|
+
const result = await client.sendNotification(notification, { tagExpression });
|
|
553
549
|
|
|
554
550
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
555
551
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -563,17 +559,15 @@ if (result.notificationId) {
|
|
|
563
559
|
Using the modular approach, the code would be as follows:
|
|
564
560
|
|
|
565
561
|
```typescript
|
|
566
|
-
import {
|
|
567
|
-
import {
|
|
568
|
-
import { createAppleNotification } from "@azure/notification-hubs/models/notification";
|
|
569
|
-
import { sendNotification } from "@azure/notification-hubs/client/sendNotification";
|
|
562
|
+
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
|
|
563
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
570
564
|
|
|
571
565
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
572
566
|
|
|
573
567
|
const tagExpression = "likes_hockey && likes_football";
|
|
574
568
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
575
569
|
|
|
576
|
-
const
|
|
570
|
+
const notification = createAppleNotification({
|
|
577
571
|
body: messageBody,
|
|
578
572
|
headers: {
|
|
579
573
|
"apns-priority": "10",
|
|
@@ -581,10 +575,7 @@ const message = createAppleMessage({
|
|
|
581
575
|
},
|
|
582
576
|
});
|
|
583
577
|
|
|
584
|
-
|
|
585
|
-
// Not required but can set test send to true for debugging purposes.
|
|
586
|
-
const sendOptions: SendOperationOptions = { enableTestSend: false };
|
|
587
|
-
const result = await sendNotification(context, tagExpression, message, sendOptions);
|
|
578
|
+
const result = await sendNotification(context, notification, { tagExpression });
|
|
588
579
|
|
|
589
580
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
590
581
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -597,21 +588,20 @@ if (result.notificationId) {
|
|
|
597
588
|
|
|
598
589
|
#### Scheduled Send
|
|
599
590
|
|
|
600
|
-
Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleBroadcastNotification` method to send to devices with tags or a general broadcast
|
|
591
|
+
Push notifications can be scheduled up to seven days in advance with Standard SKU namespaces and above using the `scheduleBroadcastNotification` method to send to devices with tags or a general broadcast. This returns a notification ID which can be then used to cancel if necessary via the `cancelScheduledNotification` method.
|
|
601
592
|
|
|
602
593
|
```typescript
|
|
603
594
|
import {
|
|
604
|
-
|
|
605
|
-
SendOperationOptions,
|
|
595
|
+
NotificationHubsClient,
|
|
606
596
|
createAppleNotification,
|
|
607
597
|
} from "@azure/notification-hubs";
|
|
608
598
|
|
|
609
|
-
const client = new
|
|
599
|
+
const client = new NotificationHubsClient("<connection string>", "<hub name>");
|
|
610
600
|
|
|
611
601
|
const tagExpression = "likes_hockey && likes_football";
|
|
612
602
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
613
603
|
|
|
614
|
-
// Schedule 8 hours from
|
|
604
|
+
// Schedule 8 hours from now
|
|
615
605
|
const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
|
|
616
606
|
|
|
617
607
|
const message = createAppleNotification({
|
|
@@ -622,7 +612,7 @@ const message = createAppleNotification({
|
|
|
622
612
|
},
|
|
623
613
|
});
|
|
624
614
|
|
|
625
|
-
const result = await client.scheduleNotification(scheduledTime,
|
|
615
|
+
const result = await client.scheduleNotification(scheduledTime, message, { tagExpression });
|
|
626
616
|
|
|
627
617
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
628
618
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -634,17 +624,15 @@ console.log(`Notification ID: ${result.notificationId}`);
|
|
|
634
624
|
Using the modular approach, the code would be as follows:
|
|
635
625
|
|
|
636
626
|
```typescript
|
|
637
|
-
import {
|
|
638
|
-
import {
|
|
639
|
-
import { createAppleNotification } from "@azure/notification-hubs/models/notification";
|
|
640
|
-
import { scheduleNotification } from "@azure/notification-hubs/client/scheduleNotification";
|
|
627
|
+
import { createClientContext, scheduleNotification } from "@azure/notification-hubs/api";
|
|
628
|
+
import { createAppleNotification } from "@azure/notification-hubs/models";
|
|
641
629
|
|
|
642
630
|
const context = createClientContext("<connection string>", "<hub name>");
|
|
643
631
|
|
|
644
632
|
const tagExpression = "likes_hockey && likes_football";
|
|
645
633
|
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
|
|
646
634
|
|
|
647
|
-
// Schedule 8 hours from
|
|
635
|
+
// Schedule 8 hours from now
|
|
648
636
|
const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
|
|
649
637
|
|
|
650
638
|
const message = createAppleNotification({
|
|
@@ -655,7 +643,7 @@ const message = createAppleNotification({
|
|
|
655
643
|
},
|
|
656
644
|
});
|
|
657
645
|
|
|
658
|
-
const result = await scheduleNotification(context, scheduledTime,
|
|
646
|
+
const result = await scheduleNotification(context, scheduledTime, message, { tagExpression });
|
|
659
647
|
|
|
660
648
|
console.log(`Tracking ID: ${result.trackingId}`);
|
|
661
649
|
console.log(`Correlation ID: ${result.correlationId}`);
|
|
@@ -673,8 +661,11 @@ Azure Notification Hubs has a complete guide to troubleshooting problems with dr
|
|
|
673
661
|
[Test send](https://docs.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-fixer#enabletestsend-property) is supported supported in the `sendNotification` method with the `enableTestSend` option:
|
|
674
662
|
|
|
675
663
|
```typescript
|
|
676
|
-
|
|
677
|
-
const result = await client.sendNotification(
|
|
664
|
+
// Using the client
|
|
665
|
+
const result = await client.sendNotification(notification, { tags, enableTestSend: true });
|
|
666
|
+
|
|
667
|
+
// Using the modular approach
|
|
668
|
+
const result = await sendNotification(context, notification, { tags, enableTestSend: true });
|
|
678
669
|
```
|
|
679
670
|
|
|
680
671
|
### Logging
|