HipChat Nodejs Bot - Cant receive room messages - node.js

I am trying to create an hip chat bot with nodejs. The main library is node-xmpp. However at the moment the build is failing and I think thats why my nom install doesn't work.
Any who I managed to write my own version based on the core modules.
- node-xmpp-client
- node-xmpp-component
- node-xmpp-jid
I can see messages fine and send. But only private! although I am registered in a room I cannot see room messages.
The source code of node-xmpp says thats a message or stanza should have a type and from that understand if the message is private or not. Well to me only private messages come. I wonder if its an issue with Hipchat.
If you want to take a look at the code, I made a github repo as it would an overkill to page here. github

The 'problem' lies with the xmpp protocol itself.
Due to the way the protocol works, you need to have joined the room before you can receive messages from it.
Why I was, lead to believe otherwise, was because hip chat showed the user as online on the room, but in reality he is not online on the group he is just online.

Related

Telegram bot doesn't process messages anymore

I face a somewhat weird problem. Unfortunately, I have to diagnose and repair it from distance without any real access. So I don't know if I can provide enough information to solve it.
Context:
I built an interface for my grandma (94) to chat with the family via telegram by connecting a Telegram bot to a microphone (for her to record voice messages) and a small printer (for the messages to be printed for her). [This is inspired by the Yayagram invented!]
The problem:
For the last one year, everything worked just fine. However, a few days ago, the bot stopped working. My grandma could not send any voice messages and didn't receive any of our messages. After calling her and checking all the connections, we restarted the device. Now, she can send voice messages, but the bot still doesn't process our text messages (nor commands!).
I have never encountered a bot being able to send messages without processing incoming messages. As I said, I have no way to analyze the problem in detail as my grandma lives 500km from me. If anybody has any ideas where the problem could be, I would be very happy.
Edit:
I knew it would work to post a question on StackOverflow! Out of nowhere, the bot seems to work again. I have no idea what caused it, or why it started again as I did nothing. I am still grateful for any insight for what might have caused it!

How to build friend list where user status is shown online/offline?

I've 2 ideas.
Idea #1:
Using Redis put people currently online into set. Then from client side user would periodically send a request to send him status for all of his friends. Server would make sql request to get all friends and find them in the redis set and if so then they are online.
Idea #2:
Using Redis PubSub, when you as a user are online you subscribe to all n friend channels. And whenever a user goes online he publishes on a channel that he or she is online. And whoever maybe listening will get notified.
Now I can't tell which one is more scalable and efficient.
I think idea #1 should be the solution. idea #2 CANNOT work.
Redis doesn't keep published messages. So if a client is NOT connecting to Redis, the message will be lost. When he reconnects to Redis, he won't receive any messages published before.
In your case of idea #2, when a user logs in, he has no idea whether his friends are already online. Because his online friends have published online messages before he logs in, and he won't get these messages.

Efficient Chat Streams

I'm attempting to create an application which will work as a chat app. I'm currently contemplating the best way to do this and I'm thinking of going with a server sent event package such as the following. Every conversation would have an id, and the message would be emitted under the id. For instance
stream.emit(1512, "Hello") would send the message and
stream.on(1512, function(message){console.log(message)}) would print the message. Only the chat members would have the chatId.
I was initially thinking of using websockets but I thought that not every user should be receiving data, as chats were private and I didn't want to configure authentication within websockets.
Back to server sent events:
I have a few questions on the topic.
Are they efficient and, if not, what would be a more efficient solution
Is the method of sending chat through a randomized, hashed, id (such as 309ECC489C12D6EB4CC40F50C902F2B4D) secure?
Would you recommend a different method for sending chat? This is to be implemented as a mobile application where individual users can chat privately with oneanother so, again, security is pretty important.
Thanks.
I recommend the client-call package (disclaimer: I wrote it). It provides a very simple method to run a client-side method from the server code.
Besides this, you can always just put the chat messages to a db collection and remove them after some time.

A way to transfer IRC chatter/pm to gtalk

I'd like to know if some sort of bot/tool/service exists that would allow people on (regular) IRC chat to me on gtalk
so: irc user X sends a pm to MyBot (f.e.); that pm forwards to me
a irc room to chat would also work fine (so everything said in channel #abc gets into my gtalk conversation with mybot#domain.com
hope I was clear enough for you to understand what I'm looking for and that anyone knows a way for me to solve it.
Thanks!
You can use PircBotX to create an IRC bot in Java yourself, and use pm events to send gtalk messages using any old Jabber library. A quick search finds me Smack.
I did something similar once, but I made two instances of PircBotX, one to connect to the IRC server, and another to connect to this special IRC server somewhere that was configured to automatically pass on messages to popular IM protocols. I can't seem to remember what that service was called, perhaps you'll have better luck.
Well, there's the hans-irc-gtalk bot which does something like that. People need to subscribe to the messages in order to get them from gtalk. Not sure how well supported the project is.

How to model Push Notifications on server

Brief Description:
Well, since many days I've been looking for an answer to this question but there seems to be answers for 'How to create a Push Notification Server' and like questions. I am using node.js and it's quite easy to 'create' a push notification server using sock.js (I've heard socket.io isn't good as compared to sock.js). No problem till here. But what I want is how to model such a server.
Details:
OK, so, let's say I've an application where there's a chat service (just an example this is, actual thing is big as you might have guessed). A person sends a message in a room and all the people in the room get notified. But what I want is a 'stateful' chat - that is, I want to store the messages in a data store. Here's where the trouble comes. Storing the message in the database and later telling everyone that "Hey, there's a message for you". This seems easy when we need the real-time activity for just one part of the app. What to do when the whole app is based on real-time communication? Besides this, I also want to have a RESTful api.
My solution (with which I am not really happy)
What I thought of doing was this: (on the server side of course)
Data Store
||
Data Layer (which talks to data store)
||
------------------
| |
Real-Time Server Restful server
And here, the Real-time server listens to interesting events that the data-layer publishes. Whenever something interesting happens, the server notifies the client. But which client? - This is the problem with my method
Hope you can be of help. :)
UPDATE:
I think I forgot to emphasize an important part of my question. How to implement a pub-sub system? (NOTE: I don't want the actual code, I'll manage that myself; just how to go about doing it is where I need some help). The problem is that I get quite boggled when writing the code - what to do how (my confusion is quite apparent from this question itself). Could please provide some references to read or some advice as to how to begin with this thing?
I am not sure if I understood you correctly; but I will summarize how I read it:
We have a real-time chat server that uses socket connections to publish new messages to all connected clients.
We have a database where we want to keep chat logs.
We have also a restful interface to access the realtime server to get current chats in a lazier manner.
And you want to architect your system this way:
In the above diagram, the components I circled with purple curve wants to be updated like all other clients. Am I right? I don't know what you meant with "Data Layer" but I thought it is a daemon that will be writing to database and also interfacing database for other components.
In this architecture, everything is okay in the direction you meant. I mean DataStore is connected by servers to access data, maybe to query client credentials for authentication, maybe to read user preferences etc.
For your other expectation from these components, I mean to allow these components to be updated like connected clients, why don't you allow them to be clients, too?
Your realtime server is a server for clients; but it is also a client for data layer, or database server, if we prefer a more common naming. So we already know that there is nothing that stops a server from being a client. Then, why can't our database system and restful system also be clients? Connect them to realtime server the same way you connect browsers and other clients. Let them enjoy being one of the people. :)
I hope I did not understand everything completely wrong and this makes sense for the question.

Resources