次の方法で共有


JavaScript 用 Azure Notification Hubs SDK

Azure Notification Hubs には、任意のバックエンド (クラウドまたはオンプレミス) から任意のプラットフォーム (Apple、Amazon Kindle、Firebase、Baidu、Xiaomi、Web、Windows など) に通知を送信できるスケールアウトされたプッシュ エンジンが用意されています。 Notification Hubs は、エンタープライズ シナリオとコンシューマー シナリオの両方で適切に機能します。 シナリオの例を次に示します。

  • ニュース速報を何百万人ものユーザーに低遅延で送信します。
  • 関心のあるユーザーセグメントに位置情報ベースのクーポンを送信します。
  • メディア/スポーツ/金融/ゲーム アプリケーションのユーザーまたはグループにイベント関連の通知を送信します。
  • プロモーションコンテンツをアプリケーションにプッシュして、顧客を引き付けてマーケティングします。
  • 新しいメッセージや作業項目などのエンタープライズ イベントをユーザーに通知します。
  • 多要素認証用のコードを送信します。

主要なリンク:

: azure-sb パッケージを使用している場合は、 migration guide to move from azure-sb to @azure/notification-hubs

作業の開始

現在サポートされている環境

詳細については、 サポート ポリシー を参照してください。

パッケージをインストールする

npm install @azure/notification-hubs

[前提条件]

Azure Notification Hubs リソースを作成する

Azure Notification Hub は、次の方法を使用して作成できます。

  1. Azure Portal
  2. Azure CLI
  3. 二頭筋
  4. ARM テンプレート

作成後、通知ハブは Azure Portal または Azure CLI を使用して構成できます。

クライアントのインポート

この SDK for JavaScript には、クラスベースのアプローチとモジュール設計アプローチの 2 つの方法で Azure Notification Hubs を操作できます。 クラスベースのアプローチは、クライアントを作成し、クライアント上のメソッドと対話するために、すべてのパッケージで一貫しています。

import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const installation = createAppleInstallation({
  installationId: "<installation-id>",
  pushChannel: "<push-channel>",
  tags: ["likes_javascript"],
});

const result = await client.createOrUpdateInstallation(installation);

モジュール式アプローチにより、開発者は、各メソッドが個別に公開されるため、インポートする関数を選択できます。 このアプローチでは、ES-Modules でサブパスエクスポートを使用して、直接インポートを介してメソッドを公開します。 個々のエクスポートでは、ツリーの揺れエクスペリエンスが向上し、開発者が利用できるバンドルサイズが小さくなります。

クライアントの作成は "@azure/notification-hubs/api" サブパスを介して公開され、すべてのクライアントメソッドは "@azure/notification-hubs/api" サブパスを介して公開されることに注意してください。 エクスポートされた各関数は、 client を最初のパラメーターとして受け取り、残りのパラメーターは変更されません。

次のサブパスが公開されます。

  • @azure/notification-hubs/api - createClientContext およびクライアント メソッド ( getInstallationsendNotification
  • @azure/notification-hubs/models - Notification Hubs のモデルとファクトリ メソッド。

上記のコード スニペットは次のようになります。

import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
import { createAppleInstallation } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const installation = createAppleInstallation({
  installationId: "<installation-id>",
  pushChannel: "<push-channel>",
  tags: ["likes_javascript"],
});

const result = await createOrUpdateInstallation(context, installation);

クライアントを認証する

Azure Notification Hub との対話は、Shared Access Signature 接続文字列をサポートするNotificationHubsClientから始まります。 これには、 リスニング管理送信のアクセス許可レベルが含まれます。

Listen を使用すると、クライアントは Registration and Installations API を介して自分自身を登録できます。 送信を使用すると、クライアントは送信 API を使用してデバイスに通知を送信できます。 最後に、管理を使用すると、ユーザーはクエリなどの登録とインストールの管理を実行できます。

新しい NotificationHubsClient クライアントは、接続文字列と Notification Hub 名を持つコンストラクターを使用して作成できます。

import { NotificationHubsClient } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

モジュラーアプローチを使用すると、"@azure/notification-hubs/api"サブパスを介してcreateClientContextをインポートできます。

import { createClientContext } from "@azure/notification-hubs/api";

const context = createClientContext("<connection string>", "<hub name>");

重要な概念

NotificationHubClientが初期化されたら、次の概念を調べることができます。

  • インストールと登録によるデバイス管理説明
  • デバイスへの通知の送信

デバイスの管理

デバイス管理は、APNs や Firebase などのネイティブ プラットフォーム通知サービス (PNS) からの一意の識別子と、対象ユーザーへのプッシュ通知の送信に使用されるタグなどの関連メタデータを格納できるようにするための Notification Hubs の中核となる概念です。 これは、新しく推奨されるメカニズムであるインストール API と登録の 2 つの API を使用して行われます。

インストール API

インストールは、デバイス管理に対する新しいネイティブ JSON アプローチであり、オーディエンスへの送信に使用できるインストール ID やユーザー ID などの追加プロパティが含まれています。 インストール API には、既存の登録 API に比べて、次の点でいくつかの利点があります。

  • 完全なべき等 API であるため、インストール時に create を呼び出すため、重複を心配することなく操作を再試行できます。
  • userId プロパティと installationId プロパティをサポートし、$InstallationId:{myInstallId}$UserId:{bob@contoso.com} などのタグ式で使用できます。
  • テンプレートは、個別の登録ではなくインストールの一部となり、送信用のタグとして名前で参照できるようになりました。
  • 部分的な更新は JSON Patch Standard を通じてサポートされており、最初にインストールを照会することなく、タグを追加したり、他のデータを変更したりできます。

インストールは、次のような createOrUpdateInstallation 方法で作成できます。

import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

// Create an installation for APNs
const installation = createAppleInstallation({
  installationId: "0d8ab095-c449-493f-9195-17e4917806c4", // Must be unique
  pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
  tags: ["likes_hockey", "likes_football"],
});

const response = await client.createOrUpdateInstallation(installation);

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
import { createAppleInstallation } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

// Create an installation for APNs
const installation = createAppleInstallation({
  installationId: "0d8ab095-c449-493f-9195-17e4917806c4", // Must be unique
  pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
  tags: ["likes_hockey", "likes_football"],
});

const response = await createOrUpdateInstallation(context, installation);

インストールの更新は、 updateInstallation メソッドを使用してタグやユーザーIDを追加するなど、JSON パッチスキーマを使用して行うことができます。

import { NotificationHubsClient, JsonPatch } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const installationId = "<unique installation ID>";
const updates: JsonPatch[] = [
  { op: "add", path: "/tags", value: "likes_baseball" },
  { op: "add", path: "/userId", value: "bob@contoso.com" },
];

const installation = await client.updateInstallation(installationId, updates);

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
import { JsonPatch } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const installationId = "<unique installation ID>";

const updates: JsonPatch[] = [
  { op: "add", path: "/tags", value: "likes_baseball" },
  { op: "add", path: "/userId", value: "bob@contoso.com" },
];

const installation = await updateInstallation(context, installationId, updates);

既存のインストールを取得するには、既存の一意のインストール ID で getInstallation メソッドを使用します。

import { NotificationHubsClient } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const installationId = "<unique installation ID>";

const installation = client.getInstallation(installationId);

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, getInstallation } from "@azure/notification-hubs/api";

const context = createClientContext("<connection string>", "<hub name>");

const installationId = "<unique installation ID>";

const installation = getInstallation(context, installationId);

登録 API

登録は、上記のインストールと同様に、PNS の一意のデバイス識別子と関連するタグを使用して PNS に関連付けられます。 テンプレート登録は、事前定義された本文テンプレートを作成する方法であり、送信時にメッセージを埋めるプロパティを使用してカスタマイズできます。 テンプレートの詳細については、「 テンプレート」のドキュメントを参照してください。

インストールは、まず getInstallationId を使用してサーバーから登録 ID を取得し、次に createOrUpdateRegistration または createRegistration メソッドを使用して、次の 2 つの方法のいずれかで作成できます。

import {
  NotificationHubsClient,
  createAppleRegistrationDescription,
} from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const registration = createAppleRegistrationDescription({
  deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
  tags: ["likes_hockey", "likes_football"],
});
const updatedRegistration = await client.createRegistration(registration);

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, createRegistration } from "@azure/notification-hubs/api";
import { createAppleRegistrationDescription } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const registration = createAppleRegistrationDescription({
  deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
  tags: ["likes_hockey", "likes_football"],
});

const updatedRegistration = await createRegistration(context, registration);

更新は updateRegistration 方式で行うことができますが、インストールとは異なり、増分更新はサポートされていません。 既存の登録のクエリは、 getRegistration メソッドで実行できます。

import { NotificationHubsClient } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const registrationId = "<unique Registration ID>";

const registration = await client.getRegistration(registrationId);

if (registration.tags) {
  registration.tags.push("likes_sports");
} else {
  registration.tags = ["likes_sports"];
}

const updatedRegistration = await client.updateRegistration(registration);

モジュラーアプローチを使用すると、コードは次のようになります。

import {
  createClientContext,
  getRegistration,
  updateRegistration,
} from "@azure/notification-hubs/api";

const context = createClientContext("<connection string>", "<hub name>");

const registrationId = "<unique Registration ID>";

const registration = await getRegistration(context, registrationId);

if (registration.tags) {
  registration.tags.push("likes_sports");
} else {
  registration.tags = ["likes_sports"];
}

const updatedRegistration = await updateRegistration(context, registration);

登録は、インストールとは異なり、すべての登録を取得したり、登録を条件に照会したり、タグで照会したりできます。 登録は、 listRegistrationslistRegistrationsByChannellistRegistrationsByTag の方法を使用して照会できます。 すべてのメソッドは、 top オプションによる制限をサポートし、非同期ページングをサポートします。

import { NotificationHubsClient } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const registrations = client.listRegistrationsByTag("likes_hockey");

let page = 0;
for await (const pages of registrations.byPage()) {
  console.log(`Page number ${page++}`);
  for (const item of pages) {
    console.log(JSON.stringify(item, null, 2));
  }
}

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, listRegistrationsByTag } from "@azure/notification-hubs/api";

const context = createClientContext("<connection string>", "<hub name>");

const registrations = await listRegistrationsByTag(context, "likes_hockey");

let page = 0;
for await (const pages of registrations.byPage()) {
  console.log(`Page number ${page++}`);
  for (const item of pages) {
    console.log(JSON.stringify(item, null, 2));
  }
}

送信操作

Notification Hubs では、PNS が提供する一意の識別子を使用して直接、対象ユーザー送信用のタグを使用する、またはすべてのデバイスへの一般的なブロードキャストを使用して、デバイスへの通知の送信がサポートされています。 Standard SKU 以降を使用すると、 スケジュールされた送信 を使用すると、ユーザーは最大 7 日前に通知をスケジュールできます。 すべての送信操作は、Notification Hubs のサポート ケースに使用できる追跡 ID と関連付け ID を返します。 Standard SKU 以降では、 getNotificationOutcomeDetails メソッドを介して通知テレメトリを取得するために使用できる通知 ID も返されます。

デバッグの目的で、enableTestSend オプションを sendNotification メソッドの PNS から即時フィードバックを取得する true に設定できますが、運用シナリオではサポートされていません。 これは、スケジュールされた送信方法ではサポートされていません。

生の JSON または XML 文字列を送信またはスケジュールされた送信メソッドに送信することも、APNs、Firebase、Baidu、ADM、WNS などの PNS ごとのメッセージを構築するのに役立つ通知ビルダーを使用することもできます。 これらのビルダーはネイティブ メッセージ形式を構築するため、各 PNS で使用できるフィールドを推測することはありません。

import { createAppleNotificationBody, createAppleNotification } from "@azure/notification-hubs";

const apnsBody = createAppleNotificationBody({
  alert: {
    title: "Notification Title",
    subtitle: "Notification Subtitle",
    body: "Notification body goes here",
  },
  sound: "default",
  interruptionLevel: "time-sensitive",
});

// Send the message using the modular approach
const notification = createAppleNotification({
  body: apnsBody,
});

ブロードキャスト送信

Notification Hubs を使用すると、 sendBroadcastNotification メソッドによるブロードキャスト送信を使用して、プラットフォームごとに登録されているすべてのデバイスに通知を送信できます。

import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await client.sendBroadcastNotification(message);

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, sendBroadcastNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await sendBroadcastNotification(context, message);

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

ダイレクト送信

デバイスを直接送信するには、ユーザーは deviceHandle パラメーターを指定して sendNotification メソッドを呼び出して、APNs デバイス トークンなどのプラットフォームが提供する一意の識別子を使用して送信できます。

import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await client.sendNotification(message, { deviceHandle });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await sendNotification(context, message, { deviceHandle });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

オーディエンス送信

ユーザーは、1 つのデバイスをターゲットにするだけでなく、タグを使用して複数のデバイスをターゲットにすることもできます。 これらのタグは、タグのリストとして指定して、登録済みデバイスに一致するタグ式を作成するか、ブール ロジックを使用して適切なオーディエンスをターゲットにできるタグ式を介して指定できます。 タグとタグ式の詳細については、「 ルーティング式とタグ式」を参照してください。

タグの配列からタグ式を作成する場合は、トップレベルのインポートで公開される createTagExpression メソッド、またはタグから「またはタグ式」を作成するモジュラーインポートで使用できるタグ式ビルダー @azure/notification-hubs/models/tagExpressionBuilder があります。

import { createTagExpression } from "@azure/notification-hubs";

const tags = ["likes_football", "likes_hockey"];
const tagExpression = createTagExpression(tags);

console.log(tagExpression);

タグ式メッセージは、次のコードを使用して送信できます。

import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const notification = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await client.sendNotification(notification, { tagExpression });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const notification = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await sendNotification(context, notification, { tagExpression });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Only available in Standard SKU and above
if (result.notificationId) {
  console.log(`Notification ID: ${result.notificationId}`);
}

スケジュール送信

プッシュ通知は、標準 SKU 名前空間以上では、タグ付きのデバイスまたはscheduleBroadcastNotification付きの一般的なブロードキャストに送信するscheduleNotification方法を使用して、最大 7 日前にスケジュールできます。 これにより、通知 ID が返され、必要に応じて cancelScheduledNotification メソッドを使用してキャンセルできます。

import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

// Schedule 8 hours from now
const scheduledTime = new Date(Date.now() + 8 * 60 * 60 * 1000);

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await client.scheduleNotification(scheduledTime, message, { tagExpression });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Can be used to cancel via the cancelScheduledSend method
console.log(`Notification ID: ${result.notificationId}`);

モジュラーアプローチを使用すると、コードは次のようになります。

import { createClientContext, scheduleNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

// Schedule 8 hours from now
const scheduledTime = new Date(Date.now() + 8 * 60 * 60 * 1000);

const message = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await scheduleNotification(context, scheduledTime, message, { tagExpression });

console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);

// Can be used to cancel via the cancelScheduledSend method
console.log(`Notification ID: ${result.notificationId}`);

トラブルシューティング

React Native のサポート

React Native では、現在、Azure Notification Hubs SDK で使用される [URLSearchParams] はサポートされていません。 React NativeでSDKを使用するには、SDKを使用する前に url-search-params-polyfill パッケージをインストールしてインポートする必要があります。

また、 TextEncoder API と非同期イテレータ API のポリフィルも提供する必要があります。 詳細については、 Expo を使用した React Native サンプル を参照してください。

ドロップされた通知の診断

Azure Notification Hubs には、「 Azure Notification Hubs でドロップされた通知の診断ガイド」に、ドロップされた通知に関する問題のトラブルシューティングに関する完全なガイドがあります。

テスト送信 は、 sendNotification メソッドと sendBroadcastNotification メソッドでサポートされ、 enableTestSend オプションでサポートされています。

import { NotificationHubsClient, createAppleNotification } from "@azure/notification-hubs";

const client = new NotificationHubsClient("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const notification = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await client.sendNotification(notification, {
  tagExpression,
  enableTestSend: true,
});
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs";

const context = createClientContext("<connection string>", "<hub name>");

const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

const notification = createAppleNotification({
  body: messageBody,
  headers: {
    "apns-priority": "10",
    "apns-push-type": "alert",
  },
});

const result = await sendNotification(context, notification, {
  tagExpression,
  enableTestSend: true,
});

ロギング(記録)

ログ記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、AZURE_LOG_LEVEL 環境変数を infoに設定します。 または、setLogLevel@azure/logger を呼び出すことによって、実行時にログを有効にすることもできます。

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

ログを有効にする方法の詳細な手順については、 @azure/logger パッケージのドキュメントを参照してください。

次のステップ

次のサンプルは、Azure Notification Hubs と対話するさまざまな方法を示しています。

デバイス管理:

送信操作:

管理業務:

Contributing

このライブラリに投稿する場合は、コードをビルドしてテストする方法の詳細については、 投稿ガイド をお読みください。

このモジュールのテストは、ライブ テストと単体テストが混在しており、Azure Notification Hubs インスタンスが必要です。 テストを実行するには、次のコマンドを実行する必要があります。

  1. pnpm install
  2. pnpm build --filter @azure/notification-hubs...
  3. 次の内容を含む .env ファイルを sdk\notificationhubs\notification-hubs フォルダーに作成します。 NOTIFICATIONHUBS_CONNECTION_STRING=connection string for your Notification Hubs instanceNOTIFICATION_HUB_NAME=Notification Hub name
  4. cd sdk\notificationhubs\notification-hubs
  5. npm run test

詳細については、 テスト フォルダをご覧ください。