I’m trying to figure out how to use Azure Notification Hub. After reading the documentation 10 times I’m still not able to send any succesful template notifications with .Net and the Microsoft.Azure.NotificationHubs
nuget package.
I’ve created a test registration with an API (it’s not a real device, I’ve sent some random data to notification hub, but the message template is something that should be valid).
Sending a notification with method SendTemplateNotificationAsync
of NotificationHubClient
results in PayloadErrors visible on the chart in the Azure Portal. Unfortunately I don’t feel like paying 300$ for upgrading my free tier NotificationHub just to debug a problem before going on prod with my system. Maybe some of you will see what is wrong with my request or registration?
- Template Request screenshot
I register the device using the method CreateFcmV1TemplateRegistrationAsync
:
// the foreach loops are irrevelant to the topic
private async Task RegisterAndroidDevice(RegisterDeviceCommand command)
{
var tasks = new List<Task>();
foreach (var template in command.Templates)
{
foreach (var districtId in command.DistrictIds)
{
tasks.Add(notificationHubClient.CreateFcmV1TemplateRegistrationAsync(command.InstallationId, template.Value, new List<string>() { $"{districtId}_{template.Key}" }));
}
}
await Task.WhenAll(tasks);
}
where the value is {"message":{"title":"$(title)", "description":"$(description)"}}
as can be seen in this Registration that exists in Notification Hub screenshot.
The SendTemplateNotificationAsync
method does not return any error. The response says that the message was enqueued but after a few minutes I can see on the metrics chart in the AZ portal that messages have failed to be processed with payload errors. Unfortunately detailed error details are accessible only with premium tier.
Below you can see how I call the SendTemplateNotificationAsync
method:
var outcome = await notificationHubClient.SendTemplateNotificationAsync(parameters, $"{districtId}_{type}");
Where parameters
object is a key-value pair like:
{
"alertType" : "Weather"
"title" : "Test alert 2"
"description" : "Content of test alert"
}
peper1998 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3