Push notifications

Send Things5 event notifications to browsers and native mobile apps through Firebase Cloud Messaging

Things5 can send push notifications to the user's browsers and to native mobile apps (iOS and Android) when a device raises an event the user has subscribed to. Delivery goes through Firebase Cloud Messaging (FCM): your app gets a token from Firebase and registers it with Things5, and Things5 sends the notifications to every registered device of the user.

How it works

  1. The user chooses which events of a device model they want to be notified about (see Event notifications).
  2. Your app gets an FCM registration token from the Firebase SDK and registers it with Register push device.
  3. When a device raises one of those events, Things5 sends a push notification to the user's registered devices on the platforms the user has enabled.

Firebase setup

Tokens are tied to the Firebase project that generated them, so your app must be configured with the Things5 Firebase project: tokens from any other project are rejected by FCM. Contact Things5 to register your app (Android package name, iOS bundle ID) and to get its google-services.json / GoogleService-Info.plist.

🚧

iOS

Use the Firebase Messaging SDK and register the FCM token it returns, not the raw APNs device token. Push delivery to iOS also needs your app's APNs authentication key (.p8) to be uploaded to the Firebase project: send it to Things5 together with your bundle ID.

Getting the token

PlatformSteps
AndroidAsk for the POST_NOTIFICATIONS permission (Android 13+), then read FirebaseMessaging.getInstance().token. FirebaseMessagingService.onNewToken() is called when the token changes.
iOSAsk for permission with UNUserNotificationCenter.requestAuthorization, call registerForRemoteNotifications(), then read Messaging.messaging().token or implement messaging(_:didReceiveRegistrationToken:).
Flutter / React NativegetToken() and onTokenRefresh from firebase_messaging / @react-native-firebase/messaging.

Token lifecycle

WhenCall
App start or loginRegister push device with platform and user_agent. You can use Check push device first.
Firebase rotates the tokenRegister the new token and unregister the old one.
User logs outUnregister push device, then delete the token in the Firebase SDK so the next user on the same device gets a new one.
User manages their devicesList push devices and Update push device to rename a device or turn it off.

The token goes in the URL path: URL-encode it, since it may contain :.

Who receives a notification

A device receives a notification when all of these hold:

  • the user is subscribed to that event for the device model (Event notifications);
  • the channel for the device's platform is enabled on the user: web_notifications_enabled for web devices, mobile_notifications_enabled for ios and android devices (see Current user update);
  • the device itself is enabled (Update push device).

Notification content

The notification title and body are already translated into the user's language. The data payload carries:

KeyDescription
machine_idID of the device that raised the event. Use it to open the device screen when the user taps the notification.
machine_nameName of the device
event_nameName of the event, translated into the user's language