Hi Guys,
I'm building a module of mine for getting few data from a running ejabberd server. I'd like to get few data from chat history (user or chatroom) and publish it on a web app. I'm currently using mod_mam (xep 0313) with a v16.04 and a PostgreSQL db as backend. mod_mam works fine, history_size is properly set on ejabberd.yml, messages are correctly stored in the db (I can see them as records) and I'm now trying to retrieve them from a module.
I'm aware I can get a chat history with a client, I can:
- use an existing account and enter in a chatroom with it
- issue a command like (PSI here...):
<presence to="test@conference.myserver/test1">
<priority>5</priority>
<x xmlns="http://jabber.org/protocol/muc"/>
</presence>
or use something like:
<iq type='set' id='112233' to='test@conference.myserver'>
<query xmlns='urn:xmpp:mam:1' queryid='f27' />
</iq>
this works when I'm a client or I enter inside that specific room.
In my case I just want to get these msgs from a server module, I'm not an user (client) so I guess I need to use some internal FUNs instead of issuing xmpp commands.
I have also seen topics like this or modules like
How can I get messages (already stored) for my module ?
Thanks in advance
Ben
mod_mam has the function
mod_mam has the function select_and_send that searches in the database the matching messages and directly routes them to the corresponding user. Check what arguments are used inside it, and what is returned (you can add debug lines that print arguments and variables, then trigger that function using a Jabber client, and so you get internal details.
First of all, export the select/5 function adding this line, recompile, reinstall and restart:
Then I can run this call:
and I get this result:
Solved and glad to have a
Solved and glad to have a working solution now.here ) and closed the problem.
I have used your hints reported above and I have figured how can I use SELECT without altering the official tree or exporting other functions from these modules.
I have detected the inner mod_mam_* used to deal with the db (mod_mam_sql in my case) and used it direcly from my code, I have reported details on this topic in the issues available on github as well (
Code is helpful, thanks
Why the select/6 function was
Why the select/6 function was not export by default in mod_mam module? Is there any benefits in use this function instead of access directly the database?