簡體   English   中英

Azure功能:向特定用戶發送通知

[英]Azure function: send notification to specific users

我編寫了一個Azure功能,並將輸出連接到通知中心,以使用APNS發送推送通知。 只要我將通知發送到所有已注冊的設備,它就可以正常工作,但我不知道如何使用標簽來解決特定用戶的問題。 如果我嘗試使用標記,我會收到一條錯誤消息,說“執行函數時出現異常:Functions.SendSinglePushNotification。Microsoft.Azure.WebJobs.Host:函數返回后處理參數通知時出錯:Microsoft.Azure.NotificationHubs:notification。標簽屬性應為null。“

到目前為止,這是我的代碼:

#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); 
}

我試圖使用notification = new
AppleNotification(apnsNotificationPayload,tagExpression); 但這不起作用。 我怎樣才能實現這一目標?

非常感謝和最誠摯的問候

我有類似的問題。 最終,對我有用的是手動構建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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM