Skip to main content

Overview

MechZie uses Firebase Cloud Messaging (FCM) for push notifications with Fast2SMS as an SMS fallback. All notifications are also stored in-app for retrieval via the API.

Setting Up Push Notifications

Register FCM Token

On app startup and whenever the FCM token refreshes, register it with the API:
Call this on every app launch. The server tracks last_used_at and automatically prunes stale tokens. If you don’t re-register, the token may be cleaned up and the user will stop receiving push notifications.

Listen for Token Refresh

Listing Notifications

Fetch in-app notifications (paginated):
Response:

Marking as Read

Mark a single notification

Mark all as read

Notification Triggers

These events generate notifications for the relevant user:

Customer Notifications

Mechanic Notifications

Notification Data Payload

The data field contains structured data for deep-linking. Use it to navigate the user to the relevant screen:

Delivery Channels

Reliable Push Delivery (Inline-first with Fallback)

To ensure mechanics receive job offers instantly without delay, the API uses a two-stage delivery mechanism:
  1. Inline Send (Stage 1): When a job is dispatched, the API attempts to send the FCM push notification inline with a strict 1-second timeout. If Firebase accepts the message within this window, the delivery is complete.
  2. Queue Fallback (Stage 2): If the inline send times out or fails, a BullMQ job is enqueued immediately. The background worker attempts to reclaim and deliver the notification. It retries up to 3 times using exponential backoff (retry 1 at +2s, retry 2 at +4s).

FCM Payload Priority

For critical notifications (like job_offer):
  • Android: Priority is set to high with a TTL of 30 seconds.
  • iOS (APNs): apns-priority is set to 10 with expiration set to 30 seconds.
  • Background Prefetching: APNs payload includes content-available: 1 to allow background state updates/pre-fetching of job data before the user taps the alert.
Push notifications and Socket.io events often carry the same information. Socket.io is for real-time UI updates while the user is active. Push notifications reach users when the app is in the background. In-app notifications serve as a persistent history.

Unread Badge Count

The API doesn’t have a dedicated unread count endpoint, but you can calculate it from the notification list:
For a proper unread count, fetch the first page and count items where is_read == false. Consider caching this and updating it when you mark notifications as read.