Skip to content

Commit f289a02

Browse files
committed
Initial refresh of article
1 parent ac9b8da commit f289a02

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

articles/azure-functions/functions-bindings-notification-hubs.md

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
---
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
45
ms.topic: reference
56
ms.devlang: csharp
7+
ms.date: 06/24/2024
68
# ms.devlang: csharp, fsharp, javascript
79
ms.custom: devx-track-csharp
8-
ms.date: 11/21/2017
910
---
1011

11-
# Notification Hubs output binding for Azure Functions
12+
# Azure Notification Hubs output bindings for Azure Functions
1213

1314
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.
1415

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).
1617

1718
> [!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).
1920
20-
## Packages - Functions 1.x
21+
## Packages: Functions 1.x
2122

2223
[!INCLUDE [functions-runtime-1x-retirement-note](../../includes/functions-runtime-1x-retirement-note.md)]
2324

2425
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.
2526

2627
[!INCLUDE [functions-package](../../includes/functions-package.md)]
2728

28-
## Packages - Functions 2.x and higher
29+
## Packages: Functions 2.x and higher
2930

30-
This binding is not available in Functions 2.x and higher.
31+
Output binding isn't available in Functions 2.x and higher.
3132

32-
## Example - template
33+
## Example: template
3334

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.
3536

36-
See the language-specific example:
37+
Template examples for each language:
3738

3839
* [C# script - out parameter](#c-script-template-example---out-parameter)
3940
* [C# script - asynchronous](#c-script-template-example---asynchronous)
@@ -42,7 +43,7 @@ See the language-specific example:
4243
* [F#](#f-template-example)
4344
* [JavaScript](#javascript-template-example)
4445

45-
### C# script template example - out parameter
46+
### C# script template example: out parameter
4647

4748
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.
4849

@@ -65,9 +66,9 @@ private static IDictionary<string, string> GetTemplateProperties(string message)
6566
}
6667
```
6768

68-
### C# script template example - asynchronous
69+
### C# script template example: asynchronous
6970

70-
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.
7172

7273
```cs
7374
using System;
@@ -90,7 +91,7 @@ private static IDictionary<string, string> GetTemplateProperties(string message)
9091
}
9192
```
9293

93-
### C# script template example - JSON
94+
### C# script template example: JSON
9495

9596
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.
9697

@@ -104,9 +105,9 @@ public static void Run(string myQueueItem, out string notification, TraceWriter
104105
}
105106
```
106107

107-
### C# script template example - library types
108+
### C# script template example: library types
108109

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/).
110111

111112
```cs
112113
#r "Microsoft.Azure.NotificationHubs"
@@ -158,9 +159,9 @@ module.exports = async function (context, myTimer) {
158159
};
159160
```
160161

161-
## Example - APNS native
162+
## Example: APNS native
162163

163-
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:
164165

165166
```cs
166167
#r "Microsoft.Azure.NotificationHubs"
@@ -177,7 +178,7 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
177178
// In this example the queue item is a new user to be processed in the form of a JSON string with
178179
// a "name" value.
179180
//
180-
// The JSON format for a native APNS notification is ...
181+
// The JSON format for a native Apple Push Notification Service (APNS) notification is:
181182
// { "aps": { "alert": "notification message" }}
182183
183184
log.LogInformation($"Sending APNS notification of a new user");
@@ -189,9 +190,9 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
189190
}
190191
```
191192

192-
## Example - WNS native
193+
## Example: WNS native
193194

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:
195196

196197
```cs
197198
#r "Microsoft.Azure.NotificationHubs"
@@ -236,21 +237,21 @@ public static async Task Run(string myQueueItem, IAsyncCollector<Notification> n
236237

237238
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.
238239

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.
240241

241242
## Configuration
242243

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:
244245

245246
|function.json property | Attribute property |Description|
246247
|---------|---------|----------------------|
247-
|**type** |n/a| Must be set to `notificationHub`. |
248-
|**direction** |n/a| Must be set to `out`. |
248+
|**type** |n/a| Set to `notificationHub`. |
249+
|**direction** |n/a| Set to `out`. |
249250
|**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>&mdash;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>&mdash;[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>&mdash;[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>&mdash;[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> |
254255

255256
[!INCLUDE [app settings to local.settings.json](../../includes/functions-app-settings-local.md)]
256257

@@ -277,15 +278,20 @@ Here's an example of a Notification Hubs binding in a *function.json* file.
277278

278279
### Connection string setup
279280

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.
281282

282283
To configure the connection string to an existing notification hub:
283284

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-
![Copy the notification hub connection string](./media/functions-bindings-notification-hubs/get-notification-hub-connection.png)
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.
287286

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+
![Screenshot that shows how to copy the notification hub connection string.](./media/functions-bindings-notification-hubs/get-notification-hub-connection.png)
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**.
289295

290296
[!INCLUDE [app settings to local.settings.json](../../includes/functions-app-settings-local.md)]
291297

@@ -295,7 +301,6 @@ The name of this application setting is what goes in the output binding connecti
295301
|---|---|
296302
| Notification Hub | [Operations Guide](/rest/api/notificationhubs/) |
297303

298-
## Next steps
304+
## Related content
299305

300-
> [!div class="nextstepaction"]
301-
> [Learn more about Azure functions triggers and bindings](functions-triggers-bindings.md)
306+
* [Azure Functions triggers and bindings concepts](functions-triggers-bindings.md)

includes/functions-package.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
author: ggailey777
33
ms.service: azure-functions
44
ms.topic: include
5-
ms.date: 03/20/2022
5+
ms.date: 06/24/2024
66
ms.author: glenga
77
ms.custom: include file
88
---
99

10-
The following table tells how to add support for this binding in each development environment.
10+
The following table lists how to add support for output binding in each development environment.
1111

12-
| Development environment | To add support in <br>Functions 1.x |
13-
|----------------------|----------------|
14-
|Local development - C# class library | [Install the package](../articles/azure-functions/functions-develop-vs.md#add-bindings) |
15-
|Local development - C# script, JavaScript, F# |Automatic |
16-
|Portal development| Automatic |
12+
| Development environment | To add support in Functions 1.x |
13+
|-------------------------|----------------------------------|
14+
| Local development: C# class library | [Install the package](../articles/azure-functions/functions-develop-vs.md#add-bindings) |
15+
| Local development: C# script, JavaScript, F# | Automatic |
16+
| Portal development | Automatic |

0 commit comments

Comments
 (0)