How can I get the timestamp of a XMPP chat message that's sent to Hubot? - xmpp

I'm using an Openfire server to support Jabber chat between Spark clients. I want to use GitHub's Hubot to monitor chatrooms and listen for users to send messages to Hubot, then log the messages. I'm having a hard time figuring out how I can get the timestamp of the message from the point of view of the Openfire server... is this even possible or should I just use the system time of the system running Hubot?

Use the system time of the receiving process. Only messages that were stored before you join a room will have timestamps with the server time.

Related

How can I create multiple independent conversations between two users in XMPP Server?

I want to create a chat where multiple independent conversations can be created between two users in my XMPP Server (MongooseIM).
I tried to do it with threads but it does not work since when I log in if the user has messages offline, the server marks the messages as read. Or if I send a message to the other user, the server marks all messages as read.
Do you think it would be the solution to use MUC?, or can I do it without using MUC?

How can I get last message of each conversation(per JIDs) from openfire?

I'm developing an instant messaging app on android with SMACK library that uses OPENFIRE as a xmpp server. I want to get last message of each conversation from MessageArchiveManager in openfire server that was enabled by MONITORING SERVICE plugin(based on XEP-0313).
I know that mamManager.queryArchive() can gets the messages that related to specific jid or can get a specific number of messages that exists in server(with no custom sepration), but we suppose that smack doesn't knows which JIDs has conversation on server!
One solution is that send request per each ROSTER entry, but it has heavy cost when it contains numerous contacts and perhaps we have a conversation with anybody out of Roster. Is there any way or plugin or another extension to do this?

Openfire XMPP Bot over Channels

I am using Openfire as an XMPP server for building a customer support Bot framework.
I am planning to make use of channels/groups for the same. I am keen to use channels as there might be multiple human agents and a bot listening to the same conversation. So I am likely to have a group/channel for each individual.
I want the messages to be read and processed by my custom server. How do I go about this ? I couldn't find any plugin that allows me to intercept the messages and return back processed response.
Any recommendations ?
You can also create your an own openfire bot plugin if you are familiar with Java (small example: https://rmsol.de/2018/03/06/Openfire_Bot/). Otherwise create bot as a client lilke dontknow suggested (The "bot/client" will join every channel you like and e.g. listen for specific keywords)
I figured out that since Openfire is an XMPP Communication software, its best to just use a custom XMPP client ( on your own server ) to listen to all the messages and process it from there and reply back from the XMPP Client as well.
So if I have a Nodejs server, I will create a Node XMPP Client and listen to XMPP messages coming via Openfire from other users, will process them and reply back with custom messages which Openfire will send back to the user.

XMPP Duplicate message handling in MUC

Is it possible to add server timestamp in the messages sent by the ejabberd server ? This will help in synchronizing the Server and Client clock times. I am facing difficulties in trying to retrieve the message history in an MUC chat.
Scenario:
Lets say that the Server time is T100 and that the client's clock is 10 seconds behind the server time(Lets call this time T90).
At T100, the server sends an message M1 to the client. The client receives this message at time T90(Clients local time).
Next the client goes offline and tries to rejoin the group. The client requests for all messages after time T90 (since the last received message M1 was received by client at T90).
The server sends M1 back to the client again because M1 has an timestamp of T100.
Thanks,
MAM messages have ids. You can use those ids to paginate in archive, retrieve messages and undupe.

Send XMPP message without starting a chat

I am basically writing a XMPP client to automatically reply to "specific" chat messages.
My setup is like this:
I have pidgin running on my machine configured to run with an account x#xyz.com.
I have my own jabber client configured to run with the same account x#xyz.com.
There could be other XMPP clients .
Here is my requirement:
I am trying to automate certain kind of messages that I receive on gtalk. So whenever I receive a specific message eg: "How are you" , my own XMPP client should reply automatically with say "fine". How are you". All messages sent (before and after my client replies) to x#xyz.com but should be received by all clients (my own client does not have a UI and can only respond to specific messages.).
Now I have already coded my client to reply automatically. This works fine. But the problem I am facing is that as soon as I reply (I use the smack library), all subsequent messages that are sent to x#xyz.com are received only by my XMPP client. This is obviously a problem as my own client is quite dump and does not have a UI, so I don't get to see the rest of the messages sent to me, thereby making me "lose" messages.
I have observed the same behavior with other XMPP clients as well. Now the question is, is this is a requirement of XMPP (I am sorry but I haven't read XMPP protocol too well). Is it possible to code an XMPP client to send a reply to a user and still be able to receive all subsequent messages in all clients currently listening for messages? Making my client a full fledged XMPP client is a solution, but I don't want to go that route.
I hope my question is clear.
You may have to set a negative presence priority for your bot..
First thing to know is that in XMPP protocol every client is supposed to have a full JID. This is a bare JID - in your case x#xyz.com with a resource in the end e.g. x#xyz.com/pidgin or x#xyz.com/home (where /pidgin and /home are the resource). This is a part of how routing messages to different clients is supposed to be achieved.
Then there are the presence stanzas. When going online a client usually sends a presence stanza to the server. This informs about e.g. if the client is available for chat or away for lunch. Along with this information can be sent a priority. When there are more than one clients connected the one with the highest priority will receive the messages sent to the bare JID (e.g. ClientA(prio=50) and ClientB(prio=60) -> ClientB receives the messages sent to x#xyz.com). But there are also negative priorities. A priority less than 0 states that this client should never be sent any messages. Such a stanza might look like this
<presence from="x#xyz.com/bot">
<priority>-1</priority>
</presence>
This may fit your case. Please keep in mind it also depends on the XMPP server where your account is located, which may or may have not fully implemented this part of the protocol.
So to summarize: I recommend you to look through the Smack API how to set a presence and set the priority to <0 for your bot client right after it connected.