Adding facebook like notification feature to MERN app with isRead flag - node.js

I am trying to add facebook like notification feature for my app. Instead of different notification for different user I have general notifications which are common to all the users. And for every user I want to have isRead flag so that I can show the user read and unread notifications. So, the question is, how should I design my model and how should I achieve the isRead functionality??
One idea in my mind is to create a notification collection with all the notification and have a field of readBy in which I will store the userId of all the users who have read this notification. And while showing the notifications to the user I can check whether his name is in the readBy field or not and show read or unread notification accordingly.
But is this method efficient? If not please suggest any more efficient method.

Related

Send notification to one user with firebase cloud function node

I am trying to send a notification to a specific user using FCM, but I haven't found a way. I have a mobile app and a node server running.
I want to be able to send a notification when the shipment status changes. I have already a function for it in my server I just have to send the notification to the user. Is it possible to achieve this using nodejs or is there a way to implement it in flutter?
I found this code
    var FCM = require('fcm-node')
var serverKey = require('path/to/privatekey.json') //put the generated private key path here            
var fcm = new FCM(serverKey)     
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)        
to: 'registration_token',         
collapse_key: 'your_collapse_key',                
notification: {            
title: 'Title of your push notification',             
body: 'Body of your push notification'         
},                
data: {  //you can send only notification or only data(or include both)            
my_key: 'my value',            
my_another_key: 'my another value'        
}    
}        
fcm.send(message, function(err, response){        
if (err) {            
console.log("Something has gone wrong!")        
} else {            
console.log("Successfully sent with response: ", response)        
this is a npm package taht lets send a notification but it asks for a registration token.
I hope you can help me. Thanks in advance!
Firebase Cloud Messaging has no concept of a user. Instead it can send messages to:
Specific app instances (so your specific app as installed on one specific device), as identified by an FCM/device token.
A group of app instances/tokens, as defined by your application logic.
A specific topic, to which app instances can then subscribe.
It's up to your application logic to decide how to map from your user ID to one of these options. The most common are to:
Store the device token(s) and your user ID in your own database, then look up the device token(s) for a user when needed and fill them in to the API call you already have.
Use a specific topic for each user ID, subscribe the application to that when it starts, and then send a message to that topic when needed. Note that anyone can subscribe to any topic though, so this approach would allow folks to receive message for anyone whose user ID they know.

Retrieve Teams User ID based on AAD ID

I am trying to start a scheduled proactive conversation (the bot initiates the conversation on scheduled time).
I managed to get the User's AAD ID based on Graph API, but it doesn't match the Teams user ID. Tried for over 2 hours to obtain the right id, but I can't figure it out how. What would be the best approach I should take?
Have a look at the Microsoft Graph api to get the chat thread ID.
When the app is installed for the user, the bot will get receive a conversationUpdate event that will contain the necessary information for it to send the proactive message. For more information, see Bot events.
If you lose the chatThreadId, you can find it again by calling:
GET /users/{user-id}/chats?$filter=installedApps/any(a:a/teamsApp/id eq '{teamsAppid}')
However, this will only for for the personal scope! My advice would be to make sure you catch the conversationUpdate which is triggered after an install and persist the user details in a database.
I'm curious how you tried to "match" these? In any case, I don't think they're intended to match up in any way (the aadObjectId Guid and the "29:..." user id). As a result, you should store a mapping on your side (database or similar). You need to store ServiceUrl and ConversationId anyway to do proactive messaging, so just tack userid on as well.

Personalized web push notifications

I want to send web push notifications to registered users, are there any best practices on how to implement the cases when multiple users have access to the same device and one should not see the message of another user.
Thanks in advance.
A web push notification subscription is tied to the browser, not the device.
What you need to do is, map this id with your registered user when he logs in from a particular browser. Also, you need to remove the subscription id mapping with any other users in the system.
In the case of multiple users using the same browser, the above logic will make sure that at a time, a particular browser subscription id is linked only to a single user.
And when you want to send a notification to a registered user, you can retrieve all push subscription IDs linked to this user in your database, and trigger notifications to those subscription IDs.
And don't forget to unmap a subscription id when the user logs out from a browser. Otherwise, he will continue to receive all notifications even if he has logged out.

Can I integrate getstream.io notification services in Drupal 8 site? If no then any other way to use the notification services in Drupal 8 site?

I need to add push notification in my web site
If a user has made payment for something... we show them alert in their account page on the website that you are now successfully connected to this community
If a user has done payment by check... we clear the payments by check through a cron job... once the job runs and payment is cleared... we show a notification to user whenever they log in saying that their check payment is cleared
A user sends a request to connect to an organisation... that organisation's admin should get an alert in their system saying that so and so person is pending approval from you.
Something similar to alerts that we get in our net banking might be... that your credit card payment is pending... something like that
Like we also get notifications on Facebook... the difference will be that instead of notifications we want to show alerts or messages directly displayed in their account
So, you want notifications in your system about payments.
In its simplest form, you could do it manually with emails, and/or popups in your application, that are loaded from DB when they login. This is sort of a manual system, and the Minimum Viable Feature could be quite easy to build yourself.
If you want it more advanced, like you mentioned, similar to Facebook's notifications button and feed. Then, yes, it might be easier to use getstream.io. It also has websocket integrations so you can get those notifications pushed in real-time. You can then also push other types of notifications in there, like for example: a notification when the user has logged in from a different browser (for security reasons).
I hope this answers your question.

How are users tracked for location based push notifications?

I want to enable push notifications for a UWP mobile app connected to Azure app service with Azure SQL database. The notifications will alert only the users that are located within x kilometres from a certain geo coordinate.
However I'm not clear about how to track the users, My questions are as follows,
In my database should I store every user that uses the app and update their location periodically? I'm guessing I would need to do this in order to calculate which ones are in range and send notification to only those. However this leads me to my next question,
If I was going to store a record for each user in my database, what identifier is used for them? How are users identified on each device? Do they need to log in with an authorization provider like Facebook, Twitter, etc. in order for my app to record a unique identifier? Or is there a different mechanism to create or get a unique identifier?
#DaveSmits is on the right direction. You could register a GeofenceBackgroundtask to report user's location to your azure service. Besides current location, you also need to report current device channel Uri to your zaure device.
I believe you're familiar with WNS. If not, please check that document, it will explain what the channel Uri for you.
Then in your azure service, you need to save the location and channel Uri in some database tables. You would need to caculate the distance from a certain geo coordinate. If it meets the requirement, you can get all qualified channel Uris.(e.g. select channelUri from yourtable where location='xxxxx')
After you get all channel Uris, you could use it to send notifications to the specific users. About how to send notification, please check the WNS document.
I've answered a similar question on MSDN, it also needs to send notifications to the specific users.
there is nothing to track the location of the user in the push notifications. There are two things you can do:
solution 1:
- use a geofence that triggers a background task. If entering a geofence register for push notifications. If leaving the geofence unsubscribe again in your backend.
solution 2:
- Only send raw notifications and use a background task to handle them. In the background task evaulate the current location and if in the right location trigger the notification from code.

Resources