Spring websocket get user subscription from stomp id - spring

Using Spring 4.0.4 I made a DisconnectHandler that implements ApplicationListener on SessionDisconnectEvent.
I can get the sessionid from the event but how do I get a list of the subscriptions for that sessionid, i.e the user?

There is currently no way to get a list of subscriptions for a user. You can keep track of subscription messages as they arrive (not very hard to do). We do have a ticket to make this easier https://jira.spring.io/browse/SPR-12029.

Related

Is it possible to know the number of unread Slack messages a user has with the Slack API?

I'm building a messaging integration with Slack and a client. I need to show the badges on the corresponding conversations when the users logs in to the client to show the client how many unread messages it has.
I know that the channels.history method had the unreads parameter which would return as part of the response the amount of unread messages according to the user token, but that method is deprecated and my app is too new to use it.
I'm using the conversations.history now to retrieve the messages which is what slack suggest to use instead of the deprecated method channel.history, but this new method doesn't have that parameter and doesn't show any info regarding the amount of unread messages in the conversation.
As my app is a new one and not a classic one, I cannot use the RTM API.
I'm also subscribed to the message events so that I know when a new message was posted.
My issue is that I need to know how many new messages were sent to the user while he was not logged in.
Is there any way to get that info?
Unread count is in conversations.info method, not in conversations.history. There in unread_count and unread_count_display property in reponse. Documentation is here.

How to get message events published on a Web API endpoint and feed it to bot framework v4 (C#, .Net Core Bot)?

I am using a third party API to provide Agent Handover (human chat) capabilities to my v4 based bot. The API requires a call back hook/ endpoint where it can send the messages/events back from the agent, and I have to get messages from it and display to users. When ever a new chat session is established a new session id is generated. And thus Session Id is passed back in all messages and events. Essentially they are sending events as Fire&Forget with a retry on failure.
For now I had implemented an eventstore (in Cosmos dB) to store events/messages and then poll Cosmos periodically display message back to user and mark them processed.
Is there any way to make it more real time or pub-sub kind of analogy?
I would like to know if some one have already implemented scenario like this. What should be the way to respond the incoming messages from agent to bot user.
Please suggest.
I would recommend creating a client using the Direct Line API to handle routing messages between the third party agent handover and the bot. Then in the bot you can pair the third party Direct Line conversation references with the user's conversation reference to forward the messages accordingly with proactive messages. For more details take a look at this Stack Overflow question.
Hope this helps!

Use Nchan to post to logged in users only

I am setting up an application with realtime events using nchan (https://github.com/slact/nchan). The application itself is built on the Laravel framework. However, for now everyone that subscripes to specific sub-channel will get new events as soon infomation is pushed to the corresponing pub-channel.
I want to limit that so only logged in users should be able to subscribe to events. Hence, if I am not logged in, it should not be possible to create a websocket and listen for events from for example http://www.example.com/chat/pubchat?id=some_id.
Is there any way to make this possible?
As far as I know, I cannot use Nginx/Nchan to make database queries to get only logged on users that way. And Laravel itself cannot limit subscribers since that is handled by Nginx/Nchan (but on the other side, can make database queries).
Thanks for any tips!
EDIT: Seems that I might can use the Drizzle module (https://github.com/openresty/drizzle-nginx-module) and use the session ID as identifier. So if that ID is not present in the session table the connection will be blocked.

Spring STOMP - immediate response

I am implementing an Angular client that connects to a spring boot backend via STOMP.
When a client connects and wants to create a "business-group", said group is created in the backend and gets a UUID; and from that moment on other clients should be able to send to and receive messages from that group.
So I am creating a topic with said business-group id in the destination - something like
#MessageMapping("/foo/group/{id}")
However I want the creator of the group to immediately receive the business group id to be able to subscribe to it himself as well. And to be able to share the id with others (user to user).
I have used raw sockets for this before, so I was able to just use the connected user's session and then send back the id to him after the had sent the create-message. But since the session handling was business-group-ID based (so that only the users in a specific group receive the messages from that group), the whole dividing user sessions by business-group-ID had to be done manually and I was looking to upgrade this to something that does that handling for me.
However I am not sure how to achieve this with spring stomp. So my question is, is there a way for the creator of such a group to immediately receive the id as an answer/response to his initial "request"?
Because he can't subscribe to anything before he receives the group id.
Background:
It's basically like a chat app where a user can create a group/chatroom and then share it with others (via URL - which contains the ID); everyone that subscribes to it can then receive msgs from it and send msgs into it. But to do so the creator first needs the created ID.
I found a solution. This can be done via #SendToUser
#MessageMapping("/group.create")
#SendToUser(value="/topic/group.create", broadcast=false)
public Response createGroup(#Payload Message message) {
...
return createResponseWithId();
}
On the other end you only need to subscribe to '/user/topic/group.create'.

How to fetch unread messages of a particular user through rocketchat rest api

I am working on rocket.chat integration. I need to fetch all unread messages of a particular user through rest api. Do anyone know any method that will do this task? Couldn't find any in the documentation as well.

Resources