Sending notification to specific device using Azure Notification Hub (Test Send) - azure

I'm trying to send a notification to my Android device using Azure Notification Hub.
When I use the Test Send functionality which is available in Azure Notification Hub it doesn't seem to care about the property "to" in the payload.
For example if I specify a fake deviceId like below I still receive a notification on my device.
{
"to" : "fW4Xab4JY3F:ERT91bHC4_hqzGj4AaHB_u1Dvzai6hFxyHFscgQ_TRAqWD1JGsE7FqFmknSuwlCEImmyn9R1gCDpsObZk33mpqaqdhWC_712AW2PI47ni15Jyrwq12xcSs9tZ784sLabz2I64J2LSe4q",
"notification": {
"title": "TITel",
"body": "Firebase Cloud Message"
}
}
If I do the same using Postman and calls the server side API of FCM I get a response saying InvalidRegistration if I enter a fake deviceId. And if I use a correct deviceId I get the notification as expected.
Anyone knows why the payload isn't working as I would expect it to within Azure Notification Hub?

Test Send is for testing only. The way it works is it sends notifications to 10 random devices. I guess the reason why it works for you from NH is probably because you have a few devices (or maybe even just 1 device) so all of them get notifications.
The reason why it doesn't work with FCM is because, as you mentioned, this is a fake ID. If you use an existing one, it should work.

Related

Azure Notification Hub not sending notifications randomly

For a few weeks there is an issue with Azure Notification Hub - we have a backend service that registers devices & schedules notifications. When one of the notifications is triggered, then we send it to Azure based on the device type (create the payload and all of that).
The response we get from azure is positive, the notification has been enqueued and is ready to be sent. However, it seems that Azure does not send them all. No error is thrown but only a small percentage is sent. It also does not seem to depend on the device type.
There are no logs to read - or none tha I can find and I cannot pin point the issue.
We have an endpoint that triggers the sending of a notification - we did a test run with 30 notifications (similar and different payloads for the same device) and it all went well.
Not sure how to troubleshoot this or what might cause this. I understood from the documentation that the device might be inactive and then the notification is deleted from the queue after a while. But it seems that the said device receives 1 out of 3 notifications (sent at the same time).
Any feedback would be appreciated.
Edit update:
After upgrading to the Standard plan, we managed to get some more information and it looks like Azure gives back a "Success" with a count of "1" but the device does not receive the notification - the problem is, this happens randomly. It's not always the same device that does or does not receive the notification.
Sorry this isn't a super helpful answer, but could you please open a support ticket in the Azure Portal for us to investigate your particular case? This does not seem like expected behavior so the team will have to look into the logs for your namespace and hub.
One immediate thought - there is de-duplication logic when sending notifications. So within a period of time (something like 15 minutes) if the same notification payload is being sent to the same device, Notification Hubs will automatically drop that duplicate notification.

Payload for sending push notifications to Windows 10 (mobile) devices with Azure notifcation hub

What is the payload to send push notification to Windows 10 (mobile) devices without showing a message to the user (silent push)? All i need to deliver within the push is a custom parameter.
Check out whether X-WNS-SuppressPopup header in Push notification service request and response headers works for you:
X-WNS-SuppressPopup
For Windows Phone Store apps, you have the
option to suppress a toast notification's UI, instead sending the
notification directly to the action center. This lets your
notification be delivered silently, a potentially superior option for
less urgent notifications. This header is optional and only used on
Windows Phone channels. If you include this header on a Windows
channel, your notification will be dropped and you will receive an
error response from WNS.

Azure Iot Rest API Message from cloud to device

Get : https://myiot.azure-devices.net/devices/mydevice/messages/devicebound?api-version=2016-02-03
Authorization: SAS key
i am getting 204 No content response from above api while receiving message using postman request maker from cloud to device.When i send messages from device to cloud it is appearing in my iot hub but giving error 204 while receiving messages from cloud.
First, if you haven't sent Cloud-To-Device messages and you get No content response(error code:204) from calling the GET api(https://myiot.azure-devices.net/devices/mydevice/messages/devicebound?api-version=2016-02-03). It is expected. It means the server has fulfilled the request, but there is no new information to send back.
Second, you want to receive the Device-To-Cloud message you have sent. It is unreachable. Because this GET api is used to receive Cloud-To-Device messages.
In short, Device-To-Cloud and Cloud-To-Device are different messaging primitives that Azure IoT hub provides to communicate with a device. And Device-To-Device communication that you want is not supported natively with Azure IoT Hub.
Finally, how to send Cloud-To-Device message?
For test purpose, you can send Cloud-To-Device message from Device Explorer. More detailed information you can reference here.
Yes, you can send cloud-to-device message
POST : https://[iotHubName].azure-devices.net/devices/[deviceId]/messages/deviceBound?api-version=2020-09-30
Header must include Authorization like :
SharedAccessSignature sr=webchatIOTHub.azure-devices.net&sig=lc7seNnczkq7Xj0IDSdFHshTTHEJUDt4y98e9Eoj%2B18%3D&se=1655587178&skn=iothubowner
For SAS (sharedAccessSignature) you have to run PowerShell CLI :
az iot hub generate-sas-token -n [iotHubName]--du 3600000000
Also, you can view the RestAPI when you use the browser to send message to device
enter image description here

Azure Notification Hub: How to view per message telemetry?

On the pricing page for Azure Notification Hubs:
https://azure.microsoft.com/en-us/pricing/details/notification-hubs/
It states that "Standard namespaces have access to Per Message Telemetry and Push Notification Services Feedback". I am using a Standard namespace.
The app is sending template based notifications to an iOS app from my back end using the C# Notification Hub client. For example:
NotificationOutcome result = await hub.SendTemplateNotificationAsync(params, tags);
The result.State is coming back as Enqueued, but some notifications are not being delivered and I am trying to figure out why. (There are no bad registrations in the hub - I have already checked that.)
In the Azure portal, I can see aggregate metrics of messages received by the hub, errors, etc. - but I cannot seem to view the specific results of a push message to determine why it failed to reach the device, or even if it was successfully handed off to APNS.
How can I see the results of an attempted push? Is this even possible with Azure Notification Hubs?
Did you try Fiddler+https://msdn.microsoft.com/en-us/library/azure/mt608135.aspx ?
Also, as far as i know, Apple does not guarantee the delivery of all notifications.
1) Is Apple's push notification service reliable?
More of that,
2) https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-faq/
"A PNS does not guarantee any SLA for delivering notifications; however, typically a vast majority of push notifications are delivered to target devices within a few minutes (usually within the limits of 10 minutes) from the time they are sent to our platform. "

Create single push notification channel for multiple apps

For sending and receiving push notifications I want to register all my apps to the push channel with:
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
I can now send and recieve pushes over this channel.
The problem is that this channel is only valid for one app. If I install the same app on another device I only receive the message on the same device as I sent it.
How can I push the notification to all my devices?
The push channel is unique for each app installation. You can only use it to send a push to this one installation. If you want to send push to all the devices running your app, you have to collect the push channel info somewhere (your server, etc.) or you can use a service like https://parse.com/ that offer targeting multiple devices at once.
Are you trying to install the same debug-based app on more than one device?
I believe that the channel is based on some identity of the app, so try to release it and I prefer you to create a store-based hidden app and test it..
The code you're writing is OK with millions of devices :)
According to this article,
Devices can specify one or more tags when registering with a Notification Hub, These tags don’t need to be pre-provisioned or disposed, and provide a very easy way for apps to send targeted notifications to millions of devices with a single API call, without you having to implement your own per-device notification routing infrastructure - https://blogs.windows.com/buildingapps/2013/09/16/delivering-push-notifications-to-millions-of-devices-with-windows-azure-notification-hubs/#mQppyhpwaEAcMehc.97
In your Windows Store app, using the Windows Store device SDK, you can register to your Notification Hub simply calling
await hub.RegisterNativeAsync(channel.Uri, new string[] { "myTag", "myOtherTag" });
And then you can have your .NET backend broadcast a message to all your clients, just by calling
var toast = #"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello everybody!</text></binding></visual></toast>";
await hub.SendWindowsNativeNotificationAsync(toast);

Resources