Skip to content

Remote Notifications Server Requirements

Kristian Berge Nessa edited this page Feb 11, 2023 · 2 revisions

Platform

Data Model

  • New table (users_devices) to store FCM tokens for each user's logged in devices (can be several per user)
    • user_id
    • device_token (200 char string)
    • locale (for supporting multiple languages later)
    • timestamp (timestamp of last use, for deleting old devices)

New endpoints

/v1/registerDevice

  • {"deviceToken": "xyz162chars+", "locale": "dk_DK"}
    • Authenticated user
  • Create or update row in users_devices for given user_id+device_token.

/v1/removeDevice

  • {"deviceToken": "xyz162chars+"}
    • Authenticated user
  • Remove row in users_devices for given user_id+device_token.

App behaviour

  • The app invokes registerDevice when the user logs in, opens the app, or deviceToken/locale changes.
  • The app invokes removeDevice when the user logs out.
  • If the app is uninstalled, phone is lost, etc... Nothing is sent, so will probably need to have a job to clean out this table.

Backend behaviour

  • It is now the responsibility of the backend to send notifications.
  • Laravel Tutorial: https://www.positronx.io/laravel-send-web-push-notification-using-firebase-tutorial/
    • Tutorial suggests adding device_key to users table, but better have a separate table to support multiple devices.
  • Implement scheduled job to run on fairly frequent intervals (every 30 minutes?)
    • Figure out what users to send notifications to based on upcoming lessons.
    • Call the Google FCM REST API to send each message to each client device based on users_devices.
  • If desired, can also add UI to send custom messages to selected (or all) users.