how to get global presence for pusher - 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.

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.

User leaving channel

Like other personal messenger, a user might want to organise chat channels they no longer wish to participate in by leaving the channel.
In Getstream sense, it would be removing the user from the channel's member list.
There does not seem to be a functionality for this.
I have tried to include removeMembers permission to user, however, I am getting an error that members cannot be removed from distinct channels.
You have a couple options to achieve this:
Remove the channel server-side (this makes sense if the conversation
is over for both)
Hide the conversation for one user (see channel.hide). Doing so will hide the conversation for one user until a new message is added.

How to get real time feed to all the follower in node application

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.

Telegram Bot Event When Users Join To Channel

After create telegram bot, access and admin this bot to channel. how to get channel members list or event when users join to this channel?
Pretty disappointed with the current answers, so I'll leave an updated (as of February 2018) answer that explains how to do this with the Telegram API itself, as well as with the framework I am using, Telegraf for Node.
The Telegram API is both very powerful, and pretty simple as far as API's go. If you are using the polling method of getting updates, and not websockets which are a whole other issue, checking if someone new has been added to a group or channel is very easy.
The API method getUpdates returns an array of Update objects, which contain all of the possible information you could want including any messages sent, inline queries, and new chat members. To get any new chat members you simply need to access update.message.new_chat_members which will contain an array of new users. For reference you can look in the API documentation here.
To fetch the update objects in browser, or with curl, all you have to do is send a GET or POST request to https://api.telegram.org/botYOUR-BOT-TOKEN/getUpdates. Then just look for messages->new_chat_members.
If you are using the Telegraf bot framework with NodeJs you can use the bot.on method with the event new_chat_members.
Example:
bot.on('new_chat_members', (ctx) => console.log(ctx.message.new_chat_members))
I know this was asked a while ago, but I hope this helps other people searching.
From docs:
new_chat_members New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
So i think you can't.
To get updates on users join group or channel you must correctly setup webhook for your bot. This update type is disabled by default. See https://core.telegram.org/bots/api#setwebhook
allowed_updates
A JSON-serialized list of the update types you want your bot to
receive. For example, specify [“message”, “edited_channel_post”,
“callback_query”] to only receive updates of these types. See Update
for a complete list of available update types. Specify an empty list
to receive all update types except chat_member (default). If not
specified, the previous setting will be used.
Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received
for a short period of time.
So, the request should look like this:
https://api.telegram.org/<BOT_TOKEN>/setWebhook?url=<WEBHOOK_URL>&allowed_updates=["chat_member"]
Yes! You can use this:
https://api.telegram.org/bot[TOKEN]/promoteChatMember?chat_id=#[channelname]&user_id=[user_id]
if user is joined response is ok, else response is not ok.

Resources