Ejabberd Message delivery while application is terminated

1k views Asked by At

I am developing a chat app using ejabberd server for both IOS and Android. I also wrote a module for ejabberd to get the offline messages sent to my own server api .

my own server api will send notifications to the IOS/Android platforms using FCM.

On the client side , if the application is in the foreground or the background , it will stay connected to ejabberd and if the client receives the message then ejabberd will send the message delivery status.

I am facing an issue while the app is terminated ( service is not running ) which means it is not connected to ejabberd (offline) . if i send a message to this app while it is not terminated , it will receive a notification but the message still undelivered . how can mark the messages as delivered when receiving the notification while the app is terminated.

to explain it more , the same functionality is working fine with whatsapp :

  • device A has whatsapp installed and whatsapp was turned off (terminated)
  • Device B has whatsapp running
  • Device B sends a message to device A
  • Device A receives a whatsapp notification
  • Without doing anything on Device A , the message status on Device B is marked as delivered .

How can I implement this scenario with ejabberd ?

2

There are 2 answers

3
Tareq Assi On BEST ANSWER

In case someone went into this issue , here is the solution that I implemented with help of @Mickaël Rémond from his answer.

  • I configured ejabberd to send the offline messages to an http service ( your own server) please refer to this link for further on how to do it
  • your server should catch the above call and generate a notification message (FCM ) in my case and send it to recipient device
  • recipient device will catch the notification which includes the message
  • recipient device will call http service (your own server backend)that responsible for sending the deliver ack to the original sender . you need to pass from, to , stanzaId , vhost with this call
  • backend server will use ejabberd-api (set of exposed apis to manage ejabberd through rest apis calls) to send delivery message using this api

please note the following notes also :

  • sending the delivery message from your own server to ejabberd will not delete them from ejabberd database
  • if the user re-connected to the ejabberd server then the recipient will receive the message again from ejabberd .
2
Mickaël Rémond On

It is probably too complex for a simple Stack Overflow question, as you need to integrate several moving part on client and server:

  1. You need to execute code in background when receiving push notifications on iOS (you need that property set on your app in your app provisioning profile and have code to handle that). The client will initiate an HTTPS query to let the server know that the message was delivered.
  2. You need to have an endpoint that will get the delivered HTTPS calls and generate either a message ack or a chat marker on behalf of the user and route it in ejabberd.

In real world, this is not enough if you want to take into account the fact that you can only have 1 push in the queue on APNS. If you have several messages sent while the device is not on the network, you will need to have the device check all received messages while offline on the server, otherwise you will lose messaging. You need to rely on XMPP Message Archive Management (MAM) to handle that history.

As you see, this is not a simple few tens of line of codes but need real design and involved work.