I want to build a menu notification with SignalR 2 in my MVC app.
So, when some user do a specific action, some others users (not all and not the same every time) must be notified. Some like the SO notification when somebody answer a question.
Do I should store the connectionId in a database to know who must be notified after the action is triggered? What would you do?
I had to do something similar and this is what I did:
1) Define notification types based on user roles. Each notification type had a list of specific recipients. That way I knew if a notification type was created I had to notify certain users.
2) I send the notifications by name, not by connection id.
3) Notifications can be sent from client code (JS) or from back-end code (C#). In JS you have functions like "others" that are really handy. In C# you have "others" too but that only works with connection ids.
4) I'm notifying changes in the data too so if someone is changing order 1, I notify a supervisor and any other user that has the order opened (in this case I send the notification to the supervisor and all the other agents and based on the order each user has opened I decide if I handle the msg or not).
I hope this helps!
Related
I just got firebase function push notifications working for the first time.
I'm monitoring a change with :
exports.observeNotifications = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) => {
Later, I use :
const userQuery = admin.database().ref(`users/${from_user_id}/username`).once('value');
const deviceToken = admin.database().ref(`/users/${user_id}/device_token`).once('value');
to retrieve the sender's userUID and device token which is later used with sendToDevice()
This works fine and is the method I see recommended everywhere, but I'm wondering why to do this over using topics in a user to user scenario.
In the example of a chat application, every time a chat is sent, a value would be sent to notifications/users/{uid} ... and trigger the event. Then the value calls have to be made, promise handling has to be done, and then the push payload can be configured and sent.
With topics, when the user first loads up the application for the firs time, you could subscribe the user to a topic like "chat_notifications_usersIUID". This negates the need to fetch device tokens and go through the process of using promises and greatly simplifies the process of sending a notification to a specific user down to just pushing to a certain topic that is specific to the recipients UID.
Are there any downsides to using topics over firebase function observes when sending a push notification from user to user(s).
Topics are publicly accessible. So even if you create a topic for each user, all users can subscribe to each of those topics.
For that reason you should only use topics in this way, if the messages are consider public. E.g. in a public chat room scenario this would probably be fine, since everyone can already see the messages in the public chat room anyway. But sending private messages via a topic, means that other users can intercept them when they know the topic for a user.
If your messages are not meant to be public, you will need to send to the individual tokens. Your should only hit a rate limit in extreme cases. If that happens for you, reach out to Firebase support for personalized help in troubleshooting
FOR iOS
Notifications
Cannot see an option for in app pop up messsages - is it only push/re-engagement message types?
Can the notifcations be automated not just scheduled one by one? Can this be done programatically? I.e. Something left in basket so send automatic push
Can the notifications be triggered based on in app user behaviour not just audience or property and can they have a time lag e.g. 3 days after trigger? I.e. User clicked on X promotion and hasn't returned in 2 days
Active Users 1, 7, 30 day
Accuracy of data - how reliable is the Firebase Active user data - what is the definition of actives reported?
Viewing new vs returning? Is this possible? I cannot find a view of this in the dashboard?
User Properties
When you add the code for the setUserProperty() once is is registered how does Firebase start to gather than data on this user property value?
Cannot see an option for in app pop up messsages - is it only
push/re-engagement message types?
FCM is for Notifications and data messages. At this time, if you want messages to appear in the app, you would use a data payload and handle the appearance of a pop-up within your code. See About FCM Messages for details on Notifications vs data messages.
Can the notifcations be automated not just scheduled one by one? Can
this be done programatically? I.e. Something left in basket so send
automatic push
From the console, you can schedule notifications. If you want to automate based on events, I suggest you use a combination of Cloud Functions for Firebase and the Admin SDK. Store the FCM tokens in the database for sending.
Can the notifications be triggered based on in app user behaviour not
just audience or property and can they have a time lag e.g. 3 days
after trigger? I.e. User clicked on X promotion and hasn't returned in
2 days
As for a delay, that would be something you'd have to handle in your own server.
Accuracy of data - how reliable is the Firebase Active user data -
what is the definition of actives reported?
According to the documentation, "An active user has engaged with an app in the device foreground, and has logged a user_engagement event."
Viewing new vs returning? Is this possible? I cannot find a view of
this in the dashboard?
No, this is not possible. You can see the first_open event and extrapolate from that.
When you add the code for the setUserProperty() once is is registered
how does Firebase start to gather than data on this user property
value?
According to the documentation, "User properties are effectively sticky event parameters that are automatically logged when you call logEvent."
We are currently developing an IOS application. The app should basically inform the staff member about new events/requests and the staff member has the option to cancel or accept the event (e.g. customer asks: "I d like to have a coffee", the staff member says: "okay, I'll do it" or "sorry, can't do it"). The idea is that the request appears on multiple smartphones (from multiple staff members) at the same time and that the notification has the buttons for accept/reject included.
The thing is we would like to solve this using Notifications (remote). But there is one thing which is not clear to us. Lets says I receive three requests/notifications. But until I have time to check them, on of the other staff members already resolved one of those requests. Is it possible, that this given requests can be cleared/removed from all staff members phones? Because otherwise I am handling a request that has already been resolved?
And what would be the best option to solve it.
Push remote notifications for every request
Push silent notification for every request and then clear out all notifications on the client, get the new/current requests using REST (GET) and add a local notification for every request?
Thanks a lot for your help.
Regards
I think second option is good.
you can refresh the data using REST api after receiving silent push.
I'm thinking best option is use Push silent notification because end user (Application Holder) will not get clue of that and it is best for us.
I would recommend 1st option
Send remote notification for every request
Handle duplicate request from backend
I think 2nd option is not reliable
APNs treats silent notifications as low priority and may throttle their delivery altogether if the total number becomes excessive. The actual limits are dynamic and can change based on conditions, but try not to send more than a few notifications per hour - source
And Individual notification can't be removed - Check this:
I have a service that allows user to enter the type of events they like, and whenever a new event that fits those criteria is available in my database, I want them to get a notification.
I have been looking around at the best way to handle it and I have found two possible solutions, but I'm not very clear with which one I should use and how.
First, a solution that looked great was the didReceiveRemoteNotification method and the usage of remote silent notifications to tell the app that new content was available. But my questions remains: how can I send this remote notification to the user if I don't know which criteria he has. I mean, how can I send this notification using PHP? I'm a bit lost here.
So I found another possible solution that does look a lot like a hack (iPhone - Backgrounding to poll for events), to be able to make your app execute a method every XX minutes while it is in background. This would be way more battery consuming and I'm not even sure it would be accepted by Apple, but at least it is clear as to how it works: the app downloads data from a link with the parameters that fit the special criteria, and if there is new data, it sends a notification.
How could I combine both these methods?
EDIT
I think the main issue on my side is that I don't understand how I could check a certain PHP file whenever new data is added into mysql and make sure that it fits the criteria of the user and then send the notification. That is the part that I don't understand in the backend PHP usage.
Your flow should be like this -
Mobile -> BackendServer(PHP) -> APNS server -> Notifications->Back on device.
User will submit her/his criteria to server then server will process on that and send request to APNS server.
The APNS server will send remote notification on her/his device based on criteria requested.
I have to add e-mail notifications to a client server application.
Notifications happen as the user do some particular action on the client UI.
If I had a middle tier or a service running at server I can imagine how to do it:
1) I simply create a DB tables with "pending notifications"
2) as a user does an action that generates a notification I add a record to the table
3) serverside I would continuously try to send those mails and removing them from the table once sending is succesful
Now I cannot do this now, I have a plan to add a service later on, but for now I must go the quick and dirty way.
So somehow what I was thinking to is to implement something like this:
1) as a notify-worth event occurs at client, the same client (my exe) tries to send the notification, upon failure it will log the notification in the "pending notifications" table (failure can be becuase lack of internet connection or any other problem)
2) I add a Timer that will work from any client machine to check for pending notifications. If there are any the client will try to send the e-mail (using a transaction: I will mark a field as "TryngToSendFromClientX" and in case of failure I will reset that field to NULL)
I think this approach would work, it has obvious limitations (if after failure no one logs into the system, no notification will be sent - same would be if service goes "down"). But can you comment on this approach and suggest a better one?
Additional notes (to better understand the scenario):
a) Note: all notifications are sent from the same e-mail account.
b) I don't need to keep track of who sent the e-mail.
c) the problem of creating the service now is that it will basically complicate significantly deployment and I need to create tools for monitoring the status of the service. Something that I will do in future but not now, in future I have plan to add more functionality (not only sending notifications) to the service, so in that case it makes more sense to create it.
d) I will send e-mails by using Indy components and SMTP server.
If you are not willing to create the service now, I think you are stuck with the scenario you describe. There are some things though you could do to circumvent the problem of no user firing up the client anymore while there are still pending messages.
You could add a commandline utility (or commandline parameter as bepe4711 suggested) that will only check for pending messages and try to send them.
Add this commandline utility to the StartUp folder or Run key in the registry. This way messages will at least get sent when the computer restarts, even if the user does not fire up the your app.
Add a scheduled task to run this utility at least once every day. The scheduled task can be added by code or by your installer.
If you do both, you will only have to worry about pending messages of users that never start their computer again.
Perhaps you can add a parameter to your client which causes it to just look at the pending notifications and send them. After this it can terminate itself. It will just act like some kind of service.
Then you install the client on the server and start it every x minutes.
I do something very similar to the approach you describe. Instead of sending emails I need to call a web service. My application is installed on several laptops and they are commonly not connected to any network.
When my application raises an exception I collect various bits of information including user comments and screen shots. Then I attempt to send this to our web service. If by chance the web service is not available. (i.e. not connected to the internet or web service is down) I write the results to an XML file on disk in the User Profile (App_Data) directory.
The one major difference is I don't poll to check to see if the server is up. I attempt to send them again on the startup of the application.
If both Systems are running on Windows, have a look at MS Message Queue. It is designed to send notifications to systems, which are not allways online. I did it in .Net, there are already easy to use classes implemented. Not sure about Delphi.
Latest version of Windows uses much more the Windows Task Scheduler, and now task can be fired on event (i.e. when a network card gets connected...). You could write a separate utility that tries to send pending notification, even if noone is logged in.