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

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?

Related

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 offline message push ejabberd

Hi I am developing a chat application using XMPP. Consider the situation in the chat application, When User A send messages to User B and if the User B is offline at that time XMPP will store the sms as offline message and it will send that messages to User B when it comes online. This is working here. But I want to send this offline messages from XMPP as push to User B. I have done lots of searching and I came in a conclusion that we need to send the offline messages from XMPP server to our backend server and from there we need to send that message as push. But how to do this, please help me
It is possible to write a custom module to do that with ejabberd API.
What you need is to use mod_offline_hook (see ejabberd Events and Hooks) to be called when the server wants to store a message in offline store.
You can read mod_offline module for inspiration.

Tracking MUC room list with XMPP (ejabberd)

I'd like to allow a client to keep track of the list of rooms on a multi-user chat service provided by ejabberd. This would require receiving notifications of room creation/destruction and presence events for all rooms on the server.
Is there a way to subscribe to receive notifications about such events without sending a presence event to, and therefore joining the roster of all rooms?
FWIW, I've found out how to send a request for the room list (http://xmpp.org/extensions/xep-0045.html#disco-rooms) and I've been trying to make sense of the pubsub system (http://xmpp.org/extensions/xep-0060.html#glossary) in hope that I'd find a solution there but nothing seems obvious.
What's the right(TM) way to do this in XMPP land?
Ubuntu 10.04 + ejabberd 2.1.5-3+squeeze1 + Strophe.js & BOSH & jQuery
You need to develop custom code for that, especially to trigger packets sending on the event you are interested.

Problem creating a chat room with XMPP in an iOS app

I have an iphone app where I want to use chat rooms. I've installed an XMPP server (ejabberd) and downloaded the XMPP framework for iOS from google code (http://code.google.com/p/xmppframework/). The server and client work as expected, since I'm able to log in and send chat messages between two users.
However, when I try to create a chat room using the createOrJoinRoom method of the XMPPRoom class (in XEP-0045), I don't get any reply from the server and the chat room is not created.
I've debugged to see what kind of package is sent to the server and it looks like this:
<presence from="test2#beta.bogus.net/mynick" to="muumit15#conference.beta.bogus.net">
<x xmlns="http://jabber.org/protocol/muc"/>
</presence>
I get no error message back but the chat room (muumit15) is not created. At the same time I can use e.g. Adium client to create a chat room and it succeeds. The server has been configured so that every user has a right to create chat rooms.
Any ideas? I even tried sniffing the TCP/IP traffic sent by the Adium client but that was encrypted/compressed/binary so I couldn't see what kind of packages it is sending.
See section 7.2.2 of XEP-0045, particularly Example 18:
<presence
from='hag66#shakespeare.lit/pda'
to='coven#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
Note that the to address MUST contain a resource, and yours doesn't. The resource is the string after the /, which is used as your nickname in the room. For more information on the XMPP address format, see RFC 6122.

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.