Notifications about unread messages (node.js + sockets.io) - node.js

I have a system of personal messages between users on node.js sockets.io, is now faced with the problem that I do not understand how to make the notification about unread messages. Let's say, how to determine what a user who has received a message read this message, and how to make a notification message if the user is not in correspondence?
ps Chat History and active dialogs are stored in mysql.

Assume if the user has an open socket, and the message has been sent, then when the user clicks in a certain area of the page (perhaps the send message box?), an onClick event is fired to notify the server the user has received the message.
If the user is not on the webpage, there's not a way to contact them through sockets.io.

Related

Get telegram group messages before brodcasting to anyone

I want to create a Telegram bot and use it, inside a group, as a bridge to get user messages and information, then send messages through the bot with a fake name.
So the Problem is: Bot receives the message after it's broadcasted to everyone and I should get the message and delete it, then do my stuff but this can reveal the user's identity.
I want to get the message before it's broadcasted to anyone and:
Prevent the message from broadcasting.
Bridge message through the bot and send the same message as the fake user created in my server.
Is there any other solution to use out there? except inline mode?

How to check if the user has the webchat window open?

I am creating a customer support bot using Ms botframework v4 with nodeJS and directline API 3.0. A customer would talk to the bot and on request, the conversation would be handed over to an agent. If the customer requested to talk to a bot, the customer will wait until the agent becomes available. I want to check if the customer is still active before the agent sends a message to him/her.
wireframe of the bot and the webiste As you can see in the image Jack is in the queue I want to find out a way to check if Jack is still waiting, or he close the window and no longer waiting.
Check out this SO solution I provided. The request is similar to yours in that the OP wants to know how the bot can be notified if a user exits.
The short answer is to use an event listener. Before the window (that houses the web chat instance) is closed, an event is fired. This event is picked up by web chat which sends an activity (message, event, or other) to notify that bot.
From this point, you simply need to forward the notification to the agent that the user has exited the conversation.
Hope of help!

How to send chat notificattion to user offline/online by socket.io?

I can send messages to others by socket when they are in a room but now I want to send a message when other users are not in a specific room or offline, as a notification.
You need to intergrate database with the socket application then only you store message offline and display to user when online.

How to close socket connection with already unauthenticated user?

There is system where users can be logged in and then do chat.
When the user is being authenticated the auth-identificator is saving to the session and session save to the Redis.
On the backend (PHP) user state (authenticated or no) based on the session value (auth-identificator).
Also the system has a chat based on nodejs and sockets.io.
There are 2 user types Admin and User and they can chat with each other.
When user/admin is being connected to the chat room or writes message in there, the nodejs gets headers and among the ones there are cookies, nodejs fetches SESSION_ID from those and check if that session is presented in Redis and has the auth-identificator if it is - we know that user is authenticated and can be connected to the room or we can save his message to the DB. Then received messsage is broadcasted to the users connected to room.
The problem is:
1 - Open browser, authenticate in the system by the admin and open chat
2 - Do the same for the user
Then these can communicate with each other.
BUT when user opens first browser tab with chat and on the second tab he gets logout, and this time admin will write message, already logged out user will continue receiving the messages.
So, the question is: how we can close socket connection with the user?
If user click Logout button, then we can send from PHP to nodejs the message via Redis pub/sub channels and nodejs will close connection, it's OK.
BUT when user open second browser tab and then will clean browser cookies he will immediatelly gets unauthenticated, but on the first tab he continues receive the messages. The same is true for admin.
How can we prevent it?
Thanks.

Using socket.io for notifications and chat

I'm very new to node.js and sokcet.io that's why I need to ask you about the plan I have to see if it makes sense or is plain stupid. I need ongoing server/client communication for two reasons: sending real-time notifications to the user when they have one, and two, for chat between users.
Here is my plan for managing notifications:
PHP script finds out user X has a new notification.
Using Elephant.io send a message to server with user X's id as the data.
On the server side, upon receiving the message, if user X is connected emit him a message telling they have a notification.
user X's brower, Upon recieving the message, uses AJAX to poll the database and receive the text for the notification.
For chat, this is my plan (messages should be save on DB):
When user X submits a chat message to user Y, use ajax to send the text to a PHP script and save it on DB. On success, use elephant.io to send a message to user Y telling them that they have a new chat message.
User Y's browser, after receiving the server message, uses AJAX to poll a php script to receive the new text.
Do you think these plans are superior to short polling using AJAX? I appreciate any comments to improve them.
Finally,I'm curious to know how reliable these technologies (node.js, socket.io, elephant.io) are. Do they work well when the server becomes busy? How do they handle exceptions and errors ,etc.

Resources