Using nodejs and redis sub/pub system. When I log into my web app I want to get the latest published content once I subscribe to it via nodejs. Is this possible? When I login I want the user to see the content from the channel they subscribed to. Right now when I login there is no data, but when I publish content to the channel it shows up, I refresh the page and the content does not show again.
EDIT
When the person logs into the system would I instead just load the results from the db via php then from there subscribe to the channel via nodejs and update the rows via redis sub/pub? Is that how it would work?
I think the best answer is anytime data is published to the channel to at the same time store that data in redis using the channel name as the key. Then when a user logs in it then grabs that data in redis, displays it then subscribe to the channel waiting for updated information. Do you agree or is there a better way?
Related
We have an Openfire XMPP/Jabber server setup (with a NodeJs backend and React frontend).
Chat is a feature embedded in the app (NOT an overlay or window that is always visible). So the user has to navigate to a specific page to access the chat interface.
It is working via websockets and messaging sending is working fine. We have a React frontend.
The challenge is that XEP-0333 Chat Markers is not supported by Openfire (the spec never become production ready).
Therefore we need to know how can we implement this feature so that :
A users knows when they are online that they have an unread message (and later, how many unread message they have). For example, if they are not in the chat window and messages are arriving, we need to indicate that in the header of the app so they see it)
if a user goes offline, and comes back online but NOT into the chat window, how can we know if they have unread messages and notify them of that?
My understanding is that somehow we have to keep track of unread messages (eg perhaps in indexedb or local storage or even in postgres backend) and after the user reads a message, we delete it from storage. If the storage still has records for that user then clearly those are the unread messages.
Obviously we don't know if they actually READ the message, but we can assume that if the chat window is open and visible (ie. active tab in their browser) that any messages delivered have been read.
So if our application tab is active, but user is not in chat, and a message arrives, we store it. When they open chat and click on the sender, we remove it from storage.
Has anyone solved it this way? (looking for links to React or JS/TS code)
Is there a better way? (links to other solutions would be helpful, esp. code)
I would like to find out how, using Node.js, Express, Typeorm I can send notifications at random times to users to add a post etc.
I would like to create something of the BeReal sort. Notifications should be sent according to the user's selected time zone at random times.
If you want to send automated notifications, I'd recommend using
node-cron. However, for your case, I'd propose to add a timeZone
indicative information in the database to link the user with the
timeZone(you can find it in HTTP Requests, update it after each
login).
For the actual sending of the notifications, I think you should use
some third party service like Google Firebase for mobile
notifications, and web-push for web applications.
I want to redirect the chat from Google dialogflow to a human. For this, I want to get the history of the conversation made by the user. Is there any platform where the history is being stored? If yes, how to access it. If not, how to achieve this functionality..
There's no current API to retrieve session history. The only alternative is to save the history yourself.
You can use any database you're familiar with, MySQL, MongoDB, or even a cloud hosted database such as Firebase Realtime Database
The code won't be too hard, everytime the user sends a new message and every time the bot answers, you will have to save that message to the database, with the right timestamp and chat ID.
When the user is redirected, you will get all the messages from that session using the chat ID, sort them by timestamp, and you will have your complete chat history available.
Some answers/tutorials that might help you:
Best way to store chat messages in a database?
Storing chat messages inside a MySql table
Firebase Web chat tutorial
I am developing Social network type of application in node.js and MongoDB.
I want to add a functionality such as -
If user A has followed user B then when user B post something it should automatically come to user A on his wall!
Approach 1- This is what I have research till now
Create a channel of user B and all the other user subscribe to that channel and when user B post something then emit that with socket.io on all the subscribers.
so for this approach, we are thinking to create a channel when the new user signup every time.
But the problem is -
is this feasible approach as for how do I know which channel is which user or is there a way to store the channel in MongoDB.
if I create too many channels will that crash my server?
Approach 2 -
Another Approach that I have got is
Look up the followers of the source user in your database.
And emit feeds to all the followers using socket.io
How to scale this if I have got 100 followers of each user and when everytime user post, will searching in a Database creates an overhead.
Using Redis caching would be better to store followers?
And instead of checking the followers-
find that from Redis and emit the msg using socket.io
Approach 3 -
I have heard the name of Redis pub/sub but not able to find how it will work in my application.
Please suggest some best standards for creating something like this!
And if above approaches are fine can you pls suggest me the flow for that or how do I create a code for that!
I would be great if you provide me an example.
I think you can use Approach 2, but you must create a queue (redis queue or rabbitMQ) to do that.
I mean when you create a post, it must push to queue to push message to 100, 1000 follower in your DB.
I want to Fetch Every Facebook Status update i make from my Fb Account using NodeJS and print it in my console ...Can this process be event driven,Is there a way wherein a event is generated and the NodeJs server is notified when a new facebook status update is made without polling for it ???
This sounds to me like a webhook is what you are looking for. I do not know whether or not Facebook offers webhooks. If they do, that should be your solution.