Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Integrate FCM with Ejabberd?

Environment:

Ejabberd Version : 16.04

Smack-android-4.1.0

I have created an Android chat application with a XMPP server. However due to Google play permission issue I had to narrow down the feature from app which supported receiving incoming message notifications when the app is in the background.

As an alternative I received the following suggestion from GooglePlay Review Team.

Once you’ve removed this permission, you might consider using Firebase Cloud Messaging (FCM) if your app’s message delivery requires a temporary exemption from battery optimization. Please set high priority only if the message is time-critical and requires the user’s immediate interaction, and be aware that setting your messages to high priority contributes to more battery drain compared to normal priority messages

So at the moment users can send messags via the app. But when he close the app, he will be considered as an offline user, and will not receive any notifications from app. When he opens the app again, he will get all the offline messages those were saved the Ejabberd server.

I want to enhance the current app so that even though a user had closed the app he will still receive a notification when some one sends a message to him (Similar to whatsapp)

  1. Is there a module in ejabberd which integrates the server with FCM and handles this?

  2. If we can not achieve this by Ejabberd, is there a 3rd party library to support this?

  3. If not do we have to write an Erlang module from scratch?

I found similar questions in the internet but I could not find any working solution. Since I am not much experienced with Erlang and would be glad to hear your solutions/ideas on this. Thanks in advance.

like image 769
B378 Avatar asked Oct 15 '22 16:10

B378


1 Answers

This can be achieved in Ejabberd with offline_message_hook. This hook is trigger when sending a message to the receiver and receiver in an offline state. So create a custom module using this hook and you can send a push notification to FCM and APNs servers. Refer this blog -- https://jasonrowe.com/2011/12/30/ejabberd-offline-messages/

like image 106
Sujan Kumar Sakthi Avatar answered Nov 01 '22 10:11

Sujan Kumar Sakthi