muc offline messages
What is the recommended way to implement push notifications (e.g. trigger some webservice) to offline users? In my use case, I've got members-only rooms where I want to be able to send messages, and if the message is not delivered right away (because the user is offline, network flaky, etc), Ejabberd should trigger a webservice that dispatches the message as a push notification (Android, iOS, ...).
How would I approach this?
p.s. I don't know any Erlang, otherwise I would have attempted to write a plugin or something....
Also, this might be interesting approach, what do you guys think?
https://github.com/ChatSecure/ChatSecure-Push-Server/blob/master/docs/v3/README.md
Why don't you use a hook to listen for offline messages and to call a script that sends notifications using any library of your choice?
@nunohorta I've worked with an offline message hook already, but it doesn't work with MUC afaik. In an open MUC room, where there are no 'fixed members', I understand the irrelevance of offline messages, but in my scenario, I only have rooms where there are specific members, that need to be notified if they're not online.
@dirkmoors MUC are indeed presence based. It is indeed not designed to care of offline users. The XMPP Standards Foundation started thinking about what is call MUC2, that would make it possible in a clean way.
To be frank, we have done thing for customers but nothing we have the right to share yet. However, we are willing to work actively on the MUC2 approach and have it implemented by following closely the XEP progress.
@mremond Aren't there any plugins available that are able to trigger a webservice (containing message + offline members), when a message is delivered into a muc room, and not all members are online?
Not that I know of. However, it should be easier to write with the new muc_message_filter API. However, this trigger is unrelated to the fact that members in the member list are online or not. You would have to do the check in the code before triggering any remote call if you wish to.
@dirkmoors Okay now I understand what you need. I'm actually working on something similar. I've barely started but my idea is to use the new muc_message_filter like @mremond said above. I will also be listening for presence changes on chat rooms(https://github.com/processone/ejabberd/commit/6e61932765f9ae8e290b88cce5c2ed574fb4bbe7), thank you @weiss ! This will work, I hope, because I do all the management of users and chat rooms on my server using php and the ejabberd_xmlrpc module, meaning that the server knows which users are members in each chat room. When a message is sent to a group, I call a script that checks offline users "in" that group and sends push notifications. This will be used in groups with around 50 people max. I believe that this should not affect the server with performance issues.
@nunohorta that is probably what I need too. My use case is similar, but I'll be managing the users from within a Django (python) application, via XMLRPC (actually, I've written an open source python library for that purpose: https://github.com/dirkmoors/pyejabberd). Are you implementing an erlang-based plugin? Or how do you anticipate implementing this feature?
@dirkmoors That looks really good! I'm using a php library that I developed myself but can't share unfortunately because it's part of a software that is not mine. To be more specific I'll listen to presence changes and chat room messages with modules that I developed. Those modules send a post request to a url in my system that caches online/offline users and sends notifications to their devices when offline. The other data I have it stored on a database because I developed a backend to manage user connections and chat rooms with a nice interface. This also runs on php and uses the xmlrpc API to call Ejabberd methods
@nunohorta Yeah I did something similar: the exact approach I tried was running a 'bot' (I've used SleekXMPP, a Python library) that connects to all the rooms to listen to the messages and presence, and updates the local database accordingly, sending push notifications to offline room members. I'm afraid that this approach is not scalable (I have no idea how much MUC rooms this 'bot' can process simultaneously)
@nunohorta it might be easier for you to read StateData right from muc_message_filter - which will give you online occupants for "right now". So that list of online users +
thanks @EugeneNews ! I hope to start this over the week. It seems like a good solution!
@EugeneNews could you help using the muc_message_filter? How can I read the body from Stanza argument? This is what I have so far https://gist.github.com/nunohorta/fd8ecf46267deef16d86 . If you could help that would be great.
@nunohorta i'm doing it with mapping list of users
_LISTUSERS = lists:map(
fun({_LJID, Info}) ->
binary_to_list(Info#user.jid#jid.luser) ++ ".."
end,
dict:to_list(MUCState#state.users)),
?DEBUG(" ######### GROUPCHAT _LISTUSERS = ~p~n ####### ", [_LISTUSERS])
you see, I'm using ".." as a separator in the string, because i like to send all users as just 1 parametor in POST request. But if advance fun() you may get LIST/array to convert it to smthn you need...
:8ball: I have the same question.
Is there anyone willing to implement an (open source) Ejabberd plugin that -once a MUC room has MEMBER affiliations- simply triggers a REST/webservice, notifying which MEMBERS are offline, and which message did not get to them. I think a lot of developers would benefit from such a plugin?
If needed I can explain in more detail.
@dirkmoors I think better approach is never to go offline. Client developers should be encouraged to implement XEP-0198. I also do not understand the dance around affiliations. Have you ever seen MUC rooms with 1000 members in the list? Your REST/webservice will die during notifications.
@zinid In many usecases, you're talking of less members. Think intranet chat application, friend-groups, etc. In those usecases, I think it would make perfect sense to notify a webservice?
Moreover, never going offline seems hard in mobile environments, which by nature do not provide stable connectivity?
Moreover, never going offline seems hard in mobile environments, which by nature do not provide stable connectivity?
Actually with XEP-0198 you can be always online. XEP-0198 will transparently resume your session during re-login.
That sounds very interesting! I'm going to look into that XEP definitely.
Nevertheless; triggering a webservice to notify about offline room members would make (mobile) push notifications to mobile devices very straightforward to implement. Or would you suggest another approach to achieve this?