Skip to content
Thanh-Son-Philippe Lam edited this page Apr 29, 2019 · 4 revisions

Push Notifications Process

Notifications for ÉTSMobile are handled through a mix of the following services:

Notification flow image

At it's most basic form, MonÉTS acts as a portal for the various services for the students in ÉTS. Students can receive notifications as well from this service. To do so, when a notification is received in MonÉTS, the service saves it in it's web application but also sends it through AWS SNS. SNS then sends the message to the user's device based on it's platform.

Glossary

Term Definition
FCM Registration Token Token used by FCM to communicate on a given application instance for a device.
Platform Application Application registered on SNS where the message from MonÉTS will get sent to.
Platform Endpoint ARN used to define a device that will get notifications.
Data Message Message retrieved by FCM but handled by a client app instead of Firebase itself.

Why using AWS SNS

Historically, ÉTSMobile was developped on iOS, Android and Windows Phone. Because handling notifications for 3 different platforms would prove itself difficult since each platforms has it's caveats, it was easier at the time to consider a unified solution that could send a message to the required platform. Even though Windows Phone is no longer developped and solutions like FCM can work on iOS/Android, if it's not broken, don't fix it! 👍

Device registration/Retrievement process

This feature is nice in theory but how can we get this working on a given device? It can get a bit difficult to understand at first so below is a high level view explaining the registration flow for Android using FCM. We're assuming that the same process could be applicated to iOS using both APNs and FCM as well. The process is also explained over in the AWS documentation.

Notification registration and retrivement FCM

  1. When ÉTSMobile is run for the first time, Firebase generates a registration token which identifies and authenticates a given device for the application.

  2. Once a user is authenticated into ÉTSMobile, the registration token is sent over AWS SNS where it is being stored to a platform application. A platform endpoint for the device is also created at this time. Personal information not used by AWS can be stored in the platform. (In this case, the student ID is kept for further usage)

  3. If correctly configured, the platform application notifies a topic with a message that contains it's information everytime a platform endpoint is created, modified, and deleted. A AWS Simple Queue Service (SQS) queue is subscribed to the topic and thus saves the message for further usage.

  4. Internally, a process from ÉTS reads the messages from the SQS queue and saves the platform endpoint to a given student profile inside MonÉTS. (Using the student ID that has been saved earlier when registering the device)

  5. When a notification is available for a student on the web portal, MonÉTS also creates a request that sends the notifications's content to all SNS platform endpoints it has saved for the given student.

  6. Based on the platform endpoint, SNS sends a request containing the message for the notification to FCM based on the registration token it has saved.

  7. Finally, FCM delivers the message. A notification is created and is shown on screen. (Shown later if the device isn't connected, etc...)

Note: This process happens whenever a new token is generated and not only on first login.

Message structure

Even though some services might need a payload for sending the message. Note that FCM parses a message from SNS as a data message. Below is an example of the structure for a message when it is parsed and received in a JSON format:

{  
   "DossierId":0,
   "Id":1234567,
   "NotificationApplicationNom":"Signets",
   "NotificationTexte":"Cours PEP110. Élément «Présence-participation cours 1». Note publiée : 1 sur 1",
   "Url":"https://signets-ens.etsmtl.ca?portail\u003d1234567"
}
  • DossierId: The id of the student. So far, it always returns a value of 0
  • Id: The id of the notification itself.
  • NotificationApplicationNom: The name of the application that sent the notification. Since MonÉTS acts as a broker, it is normally the name that will appear in the web portal
  • NotificationTexte: The actual content of the notification
  • Url: The URL which can be used to redirect the user to the content of the notification.

Implementation

Android

In order to implement this correctly, you will need the AWS SNS SDK as well as the Firebase SDK. We're assuming that a platform application and a Firebase project are also created. For App|ETS members, a platform application for production and development purposes are available. Please check with ÉTS if that's not the case so they can configure it for you.

It can be hard to get everything right the first time so ÉTSMobile 2.x has an implementation available. Note that some stuff might get deprecated by the time you read this so you might want to search for the things that have been replaced.

MonÉTS

For App|ETS club members, a document is available internally explaining how the notification integration works between MonÉTS and AWS. If there are some parts that you do not understand, you might want to ask directly your questions over to the staff there since they have direct access to the systems.

Testing

Once you want to verify if everything works correctly, you will probably want to try everything from the AWS console. It is also possible to test a notification in FCM, but it won't simulate the situation as much since a message is going through SNS before going to FCM. This procedure assumes you have access to a AWS console with permissions to SNS. In order to send a test notification:

  1. Connect to the AWS console. Go to the SNS section.
  2. Select the platform application corresponding to the application. (For this case, we'll use the development one for the club)
  3. If you device has been successfully registered, you should see it's token alongside it's endpoint ARN.
  4. Select the application and click on "Publish Message".
  5. Since we want to send a message to FCM, select the second option "Custom payload for each delivery protocol". (See the image below for to be sure)
  6. Based on the example message above, put the string below in the text field:
{
  "GCM": "{ \"data\": { \"DossierId\":0, \"Id\":1234567, \"NotificationApplicationNom\":\"Signets\", \"NotificationTexte\":\"Cours PEP110. Élément «Présence-participation cours 3». Note publiée : 1 sur 1\", \"Url\":\"https://signets-ens.etsmtl.ca?portail\u003d1234567\"} }"
}
  1. Press on "Publish Message"
  2. Enjoy! 🎉