Design – When to send a push notification to a chat app

designnotifications

I want to add push notifications to an chat application I am working on.

Initially I thought that I should write business logic to detect that a message wasn't delivered and then attempt to send the notification for the unread message. If a user's online presence is detected, I can skip the push notification call.

However, after doing some research, I discovered this answer from a support engineer at PubNub.

The answer states that they don't really care whether the subscription is active, they just send GCM/APNS requests for all messages.

The publisher does not know or care whether subscribers are active (foreground) or inactive (background or not running at all – kill state) on the device. Publisher always publishes the message with a GCM (and possibly APNS) payload.

Active apps will receive both and will prevent the display of the push notification via the OS's push msg receiver listener.

Inactive apps will receive only the push notification and display that. When end user taps the push msg, it will open the app where you can get the missed message and display the full content in your app's UI.

If I understand correctly, this would display a notification if the app is in the background and trigger a method (didReceiveRemoteNotification iOS, ??? Android) if the app is open. I could then choose to display a local notification depending on my own logic.

Is this good design or do chat applications generally make more effort to detect if a message was delivered before falling back to push notifications?

Best Answer

I have used ejabberd chat server (Used by WhatsApp) in one project. Team have implemented notification functionality in the following manner :-

For offline User case

  • If chat message can't be delivered because user is offline, we pushed that message to notification queue (RabbitMQ)
  • Notification service will pick notification from this queue and push it to device (Android/iOS).

User receive's push notification, touch it and go inside app to perform defined action.


If user is connected to chat server, chat library will receive message on handler and app itself can generate required notification in this case.

You can send push notification using Amazon SNS service or can also integrate GCM and APNS.

Design wise Notification Queue makes chat and push notification asynchronous. So it is easy to pick notification and send using Notification service. There could be other ways to do this but better not to put conditions/processing in flow of chat message. It will introduce extra delay in message delivery.

Hope this will help.

Related Topic