Send XMPP message without starting chat

I basically write an XMPP client to automatically respond to specific specific messages.

My setup is this:

I have pidgin installed on my machine, configured to work with the x@xyz.com account.
I have my own jabber client configured to work with the same account x@xyz.com .
There may be other XMPP clients .

Here is my requirement:

I am trying to automate certain messages that I receive on gtalk. Therefore, whenever I receive a specific message, for example: "How are you", my own XMPP client should respond automatically, saying "fine". "How are you". All messages sent (before and after my client’s response) to x@xyz.com , but must be received by all clients (my own client does not have a user interface and it can only reply to specific messages.).

Now I have already encoded my client for an automatic response. It works great. But the problem that I encountered is that as soon as I reply (I use the smack library), all subsequent messages sent to x@xyz.com are only accepted by my XMPP client. This is obviously a problem, since my own client is pretty dump and does not have a user interface, so I do not see other messages sent to me, thereby making me "lost" messages.

I have observed the same behavior with other XMPP clients. Now the question is whether this is an XMPP requirement (sorry, but I did not read the XMPP protocol too well). Is it possible to encode an XMPP client to send a response to the user and still be able to receive all subsequent messages for all clients that are currently listening to messages? Providing the client with a full-fledged XMPP client is a solution, but I do not want to go this route.

Hope my question is clear.

+4
source share
1 answer

You may need to set a negative presence priority for your bot.

First of all, you need to know that in XMPP, each client must have a full JID. This is a simple JID - in your case x@xyz.com with a resource at the end, for example. x@xyz.com / pidgin or x@xyz.com / home (where / pidgin and / home are the resource). This is part of the assumption that routing messages for different clients will be reached.

Then there are the stanzas present. When accessing the Internet, the client usually sends a presence gate to the server. This is reported, for example, if the client is available for chat or for lunch. Along with this information, you can send priority. When more than one client is connected, the one with the highest priority will receive messages sent to the bare JID (for example, ClientA (prio = 50) and ClientB (prio = 60) β†’ ClientB receives messages sent by x xyz com). But there are also negative priorities. A priority of less than 0 indicates that this client should never send any messages. Such a stanza might look like this:

<presence from=" x@xyz.com /bot"> <priority>-1</priority> </presence> 

This may fit your case. Remember that this also depends on the XMPP server where your account is located, which may or may not have fully implemented this part of the protocol.

So, to summarize: I recommend that you look at the Smack API, how to set presence and set priority <0 for your bot client immediately after it is connected.

+5
source

All Articles