How can I inform an XMPP sender of other clients sending messages on the sender's behalf? - xmpp

I'm building a chat service that supports connectivity over the web as well as XMPP. Assume we have two users, Alice and Bob, chatting with each other over the web interface. Alice is simultaneously logged via web and XMPP. If Bob sends a message to Alice, she sees the message in both clients, but if she replies via the web, the XMPP client ends up with a one-sided conversation: Alice's messages won't be part of the chat history, but Bob's messages will continue to arrive.
Is there any way in XMPP to inform a sender that a different client sent a message on the sender's behalf, to keep the conversations synchronized?

Get your server vendor to implement XEP-0280: Message Carbons. Then you'll need to turn it on in your client.

Related

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.

How does the persistence work in XMPP?

I'm trying to understand the differences between AMQP and XMPP and among other things I don't really understand if XMPP works like it had Queues.
When you send a message to various clients what happen if one of them is down? The server enqueues the message up to the client is up again or how does it work?
Thanks
It depends on the XMPP server implementation how messages and iq's are handeld when the JID is offline. Section 11.1 of RFC 3921:
Else if the JID is of the form and there are no
available resources associated with the user, how the stanza is
handled depends on the stanza type:
...
For message stanzas, the server MAY choose to store the stanza on
behalf of the user and deliver it when the user next becomes
available, or forward the message to the user via some other means
(e.g., to the user's email account). However, if offline message
storage or message forwarding is not enabled, the server MUST return
to the sender a stanza error. (Note: Offline
message storage and message forwarding are not defined in XMPP, since
they are strictly a matter of implementation and service
provisioning.)
For IQ stanzas, the server itself MUST reply on behalf of the user
with either an IQ result or an IQ error. Specifically, if the
semantics of the qualifying namespace define a reply that the server
can provide, the server MUST reply to the stanza on behalf of the
user; if not, the server MUST reply with a
stanza error.

How to send XMPP Message with a given From or ReplyTo?

I would like to initiate a Chat between two users A and B from my web application. So I create an XMPP Message using Smack Client API or directly from an OpenFire Plugin:
Send a Message by Smack from A to B
Send a Message by Smack from Server to B with replyTo A
XEP-0033 allow "replyTo address" supported by OpenFire but not suported by IM Clients.
It seems "from" can't be overrided by a client or an OpenFire plugin. I also think GTalk will not accept an xmpp message from userA#gmail.com to userB#gmail.com by ServerToServer protocol.
Is there an other way to do this ? I want my web application to forge a message from UserA to UserB. But this webapp is not A or B.
Best Regards,
Jp
Any XMPP server should ignore the from address in a stanza and stamp the one that it get's from the connection into the stanza it sends on. This is a specific feature of XMPP compliant servers and is used to stop address spoofing and spam etc. You'd probably have to edit the source of a server and change it's behaviour. This is dangerous though and I wouldn't reccomend it if you'll be federating with other servers.
J

In Google Talk, how to send a message to person that is not in my friend list?

In Google Talk, how to send a message to person that is not in my friend list?
I work on an application that notify customers of a bank about change of their accounts. When I send a message to a person not in my list, no error is created, but the message isn't delivered to the recipient.
Because of design issues it is not suitable to send an invitation to customers and store information about their responses to it.
You can message a user directly using XMPP without an active presence subscription (the requirement for an item to appear in your roster), but most clients (Google Talk clients included AFAIK) will discard the message upon reception, if the from header does not match a bare JID in their roster.

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.