sort buddy list in real time 1:1 chat with pubnub react sdk - pubnub

I am trying to design a real time in-app chat for social application using PubNub. I found that the best architecture to do so for one to one chat with PubNub is detailed in this article http://pubnub.github.io/pubnub-design-patterns/2015/03/05/Inbound-Channel-Pattern.html
now my next problem is I have to display the list of users in the chatting window, how can I sort this list with the users who have sent messages latest at the top and the ones who have not interacted for a long time in the bottom. if I start fetching message from the inbound channel, I will have to always traverse inbound channel to the beginning every time a user has logged in, this will be a resource expensive call and also is not feasible if we have large user base and heavy message volumes.
I will also be using PAM to control authorization of users to read / write on channels.

That is indeed a great blog entry!
If you are in hybrid mode, so you do use a replicate channel for History feeding anyway, then I would use that same channel and intercept it the content with a function and simply store in the channel Object the list of latest visitors ordered, by the latest showing first, you can even add any extra info you would like to it. Then, any time a user can access the Object values from a REST function to PubNub, so as to retrieve the "hybrid channel" associated Object values (stored earlier) and send that list that is always updated to the Chat user. This has an advantage: if you do not want to retrieve messages until a user taped on one of the contacts in the contact list to avoid pre-loading, then you would load no messages for any channel, except maybe the first user, but then its always less to load from History then all messages from all of the channels, and its always available, before fetched, so fastest.

Related

Adaptive Card Expire After Specific Time

We have integrated the NodeJs bot application with the bot framework for interacting with bot in the Microsoft teams.
Based on the user input we are sending the adaptive cards respectively. Currently user can get the adaptive card today and can update the card later that day or after few days.
Is there any way to make the card expire after specific amount of time which make the card disabled.
Thank You
I have an idea how you could do this, but just an fyi that I've not done exactly this before, so there's no guarantee it will work. Basically, you'd be combining the ability to Update a message like discussed here with sending (or in this case 'updating') a pro-active message - see more here on that.
Because this is an existing conversation with the user, you'll have access from any existing message the user sends to get the parameters you need to start your proactive conversation (you need serviceurl, conversationid, tenantid, etc.). Do note that you can send a proactive message from OUTSIDE your bot (the code can be hosted somewhere else, and doesn't need to actually live IN your bot, even though to the user it will appear as if a proactive message was sent from your bot). I mention this because you could have this "expire card" message live in a separate process to your bot.
In case if you are still looking for an answer, I recently tried this approach:
In the card's response data, I set the expiry date and so now when the user submits the card, you can validate the data in the response and then update the card accordingly.
I had to use this approach because we have a very high user base and updating the card for all users proactively took much longer.
Cons: The card will remain will remain active, unless and until the user takes some action on it.
First of all, no this is nothing that is already implemented anywhere and you completely have to build that yourself.
One way to do this is this:
You need to store the activity / message ID for all cards you send. If you have the ID, you can always at any time go back and update the message (ie update your card)
Now that said, what i would suggest is this:
Sent a card to the user and store the id
Store the ID together
with creation date and expiration date somewhere on your end
Have some scheduled process that scans for expired cards
If a card is expired, update the message with a new card saying "sorry this card is expired"
We did that for our MS Teams Bot and its working quite well this way.

NodeJS and Socket.io creating room with two users

I'm doing chat app and I want to do it real time. Chat will be for now between two users. When user access to chat it finds all messages between them and displays messages. I think I need to create room with two users and then store room id in database. But I'm new to socket.io and I need advice how to do it.
Try to take some already pretty wide used chat, like Slack, as example. Usually you need pretty same set of things, workplaces, channels, private messages (like room but for two users only), and have users sending text messages with some formatting or images or just any files. Just take it easy, plan and make it step by step.
Also take note, that for both parties have their chat view updated with new messages you need not only save message one user send to db, but also broadcast that message to everyone, involved in conversation.

Track multiple context for the same Bot

We have a bot that will be used by different customers and depending on their database, sector of activity we're gonna have different answers from the bot and inputs from users. Intents etc will be the same for now we don't plan to make a custom bot for each customer.
What would be the best way to separate data per customer within Chatbase?
I'm not sure if we should use
A new API key for each customer (Do we have a limitation then?)
Differentiate them by the platform filter (seems to not be appropriated)
Differentiate them by the version filter (same it would feel a bit weird to me)
Using Custom Event, not sure how though
Example, in Dialogflow we pass the customer name/id as a context parameter.
Thank you for your question. You listed the two workarounds I would suggest, I will detail the pros/cons:
New API Key for each customer: Could become unwieldy to have to change bots everytime you want to look at a different users' metrics. You should also create a general api (bot) where you send all messages in order to get the aggregate metrics. This would mean making two api calls per message.
Differentiate by version filter: This would be the preferred method, however it could lengthen load times for your reports as your number of users grows. The advantage would be that all of your metrics are in one place, and they will be aggregated while only having to send one api call per message.

how to get global presence for pusher

I'm building a chat application and I'd like to get a list of which of the people I'm following are online and what chat rooms they are in.
According to the pusher docs, the presence channels are per channel and
This is not the same as jabber style “which of my friends are online” presence.
Pusher doesn’t offer anything out of the box for that use case right now.
https://pusher.com/docs/client_api_guide/client_presence_channels
So if I were to create this feature on pusher, should I just create a global channel and have everyone connect to that silently in the background to get a global presence - if so there is a 100 person limit to that so it wouldn't be feasible. Or should I just create a single channel per user and then let users subscribe to a channel per each person they are friends with (though that seems a bit inefficient)? Note that this is a one way people I am following relationship and not a 2-way friend relationship.
As you pointed out Presence channels are more for rooms of up to 100 users.
Note: The thinking behind that is that a room with more than that isn't really a chat session. Hopefully this restriction will change in the future and it will increase the use case for presence channels.
To get a count of the number of the users you follow who are online you'll need to ensure each user is subscribed to a user-specific channel (e.g. myUserId-channel or private-myUserId-channel if auth is required) and then query the Pusher HTTP API and check to see if a user-specific channel is occupied. If it is then that user is subscribed to the channel and thus online. See Querying Application Channels.
For a more detailed description see Using presence for large groups of users.

Google Cloud Messaging for Chrome channelId unique per device?

Suppose I have my extension installed on two computers, and I am logged into both with the same google account.
Will chrome.pushMessaging.getChannelId return the same value for both computers? Is there any way to request that each individual install gets its own channel? I cannot find this information readily available anywhere.
The question was asked here on Stack Overflow https://stackoverflow.com/questions/13235810/google-cloud-messaging-and-identity, but there is no answer given.
From what I observe, the Channel ID is unique to the user's account, not unique to the install. But I am not sure if this is intended behavior or I can count on this always being the case.
I really think the Channel ID is per application ID and will stay that way. Otherwise, think how complex it would be to send a message to, say, 100,000 installations of your app. You'd have to keep a file of 100,000 Channel IDs, and it would take a very long time to invoke the API 100,000 times, since the Channel ID is part of the API call to send a message.
Sorry... I was wrong. To quote https://developer.chrome.com/apps/cloudMessaging:
"The push messaging service returns a channel ID to the client; this ID is specifically linked to your app ID and to the user."
If a server needs to send messages to all the installations of an app, it needs to keep track of the channel IDs sent to the server by those applications, and send the message to those channel IDs.

Resources