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
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-notification-hubs.md
+44-39Lines changed: 44 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,39 +1,40 @@
1
1
---
2
-
title: Notification Hubs bindings for Azure Functions
3
-
description: Understand how to use Azure Notification Hub binding in Azure Functions.
2
+
title: Azure Notification Hubs output bindings for Azure Functions
3
+
description: Learn how to use Azure Notification Hub output bindings in Azure Functions.
4
+
ms.service: azure-functions
4
5
ms.topic: reference
5
6
ms.devlang: csharp
7
+
ms.date: 06/24/2024
6
8
# ms.devlang: csharp, fsharp, javascript
7
9
ms.custom: devx-track-csharp
8
-
ms.date: 11/21/2017
9
10
---
10
11
11
-
# Notification Hubs output binding for Azure Functions
12
+
# Azure Notification Hubs output bindings for Azure Functions
12
13
13
14
This article explains how to send push notifications by using [Azure Notification Hubs](../notification-hubs/notification-hubs-push-notification-overview.md) bindings in Azure Functions. Azure Functions supports output bindings for Notification Hubs.
14
15
15
-
Azure Notification Hubs must be configured for the Platform Notifications Service (PNS) you want to use. To learn how to get push notifications in your client app from Notification Hubs, see [Getting started with Notification Hubs](../notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification.md) and select your target client platform from the drop-down list near the top of the page.
16
+
You must configure Notification Hubs for the Platform Notifications Service (PNS) you want to use. For more information about how to get push notifications in your client app from Notification Hubs, see [Quickstart: Set up push notifications in a notification hub](../notification-hubs/configure-notification-hub-portal-pns-settings.md).
16
17
17
18
> [!IMPORTANT]
18
-
> Google has [deprecated Google Cloud Messaging (GCM) in favor of Firebase Cloud Messaging (FCM)](https://developers.google.com/cloud-messaging/faq). This output binding doesn't support FCM. To send notifications using FCM, use the [Firebase API](https://firebase.google.com/docs/cloud-messaging/server#choosing-a-server-option) directly in your function or use [template notifications](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md).
19
+
> Google has [deprecated Google Cloud Messaging (GCM) in favor of Firebase Cloud Messaging (FCM)](https://developers.google.com/cloud-messaging/faq). However, output bindings for Notification Hubs doesn't support FCM. To send notifications using FCM, use the [Firebase API](https://firebase.google.com/docs/cloud-messaging/server#choosing-a-server-option) directly in your function or use [template notifications](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md).
The Notification Hubs bindings are provided in the [Microsoft.Azure.WebJobs.Extensions.NotificationHubs](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.NotificationHubs) NuGet package, version 1.x. Source code for the package is in the [azure-webjobs-sdk-extensions](https://github.com/Azure/azure-webjobs-sdk-extensions/tree/v2.x/src/WebJobs.Extensions.NotificationHubs) GitHub repository.
This binding is not available in Functions 2.x and higher.
31
+
Output binding isn't available in Functions 2.x and higher.
31
32
32
-
## Example - template
33
+
## Example: template
33
34
34
-
The notifications you send can be native notifications or [template notifications](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md). Native notifications target a specific client platform as configured in the `platform` property of the output binding. A template notification can be used to target multiple platforms.
35
+
The notifications you send can be native notifications or [template notifications](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md). A native notification targets a specific client platform, as configured in the `platform` property of the output binding. A template notification can be used to target multiple platforms.
35
36
36
-
See the language-specific example:
37
+
Template examples for each language:
37
38
38
39
*[C# script - out parameter](#c-script-template-example---out-parameter)
@@ -42,7 +43,7 @@ See the language-specific example:
42
43
*[F#](#f-template-example)
43
44
*[JavaScript](#javascript-template-example)
44
45
45
-
### C# script template example - out parameter
46
+
### C# script template example: out parameter
46
47
47
48
This example sends a notification for a [template registration](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md) that contains a `message` placeholder in the template.
If you are using asynchronous code, out parameters are not allowed. In this case use `IAsyncCollector` to return your template notification. The following code is an asynchronous example of the code above.
71
+
If you're using asynchronous code, out parameters aren't allowed. In this case, use `IAsyncCollector` to return your template notification. The following code is an asynchronous example of the previous example.
This example sends a notification for a [template registration](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md) that contains a `message` placeholder in the template using a valid JSON string.
96
97
@@ -104,9 +105,9 @@ public static void Run(string myQueueItem, out string notification, TraceWriter
104
105
}
105
106
```
106
107
107
-
### C# script template example - library types
108
+
### C# script template example: library types
108
109
109
-
This example shows how to use types defined in the [Microsoft Azure Notification Hubs Library](https://www.nuget.org/packages/Microsoft.Azure.NotificationHubs/).
110
+
This example shows how to use types defined in the [Microsoft Azure Notification Hubs Library](https://www.nuget.org/packages/Microsoft.Azure.NotificationHubs/).
This C# script example shows how to send a native APNS notification.
164
+
This C# script example shows how to send a native Apple Push Notification Service (APNS) notification:
164
165
165
166
```cs
166
167
#r"Microsoft.Azure.NotificationHubs"
@@ -177,7 +178,7 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
177
178
// In this example the queue item is a new user to be processed in the form of a JSON string with
178
179
// a "name" value.
179
180
//
180
-
// The JSON format for a native APNS notification is ...
181
+
// The JSON format for a native Apple Push Notification Service (APNS) notification is:
181
182
// { "aps": { "alert": "notification message" }}
182
183
183
184
log.LogInformation($"Sending APNS notification of a new user");
@@ -189,9 +190,9 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
189
190
}
190
191
```
191
192
192
-
## Example - WNS native
193
+
## Example: WNS native
193
194
194
-
This C# script example shows how to use types defined in the [Microsoft Azure Notification Hubs Library](https://www.nuget.org/packages/Microsoft.Azure.NotificationHubs/) to send a native WNS toast notification.
195
+
This C# script example shows how to use types defined in the [Microsoft Azure Notification Hubs Library](https://www.nuget.org/packages/Microsoft.Azure.NotificationHubs/) to send a native Windows Push Notification Service (WNS) toast notification:
195
196
196
197
```cs
197
198
#r"Microsoft.Azure.NotificationHubs"
@@ -236,21 +237,21 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
236
237
237
238
In [C# class libraries](functions-dotnet-class-library.md), use the [NotificationHub](https://github.com/Azure/azure-webjobs-sdk-extensions/blob/v2.x/src/WebJobs.Extensions.NotificationHubs/NotificationHubAttribute.cs) attribute.
238
239
239
-
The attribute's constructor parameters and properties are described in the [configuration](#configuration) section.
240
+
The attribute's constructor parameters and properties are described in the [Configuration](#configuration) section.
240
241
241
242
## Configuration
242
243
243
-
The following table explains the binding configuration properties that you set in the *function.json* file and the `NotificationHub` attribute:
244
+
The following table lists the binding configuration properties that you set in the *function.json* file and the `NotificationHub` attribute:
|**name**|n/a| Variable name used in function code for the notification hub message. |
250
-
|**tagExpression**|**TagExpression**| Tag expressions allow you to specify that notifications be delivered to a set of devices that have registered to receive notifications that match the tag expression. For more information, see [Routing and tag expressions](../notification-hubs/notification-hubs-tags-segment-push-message.md). |
251
-
|**hubName**|**HubName**|Name of the notification hub resource in the Azure portal. |
252
-
|**connection**|**ConnectionStringSetting**| The name of an app setting that contains a Notification Hubs connection string. The connection string must be set to the *DefaultFullSharedAccessSignature* value for your notification hub. See [Connection string setup](#connection-string-setup) later in this article.|
253
-
|**platform** | **Platform** | The platform property indicates the client platform your notification targets. By default, if the platform property is omitted from the output binding, template notifications can be used to target any platform configured on the Azure Notification Hub. For more information on using templates in general to send cross platform notifications with an Azure Notification Hub, see [Templates](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md). When set, **platform** must be one of the following values: <ul><li><code>apns</code>—Apple Push Notification Service. For more information on configuring the notification hub for APNS and receiving the notification in a client app, see [Sending push notifications to iOS with Azure Notification Hubs](../notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started.md).</li><li><code>adm</code>—[Amazon Device Messaging](https://developer.amazon.com/device-messaging). For more information on configuring the notification hub for ADM and receiving the notification in a Kindle app, see [Getting Started with Notification Hubs for Kindle apps](../notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started.md).</li><li><code>wns</code>—[Windows Push Notification Services](/windows/uwp/design/shell/tiles-and-notifications/windows-push-notification-services--wns--overview) targeting Windows platforms. Windows Phone 8.1 and later is also supported by WNS. For more information, see [Getting started with Notification Hubs for Windows Universal Platform Apps](../notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification.md).</li><li><code>mpns</code>—[Microsoft Push Notification Service](/previous-versions/windows/apps/ff402558(v=vs.105)). This platform supports Windows Phone 8 and earlier Windows Phone platforms. For more information, see [Sending push notifications with Azure Notification Hubs on Windows Phone](../notification-hubs/notification-hubs-windows-mobile-push-notifications-mpns.md).</li></ul> |
251
+
|**tagExpression**|**TagExpression**| Tag expressions allow you to specify that notifications be delivered to a set of devices that are registered to receive notifications matching the tag expression. For more information, see [Routing and tag expressions](../notification-hubs/notification-hubs-tags-segment-push-message.md). |
252
+
|**hubName**|**HubName**|The name of the notification hub resource in the Azure portal. |
253
+
|**connection**|**ConnectionStringSetting**| The name of an app setting that contains a Notification Hubs connection string. Set the connection string to the *DefaultFullSharedAccessSignature* value for your notification hub. For more information, see [Connection string setup](#connection-string-setup). |
254
+
|**platform** | **Platform** | The platform property indicates the client platform your notification targets. By default, if the platform property is omitted from the output binding, template notifications can be used to target any platform configured on the Azure Notification Hub. For more information about using templates to send cross-platform notifications with an Azure Notification Hub, see [Templates](../notification-hubs/notification-hubs-templates-cross-platform-push-messages.md). When **platform** is set, it must be one of the following values: <ul><li><code>apns</code>: Apple Push Notification Service. For more information on configuring the notification hub for APNS and receiving the notification in a client app, see [Send push notifications to iOS with Azure Notification Hubs](../notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started.md).</li><li><code>adm</code>: [Amazon Device Messaging](https://developer.amazon.com/device-messaging). For more information on configuring the notification hub for Azure Deployment Manager (ADM) and receiving the notification in a Kindle app, see [Send push notifications to Android devices using Firebase SDK](../notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started.md).</li><li><code>wns</code>: [Windows Push Notification Services](/windows/uwp/design/shell/tiles-and-notifications/windows-push-notification-services--wns--overview) targeting Windows platforms. WNS also supports Windows Phone 8.1 and later. For more information, see [Send notifications to Universal Windows Platform apps using Azure Notification Hubs](../notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification.md).</li><li><code>mpns</code>: [Microsoft Push Notification Service](/previous-versions/windows/apps/ff402558(v=vs.105)). This platform supports Windows Phone 8 and earlier Windows Phone platforms. For more information, see [Send notifications to Universal Windows Platform apps using Azure Notification Hubs](../notification-hubs/notification-hubs-windows-mobile-push-notifications-mpns.md).</li></ul> |
254
255
255
256
[!INCLUDE [app settings to local.settings.json](../../includes/functions-app-settings-local.md)]
256
257
@@ -277,15 +278,20 @@ Here's an example of a Notification Hubs binding in a *function.json* file.
277
278
278
279
### Connection string setup
279
280
280
-
To use a notification hub output binding, you must configure the connection string for the hub. You can select an existing notification hub or create a new one right from the *Integrate* tab in the Azure portal. You can also configure the connection string manually.
281
+
To use a notification hub output binding, you must configure the connection string for the hub. You can select an existing notification hub or create a new one right from the **Integrate** tab in the Azure portal. You can also configure the connection string manually.
281
282
282
283
To configure the connection string to an existing notification hub:
283
284
284
-
1. Navigate to your notification hub in the [Azure portal](https://portal.azure.com), choose **Access policies**, and select the copy button next to the **DefaultFullSharedAccessSignature** policy. This copies the connection string for the *DefaultFullSharedAccessSignature* policy to your notification hub. This connection string lets your function send notification messages to the hub.
285
-

286
-
1. Navigate to your function app in the Azure portal, choose **Application settings**, add a key such as **MyHubConnectionString**, paste the copied *DefaultFullSharedAccessSignature* for your notification hub as the value, and then click **Save**.
285
+
1. Navigate to your notification hub in the [Azure portal](https://portal.azure.com), choose **Access policies**, and select the copy button next to the **DefaultFullSharedAccessSignature** policy.
287
286
288
-
The name of this application setting is what goes in the output binding connection setting in *function.json* or the .NET attribute. See the [Configuration section](#configuration) earlier in this article.
287
+
The connection string for the *DefaultFullSharedAccessSignature* policy is copied to your notification hub. This connection string lets your function send notification messages to the hub.
288
+

289
+
290
+
1. Navigate to your function app in the Azure portal, expand **Settings**, and then select **Environment variables**.
291
+
292
+
1. From the **App setting** tab, select **+ Add** to add a key such as **MyHubConnectionString**. The name of this app setting is the output binding connection setting in *function.json* or the .NET attribute. For more information, see [Configuration](#configuration).
293
+
294
+
1. For the value, paste the copied *DefaultFullSharedAccessSignature* connection string from your notification hub, and then select **Apply**.
289
295
290
296
[!INCLUDE [app settings to local.settings.json](../../includes/functions-app-settings-local.md)]
291
297
@@ -295,7 +301,6 @@ The name of this application setting is what goes in the output binding connecti
0 commit comments