0

We want to use ejabberd in the context of a web application having fairly unique and business rules, we'd therefore need to have every chat message (not protocol message, but message a user sends to another one) go through our web application first, and then have the web application deliver the message to ejabberd on behalf of the user (if our business rules allow the message to be sent).

The web application is also the one providing the contact lists (called rosters if I understand correctly to ejabberd). We need to be and remain the single source of truth to ease maintenance.

To us, ejabberd value added would be to deliver chat messages in near real-time to clients, and enable cool things such as presence indicators. Web clients will maintain a direct connection to ejabberd through websocket, but this connection will have to be read-only as far as chat messages are concerned, and read-write as far as presence messages are concerned.

The situation is similar with regards to audio and video calls. While this time the call per see will directly be managed by ejabberd to take advantage of built-in STURN, TURN etc... and will not need to go through our web app, we have custom business logic to manage who is able to call who, when, how often etc... (so in order words, we have custom business logic to authorize the call or not and we'd like to keep all the business logic centralized in the web app).

My question is what would be the proper hooks we'd need to look into to achieve what we are after? I spent an hour or so in the documentation, but I couldn't find what I am after so hopefully someone can provide me pointers. In an ideal world, we'd like to expose API endpoints from our web app that ejabberd hooks can hit. However, the first question is: which relevant hooks is ejabberd offering and where are these hooks documented?

Any help would be greatly appreciated, thank you!

Samuel
  • 37
  • 5

1 Answers1

1

When a client sends a packet to ejabberd, it triggers the user_send_packet hook, providing the packet and the state of the client's session process. Several modules use that hook, for example mod_service_log.

Badlop
  • 3,840
  • 1
  • 8
  • 9
  • Thank you for your help, so your answer is that we would need to write a custom module – Samuel Jul 31 '21 at 19:21
  • which relevant hooks is ejabberd offering and where are these hooks documented? <-- I replied to that question. – Badlop Aug 02 '21 at 10:32
  • your answer is that we would need to write a custom module <-- If you want to use ejabberd hooks, then obviously you use them writting an ejabberd module, either in Erlang or in Elixir – Badlop Aug 02 '21 at 10:33
  • Thanks, I am new to ejabberd so obvious things are not obvious yet for me :D Is there a way to achieve this without using hooks? I am not looking to use hooks specifically, I was using the term in the general sense of "extensibility point". If we can avoid needing to learn a new technology stack (Erlang/elixir) this would great. – Samuel Aug 02 '21 at 22:17
  • 1
    A dirty dirty solution: write a XMPP chatbot (in any language you want, Python, Perl, whatever), your users send messages to him, he performs your business stuff, and then forwards the message to the destination. – Badlop Aug 04 '21 at 08:44
  • 1
    The clean way, as I said, is to write an ejabberd module that intercepts every stanza, calls your business API to decide if stanza can pass or not. You can use mod_filter to start with: https://github.com/processone/ejabberd-contrib/tree/master/mod_filter – Badlop Aug 04 '21 at 08:45