Push
Push notifications for Android, iOS, and web through FCM and APNS, with your app's credentials.
Push goes out through your credentials: FCM (Firebase Cloud Messaging) delivers to Android and the web, and APNS (Apple Push Notification service) to iOS. It reaches only the devices your app has registered, and it doesn’t count toward the email and SMS daily limit.
1. Set up FCM
Section titled “1. Set up FCM”- In the Firebase console, open your app’s project (or create one and add the Android or web app).
- Under Project settings → Service accounts, click Generate new private key. A
.jsonfile is downloaded. - In Owbase: Messaging → Providers → New provider → FCM, give it a name and choose the file.
The console reads the file in the browser and checks that it belongs to a service account (type: "service_account", with project_id, private_key, client_email, and token_uri). After you choose it, the screen shows only the project and the account’s email; the private key is never displayed.
2. Set up APNS
Section titled “2. Set up APNS”- In Apple Developer, under Certificates, Identifiers & Profiles → Keys, create a key with Apple Push Notifications service (APNs) and download the
AuthKey_<KEY ID>.p8file (Apple only lets you download it once). - In Owbase: New provider → APNS, choose the
.p8(the Key ID comes from the file name) and enter the Team ID (under Membership details, in Apple Developer) and the app’s App bundle ID. - Turn on Apple test environment (sandbox) for development builds installed through Xcode; off applies to TestFlight and the App Store.
Several push providers can be enabled at the same time, for example one FCM and one APNS. When editing, leave the file and fields blank to keep the saved credential; to replace it, upload the file again. There is no test send in the console: push only reaches a registered device.
3. Register the device in the app
Section titled “3. Register the device in the app”With the user signed in, the app gets the device token from the platform’s push SDK and registers it as a push target with account.createPushTarget, saying which provider delivers it. On the web, the token comes from the Firebase web SDK, with the firebase-messaging-sw.js service worker published at the site root. For a topic, the app subscribes its own target.
import { Account, ID, Messaging } from '@owbase/web';import { client } from './client';
const account = new Account(client);const messaging = new Messaging(client);
// The token comes from the platform's push SDK: on Android and web, Firebase Cloud Messaging's getToken (on web, with the// firebase-messaging-sw.js service worker published at the site root); on iOS, the APNS device token.declare function deviceToken(): Promise<string>;
// With the user signed in: registers the device as a push target of the right provider (the provider ID in the console).// A session keeps one target per provider: calling again updates the same target instead of creating another.const target = await account.createPushTarget({ targetId: ID.unique(), identifier: await deviceToken(), providerId: 'fcm-android' });
// To receive the pushes of a topic, the app subscribes its own target to it.await messaging.createSubscriber({ topicId: 'news', subscriberId: ID.unique(), targetId: target.$id });
// FCM rotates the token from time to time: update the target when the push SDK notifies you.await account.updatePushTarget({ targetId: target.$id, identifier: await deviceToken() });
// On sign-out, delete the target so the device stops receiving this user's push.await account.deletePushTarget({ targetId: target.$id });Each user’s devices appear in the console under Auth → Users → user → Devices (push), with the provider and the registration date. Remove takes the device out of future messages; for it to receive again, the app must register the device again (with account.createPushTarget).
4. Send from the console
Section titled “4. Send from the console”Under Messaging → New push:
- Title and text, with a preview beside them of how it looks on Android and iOS (the app name is the project’s);
- recipients: topics (by total push subscribers), users (all of their devices), or devices chosen one by one;
- image: a PNG or JPEG from a Storage bucket in the project (sent as
<bucket>:<file>); - tap action: the link or deep link the app opens;
- extra data: up to 20 key → value pairs delivered to the app (without FCM’s reserved keys:
from,notification,message_type,collapse_key, and those starting withgoogleorgcm); - sound, badge (the number on the icon, on iOS), and priority (high delivers immediately; normal lets the system wait to save battery);
- silent: delivered in the background so the app can refresh, without showing anything to the user; title and text become optional and priority becomes normal (Apple requires this for update-only push).
As with email and SMS, you can send now, schedule (Brasília time), or save as a draft. In a saved draft, the title, text, action, sound, and image already stored can’t be cleared (the server keeps the saved value, and the screen warns you); to remove one, create a new push. The badge and extra data can be cleared. The message detail shows the options, the recipients, the delivered count, and the delivery errors as FCM or APNS returned them.
5. Send through the API
Section titled “5. Send through the API”import { ID, MessagePriority, Messaging } from '@owbase/node';import { client } from './client';
// Scopes: providers.write and messages.write.const messaging = new Messaging(client);
// FCM (Android and web): the Firebase service account JSON, as an object (here, kept in an environment variable).await messaging.createFCMProvider({ providerId: 'fcm-android', name: 'Android', serviceAccountJSON: JSON.parse(process.env.FCM_SERVICE_ACCOUNT ?? '{}'), enabled: true });
// APNS (iOS): the text of the .p8 key, the Key ID, the Team ID and the app's Bundle ID. sandbox: true for development builds.await messaging.createAPNSProvider({ providerId: 'apns-ios', name: 'iOS', authKey: process.env.APNS_AUTH_KEY ?? '', authKeyId: 'ABC123DEFG', teamId: 'DEF123GHIJ', bundleId: 'com.example.app', sandbox: false, enabled: true,});
// Push to a topic, with an image from Storage (<bucket>:<file>, PNG or JPEG), an action on tap and extra data (text).await messaging.createPush({ messageId: ID.unique(), title: 'Order out for delivery', body: 'Arrives today by 6 pm.', topics: ['news'], image: 'banners:delivery', action: 'myshop://orders/123', data: { order: '123' }, badge: 1, priority: MessagePriority.High,});
// Silent: no title or text; the app receives the data in the background (for example, to sync).await messaging.createPush({ messageId: ID.unique(), users: ['<USER_ID>'], contentAvailable: true, data: { sync: 'orders' } });The image must be PNG or JPEG; any other type is refused. The token in the image URL that the server stores is valid for 15 days from the send (or from the scheduling).