Azure Feature: Send Notifications to Specific Users

I wrote an Azure function and connected the output to the notification hub to send push notifications using APNS. It works fine while I send a notification to all registered devices, but I don’t know how to use tags to refer to a specific user. If I try to use a tag, I get the error message "Exception when executing function: Functions.SendSinglePushNotification. Microsoft.Azure.WebJobs.Host: Error processing parameter notification after function return: Microsoft.Azure.NotificationHubs: notification. Tag property must be zero.

Here is my code:

#r "Microsoft.Azure.NotificationHubs"
#r "Newtonsoft.Json"


using System;
using Microsoft.Azure.NotificationHubs;
using Newtonsoft.Json;using         
Microsoft.Azure.WebJobs.Host.Bindings.Runtime;

public static void Run(HttpRequestMessage req, TraceWriter log,Binder     
binder, out AppleNotification notification)
{
    string user = "Test";
    string tagExpression = "Test";
    string userTag = req.GetQueryNameValuePairs()
    .FirstOrDefault(q => string.Compare(q.Key, "userid", true) == 0)
    .Value;

    string apnsNotificationPayload = "{\"aps\": {\"alert\": \"Test: (" + user + ")\" }}";
    notification = new AppleNotification(apnsNotificationPayload); 
}

=
  AppleNotification (apnsNotificationPayload, tagExpression); . ?

+4
1

. , , , Notification . Visual Studio, .

    [FunctionName("MyFunction")]
    public static async Task Run([ServiceBusTrigger("queuename", AccessRights.Listen, Connection =
    "<connection-settings-name>")] string myQueueItem, TraceWriter log)
{
    log.Info($"C# Queue trigger function processed: {myQueueItem}");

    var notificationHubSas = "<DefaultFullSharedAccessSignature from Azure portal>";
    var notificationHubName = "myhub";
    var nhClient = NotificationHubClient.CreateClientFromConnectionString(notificationHubSas, notificationHubName);
    var tags = "";
    await nhClient.SendTemplateNotificationAsync(<notification payload>, tags);
}
0

Source: https://habr.com/ru/post/1672961/


All Articles