No XEP-0333 Chat Markers in XMMPP Openfire backend - how to solve it? - node.js

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)

Related

Carousel in Bot Framework - continuously updating from database - upon scrolling it?

Is it possible that carousel in Bot Framework (where it is allowed - like Messenger, Bot Emulator etc.) updates continuously (according to a database from which it reads data) after it was initially rendered and sent as a message to the user - without rerendering the whole carousel and resending it to the user?
Something like - .onFlipHandRightOnCarousel or .onFlipHandLeftOnCarousel - delete void HeroCards (where in database they are flagged as 'inactive') from already rendered carousel and rerender this new carousel without resending a new session.send(msg) to the user?
Modifying messages that have already been sent means modifying the chat history. This functionality will be highly channel-specific as it depends on how the client handles the history and what the client allows users to do to the history. Many channels do not support this functionality but some do. Generally speaking, if you as a user can go back and delete or edit messages in the chat history then a bot can too. If you as a user cannot then you should not expect a bot to be able to do it. But if you're working with a channel that does allow history edits then I imagine you should be able to edit the carousels if those are also supported.

How to use trigger event in facebook messenger bot

I'm developing Facebook messenger bot. Based on the official sample
here made by Node.js, Express, ES7.
I want to use Firebase database, trigger event.
If someone updates the database, send notice to certain people. I add source code "Child Changed" to "messages.js" in messenger-api-helpers, but it doesn't work.
I can check working "Child Changed" in HTML, but in messenger, I cannot.
Where should I write the trigger events code?
You should definitely use Facebook Messenger Broadcast API for this kind of functionality. This will broadcast a notice/broadcast to users.
Caveats:
You have to apply for this permission. (pages_messaging and pages_messaging_subscriptions.Takes about 1-2 days, but
can test on Admin/Test users of the app)
Each broadcast has to be a separate broadcast. (e.g. you can't send image and a text together, each has to be its own individual broadcast).
Have some kind of un-subscription option as well. FB user might think you are spamming even if you clearly say in the messages that your bot will send updates.
Use custom labels to create targetted sends. So you can either subdivide who you will send updates to about specific issues or just label people if they unsubscribe to your broadcast or not.
Basic workflow:
Get permission to broadcast.
On event in your Database. Start process.
Create message_creative_id via POST to endpoint
Use message_creative_id to POST a broadcast_messages
On a successful send you will get back broadcast_id

Using socket.io to send data to a specific view/id

I have a web application using NodeJS, Express, and MongoDB. In my application, I have a view, that can be seen by anyone who accesses the application. That view is rendered with a different image, depending on which a user selects to view (they do not need to be logged in) ie the view is mapView/mapId.
Now, I want something similar to notifications to occur in realtime for those that are on that page. When a specific event happens from an external source, I want to display a popup on the view to which the event belongs to. So the event may only belong to one mapView/mapId and not another mapView with a different ID. All users on the same mapView/mapId should see the notification. Remember, these are general users that do not need to be logged in.
I am researching into Socket.io because I know it is for making realtime applications. But I am wondering if this is even the right way to go. How will I send data to the correct mapView/mapId?
Check out what your server can do with rooms
The idea is that each of your connections, from a particular view, is joined to a room. Then you use socket.io from the server to send a message only to that room. And only those sockets will get the message.

Call server in background

I'm building an iPhone-app in which the logged in users can chat to each other. It's very like the Wordfeud chat for example. You click a user and a modal view controller shows up where you chat.
I have set up a push notification server that works, I just need to know just how I should use it.
When the chat view controller is open I poll in the background with ASIHttpRequest every tenth second to see if a message has been sent from the user you chat with. This works perfectly fine.
But what happends when i close the chat view controller to do something else in the app. Should I create a ASIHttpRequest in every single view controller in the app to poll for new messages or is it here the push notification service takes over? Even though the app is still open?
Or shouldn't I send push notifications when the app is running, only when it's not running?
If that's the case I guess I have to send a request to the server which says that the app is has now been closed (here is a problem if the app crashed out of the blue).
I would be really greatful for some guidelines here, I have searched the web but there are old discussions which confuses me, and some new ones where many people says different.

How does gmail check gtalk statuses in real time?

How is it that if I have thousands of contacts (let's suppose) all around the world and one of them changes their status to away or becomes idol that it will change immediately in my browser?
It isn't instant really, there is a small delay, basically when you load the gmail page in your browser you also download a javascript file that refreshes the content dynamically via ajax. Similarly if a contact of yours changes gtalk status and you're using the gtalk client in gmail that change will be reflected after the next time the page you're viewing asks the server for updates. It's just constantly checking with the server for changes (the event oriented paradigm isn't really prevalent on the web).
I'm not sure of the exact mechanism gmail uses, but a fairly dumb way would be to have the page poll (via XMLHTTPRequest, aka AJAX call) the servers every X seconds for a change in contact statuses since N seconds ago... then apply those changes.
Google chat system is based upon XMPP protocol and Gmail chat block is just like another XMPP client (similar to gtalk,pidgin,psi for desktops). XMPP runs over browser using Bosh extension. Though i m sure google must have hacked to get it working in their own way, but underlying idea is still the same.
In short, when one of your contact update his/her status, it is being pushed to the google chat xmpp servers which in turn pushes that information to your gmail chat client.

Resources