PubNub: How to get conversation history - pubnub

I have an application used by hundreds of users. Users can start a private chat with each other.
Each one of the users has its own unique id and its own static channel id.
for example:
userId 1 has its private channel id called: app-private-1
userId 2 has its private channel id called: app-private-2
userId 200 has its private channel id called: app-private-200
and so on....
Each one of the users subscribe to its own private channel id to get private messages and also knows the list of all other users private channel ids in order to publish private messages to them.
For example:
when userid 1 want to talk with userid 2 than:
- userId 1 publish message on app-private-2 channel.
- userId 2 which subscribed to app-private-2 get the message.
- userId 2 publish back a message to userId 1 on app-private-1 channel.
The question is how can I get the conversation history chronologically, in the form of who said to whom, in order to present it to the user (I also have section of history in my app).
I can't use the history feature of PubNub because it gives only history of one channel and I will lose the context of who said to whom.
Also, if I will save the messages in my db, it will be a complicate thing to manage and won't solve the issue in a scenario when one side subscribe to channel group and others to only one of the channels.
Any ideas???

PubNub Channel Topology Decisions
Channel topology is a decision that you need to make early in your app design.
The strategy you have used makes getting a conversation between two users very difficult. To make this simpler, you should create a unique channel for each user-to-user private chat and use the user's private channel for notifications only: you got a message/invite on channel abc, for example.
What you would have to do it get history on both users' channels and pick out the messages from only those two users. If you didn't store the userid within your message payload, then there is no way to know.
PubNub Function Endpoints
Furthermore, if you pull history on both channels from a client side app, then the user would see all messages published by other users, assuming the user pulling history has read access to the other users' private channels, but that would be bad.
So you would need to call your server (better to implement a PubNub Function Endpoint to do this so you do not have to hit your server) to pull history of both channels and sift out the relevant messages of the user-to-user conversation.
PubNub ChatEngine For the Win
If it is an option for you, PubNub ChatEngine will remove much of the design and implementation details for you, with many plugins (all open source) to handle lots of chat functionality you will need.

Related

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

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.

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.

How to get the messages count in app insights

I am trying to run the below query and attached is the result of the query. I would like to understand the difference between the conversationupdate, message, event, and endofconversation. Thank you.
customEvents
| where timestamp>ago(7min)
| summarize count=count() by tostring(customDimensions["Activity type"])
Here is the result:
Those are all activity types. You can find a list of activity types in many places, such as here.
conversationUpdate
A bot receives a conversation update activity whenever it has been
added to a conversation, other members have been added to or removed
from a conversation, or conversation metadata has changed.
message
Your bot will send message activities to communicate information to
and receive message activities from users. Some messages may simply
consist of plain text, while others may contain richer content such as
text to be spoken, suggested
actions,
media
attachments,
rich
cards,
and channel-specific
data.
event
Your bot may receive an event activity from an external process or
service that wants to communicate information to your bot without that
information being visible to users. The sender of an event activity
typically does not expect the bot to acknowledge receipt in any way.
endOfConversation
A bot receives an end of conversation activity to indicate that the
user has ended the conversation. A bot may send an end of Conversation
activity to indicate to the user that the conversation is ending.

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