Problem Statement:
The broadcast message at the app launch will be used in the below following cases for ex -
Examples of use:
1. When Sunbird instance goes down, show a message about (the reason and) when it's going to come back up.
2. When Sunbird instance is going through a lot of issues, a message informing users about what the ongoing activity.
3. A general wishing the user about a festive day (e.g. Happy Diwali, Eid Mubarak, Merry Christmas etc.)
4. There can be other instances as well, where the need for usage of this feature can be used.
Solution:
- The poll based approach was discarded because the app would poll every time an endpoint and check for the status of the system. It was discarded because it does not provide the handy features as provided by FCM, which is discussed in the below point.
- FCM - With FCM there are many advantages which helps to build our requirement in a handy way -
- With FCM users can register and unregister to a topic.
- For our requirement, we can have users by default registered to one topic which can be called as “General”
- And also there can be other topics which users can register based on their needs.
- With FCM we can send messages which can be displayable or non-displayable, which will depend on the flag the payload contains.
- Non-displayable payloads could be for the app side to enable/disable a feature for a particular group of users, could be used for A/B testing.
- Using FCM we can set TTL for a message.
- For the users in the offline state would receive the notification when they come online and won't receive if the TTL is expired.
Caveat:
- If the user registers to FCM after the message has been broadcasted then the new user will not get the notification that was sent before. The solution for this may be, the server can run a cron job for repeatedly sending messages
Post Discussion -
- There will be tenant/channel based topics subscribed by the client.
- By default, all clients subscribe to one topic.
- And below will be the structure of payloads.
Payload for display messages:
{
"actiontype": "display",
"notificationtype": "general/festive/downtime/others",
"notificationid": "1235",
"expiry": "34646millis",
"type": "cancellable/non-cancellable",
"channel": "channel-id",
"poster": "image-url",
"fields": [
{
"language": "en",
"title": "Welcome to Sunbird!",
"msg": "Congratulations on downloading Sunbird, every child's best friend in their learning journey."
},
{
"language": "hi",
"title": "Welcome to Sunbird!",
"msg": "Congratulations on downloading Sunbird, every child's best friend in their learning journey."
}
]
}
Payload for non-display messages:
{
"actiontype": "non-display",
"notificationtype": "enable-feature/disable-feature",
"notificationid": "1235",
"expiry": "34646millis",
"data": "free form string data"
}
Anil Gupta Swayangjit Parida Mathew Pallan