Reputation: 3457
I am trying to send a Push Notification with a text that says "Email Read" to individual users when the email they send through my Android App is read.
I send the emails through SendGrid API,and I have setup an Azure Function webhook endpoint that gets called when the email is read.
I can attach a Notification Hub registration Id and a GCM Token to the emails which gets passed back to me via the webhook.
Armed with the GCM Token, I know the device/individual I want to send the notification to, my challenge now is how do I call Azure Notification Hub to target individual user?
Currently Azure Function only support Notification Hub binding with Templating, and that brings me to yet another challenge, how can I register for Azure notification hub from Android device using an installation?
Upvotes: 0
Views: 2287
Reputation: 726
tagExpression in NotificationHub is dynamic. Please see Configuring notification tag for Azure Function for more details. Also, Azure functions now supports sending notificaitons to GCM registrations. You need to set the Notification Platform on the Binding to GCM.
Here is a sample for sending WNS push notification to a dynamic tag that comes in as queueTrigger:
function.json
{
"bindings": [
{
"name": "myQueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "test-queue",
"connection": "AzureWebJobsDashboard"
},
{
"type": "notificationHub",
"name": "notification",
"hubName": "youthubname",
"connection": "NOTIFICATIONHUB_AppSettingName",
"direction": "out",
"tagExpression": "{userIdTag}",
"platform": "wns"
}
],
"disabled": false
}
C# QueueTrigger:
using System;
public static void Run(PushToTag myQueueItem, TraceWriter log, out string notification)
{
log.Info($"C# Queue trigger function processed: {myQueueItem.UserIdTag}");
notification = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">Test message</text></binding></visual></toast>";
}
public class PushToTag
{
public string UserIdTag { get; set; }
public string UserName { get; set; }
}
Sample Queue Data
{"UserIdTag":"tag1" , "UserName":"joe"}
Note: tag1 is the tag registered by the client
You can send GCM notifications by selecting GCM in Notification Platform.
Upvotes: 1
Reputation: 25080
@Nikita G. guides correctly in overall.
I'd like to append implementation level knowledge.
Each individual can be managed by tag
in Notification Hub as user can use multiple devices. Azure Notification Hub tag system is suitable to send a push for this situation. So, you could attach a tag like user:34939
to identify user (not to identify device).
For this reason, you should think that your requirement is to identify device
or to identiy user
. Whatever cases, GCM token does not have to be attached to email link. Only tag value (userid) is enough to identify user or only Hub registration id is enough to identify device. The Hub registration id helps to manage registered devices regardless of APNS or GCM token.
About template, yes. Template is required during registration.
FYI, tag has 120 character length limits. https://stackoverflow.com/a/21199385/361100
Upvotes: 1
Reputation: 7503
I haven't tried this myself, but here's what I think you would need:
Refer to Registration management post for more information about installation model.
Upvotes: 1