How to get ejabberd server response messages for Rest API calls - xmpp

I am trying to make use of ejabberd REST API calls by following this -
https://docs.ejabberd.im/developer/ejabberd-api/. I would like to do things like publishing to pubsub nodes or sending messages to clients by directly calling the APIs from a program or script.
I have configured the ejabberd server and tested ok with curl and Postman. Now, I would like to know if one can get detailed status messages of the API calls from the server back to the caller (program or script). Currently, the server only returns status codes of 0 for success and 1 otherwise for many of the calls.
In some cases, the API call may succeed but error may occur (for example, error in stanza). In the ejabberd debug logs, we can see the server replies back to the sender with iq stanzas with type=result or error. However, if the sender is not an XMPP client such as Postman or a Python script, the sender will have no way to receive it. Sure, we can use another XMPP client's JID in the "from" field but then we need to maintain an XMPP client and let it run all the time which we don't want.
Thanks for any advice.

Related

How to receive message stanza without sending self presence?

I am using mongooseim with Android and Ios application. I just want to receive message from the server from background without sending self presence to anyone because this task is done by system. But I can't receive message stanza until I send my presence to the mongooseIM.
Do I missing something or there is a way by which I can get quick update from MongooseIM server in the background without sending presence?
As far as I understand you all you want to do is sync the messages when you receive a Push Notification. MongooseIM can be configured to serve a simple HTTP API with which you can get archived messages (mod_mam needs to be enabled) without establishing the XMPP connection. More details can be found in the HTTP API doc, especially the Swagger doc regarding get messages. Let me know if this suites you.

Using XMPP for Request Response

I would like to know if is it possible to get XMPP messages sent by mobile client applications in my PHP Back end server?
The PHP Back end server will process the messages (JSON request) and send responses back to the client mobile apps. There will be 5 million client application users sending messages to server simultaneously.
Well you can use XMPP but definitely for that, you will need alot of changes.
Your mobile clients will send data in XMPP packets (message or iq) and you will have to handle those stanzas and parse them to get the data (which can be JSON).
So, Yes you can use XMPP but you need to have such skills (both on client side and on server side).

Programmable/scriptable mail server

I have the following scenario:
Users send email messages to the special mail addresses (each address is associated with a user).
When the message arrives to the server I need to extract a certain information from the message body and store it in the database.
I am looking for a mail server (or client) that matches following conditions:
Free/open-source
Users/inboxes can be created/deleted via some API on the fly
Works in unix/mac environment (Ubuntu/MacOS X in my case)
Allows me to set up hooks on message queue (via API or receive the data via some I/O channel)
Has good performance and/or scalability potential
Does not have a dependency on Java or other heavy framework.
Note that I do not need a full-fledged mail server i.e. all I need is messages processing.
Finally, I decided to use http://mailgun.net/ service which provides exactly what I need

Strophe & Ejabberd: problem with reauthentication after sending message

Im using Strophe attach method to connect to ejabberd (2.1.6) with external authentication. Everything works fine after attaching, but when I'm trying to send a message stanza to some user, that user does not recieve his message. Message stanza is stored in spool table in database. I don't know why the message isnt delivered directly to the user.
The only thing I see in ejabberd log is that after sending message ejabberd is testing user to whom I sent the message with external isuser call, and after that ejabberd reauthenticates me.
I don't know if that reauthentication is normal thing or there's something out there that I do wrong.
Do any of you had this type of problem before? If so, how did you managed to solve it?
Is it the sender that is getting reauthenticated? If so, it's possible that you're sending XML that is not well-formed, and the server is disconnecting you.
It appears that there was a problem with my app and htaccess file which sent all requests to index.php if the resource was not a directory or a file, which caused my app to once again run GET request if there was an image that did not exist on server, but was included in html.
And because I was connecting to ejabberd on every request (except for ajax) reauthentication was taking place.
Than you for your interest.

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.