Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] How to send a notification to a single user/device #138

Open
2 tasks done
eric-labelle opened this issue Sep 28, 2020 · 8 comments
Open
2 tasks done

[QUERY] How to send a notification to a single user/device #138

eric-labelle opened this issue Sep 28, 2020 · 8 comments
Labels

Comments

@eric-labelle
Copy link

Query/Question
Using the method NotificationHub.setUserId() from the Android sdk, how can we send a notification from the Azure Console to that user? There's only a "Send to Tag Expression" field but using the userId there won't work obviously. Just curious what this setUserId is used for if there is no way to send a push notification to only this user.

On an additional note, it would also be useful to be able to send a notif directly to the pushChannel (which is kind of the pushToken from what I understand in ANH)
Also, is there a way to see registered devices/users/tags in the console? can't find this anywhere.

Setup (please complete the following information if applicable):

  • OS: Android 11
  • IDE : Android Studio 4.2
  • Version of the Library used: 1.1.1

Information Checklist

  • Query Added
  • Setup information Added
@mpodwysocki
Copy link
Contributor

@eric-labelle I'll update the documentation for the SDK to be more in line with the Apple SDK which has this information.

To target a user, use the tag $UserId:{VALUE} where VALUE is the user ID you are targeting. This is also true of InstallationId which can be targeted using $InstallationId:{VALUE}.

To target the push channel directly, use the Direct Send capability of Azure Notification Hubs with the given device token.

@eric-labelle
Copy link
Author

oh wow, ok! never would have guess this one for userId. Thanks

For the Direct Send, that's not in the Azure Portal, only through REST API? There is only a "Test Send" button in the Azure portal.

@mpodwysocki
Copy link
Contributor

mpodwysocki commented Oct 2, 2020

@eric-labelle correct, Direct Send is through the REST API directly. The portal is just using the normal targeted send. You can, however, if you know the Installation ID, target it that way through the portal

@eric-labelle
Copy link
Author

@mpodwysocki I just tested both. Works well. Im curious though what is the RegistrationId column in the "Test Send" result table from the Azure Portal? Can't seem to get this value from ANH sdk (only have the pushChannel which seems to be the FCM token, and the InstallationId). Just don't get why sometime it send message to multiple registrationId when It should have targetted only one device.

@frankfuu
Copy link

frankfuu commented Mar 7, 2022

@mpodwysocki are you able to send to a group of users using $UserId:{VALUE} method? If so, any idea how? or where we can lookup expression building examples in their docs?

@ljunquera
Copy link

I my payload looks like this:
var notification = "{\"aps\":{\"alert\":\"Test alert!\"}}";

where does $UserId:{VALUE} go? And I assume we have to MSNotificationHub.setUserId(userId); on the iOS side, correct?

@aziztitu
Copy link
Contributor

@frankfuu Yes, you can set the same userId when registering those devices, and if you send a notification with the tag "$UserId:{VALUE}", the notification will be sent to all those devices.

Note that conceptually, UserID is meant to be used as an identifier for all the devices that belong to a single user. So a better way to send a notification to a group of users would be to add a unique group tag when registering the devices that belong to a group. And then, when sending a notification, you can specify the group tag that you want to target for that notification.

More info on using Tags with ANH: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-tags-segment-push-message

@aziztitu
Copy link
Contributor

@ljunquera You will need to provide $UserId:{VALUE} as the Tag when sending the notification.

More info on using Tags with ANH: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-tags-segment-push-message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants