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

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

Related

Is there an ejabberd module that sends stanzas using webhooks?

I want to make it easy for people to write bots for my ejabberd server by allowing them to register webhooks with their bot JIDs. Basically, I want them to be able to interact with my ejabberd server using HTTP to send and receive XMPP stanzas instead of having to maintain persistent XMPP connections. For example, the bots could simply make HTTP calls to my ejabberd server to send XMPP stanzas, and then the server would send messages to the bots by making HTTP calls to the registered webhooks. This would allow the bots to be simple HTTP servers that could easily scale horizontally.
I did find this module (https://github.com/adnam/ejabberd-webhooks) but it doesn’t seem to do exactly what I want and also it doesn’t seem to be maintained. Is there a well-maintained (maybe official) ejabberd module that does this? Maybe there is an XEP I’m not aware of that ejabberd implements? Are there other XMPP servers that support this? Thank you in advance!
the bots could simply make HTTP calls to my ejabberd server to send XMPP stanzas,
You can do this installing mod_rest in ejabberd:
https://github.com/processone/ejabberd-contrib/tree/master/mod_rest
and then the server would send messages to the bots by making HTTP calls to the registered webhooks.
I am not aware of any simple module to do this. There are Push XEPs, see https://xmpp.org/extensions/xep-0357.html but I think ejabberd Community Server does not implement everything required, only the Business Edition.

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.

Is it possible to listen/monitor messages send from a user to an another on Openfire Server using Smack API?

is it possible to listen / monitor messages send from a user to an another on Openfire Server using Smack API
No, that would be a privacy violation, because it would mean that a third party is able to intercept and read messages between two JIDs.
Of course, you can modify any XMPP server to relay certain XMPP stanzas to a third party. But since there is no XEP that defines a API for such a mechanism, it's also not available in Smack.

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.