-
Notifications
You must be signed in to change notification settings - Fork 2
Remote Notifications Server Requirements
Kristian Berge Nessa edited this page Feb 11, 2023
·
2 revisions
- Google Firebase Cloud Messaging https://firebase.google.com/docs/cloud-messaging
- Have registered user [email protected] for this, and added "music-scool" project
- Usage is completely free for our kind of numbers
- Server key etc. available from https://console.firebase.google.com/u/2/project/music-scool/
- 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)
{"deviceToken": "xyz162chars+", "locale": "dk_DK"}
-
- Authenticated user
- Create or update row in
users_devices
for given user_id+device_token.
{"deviceToken": "xyz162chars+"}
-
- Authenticated user
- Remove row in
users_devices
for given user_id+device_token.
- 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.
- 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.