-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathcreateInstallation.fcmV1.js
More file actions
45 lines (37 loc) · 1.68 KB
/
createInstallation.fcmV1.js
File metadata and controls
45 lines (37 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the createOrUpdateInstallation() method can be used to create or overwrite an
* installation in place.
*
* See https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-registration-management
* to learn about installations.
*
*
* @summary Demonstrates how to create or overwrite an installation using Azure Notification Hubs
*/
require("dotenv/config");
const { createClientContext, createOrUpdateInstallation } = require("@azure/notification-hubs/api");
const { createFcmV1Installation } = require("@azure/notification-hubs/models");
const { randomUUID } = require("@azure/core-util");
// Define connection string and hub name
const connectionString = process.env.NOTIFICATIONHUBS_CONNECTION_STRING || "<connection string>";
const hubName = process.env.NOTIFICATION_HUB_NAME || "<hub name>";
// Define message constants
const DUMMY_REGISTRATION = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const fcmV1RegistrationId = process.env.FCMV1_REGISTRATION_ID || DUMMY_REGISTRATION;
async function main() {
const context = createClientContext(connectionString, hubName);
const installation = createFcmV1Installation({
installationId: randomUUID(),
pushChannel: fcmV1RegistrationId,
tags: ["likes_hockey", "likes_football"],
});
const result = await createOrUpdateInstallation(context, installation);
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
}
main().catch((err) => {
console.log("createInstallation Sample: Error occurred: ", err);
process.exit(1);
});