Skip to main content
This page is part of Example app: a full OneSignal integration, which follows one real app from end to end. The app is Clean Beans, a cleaning rota for shared homes, built with Expo (React Native) and a Supabase backend. Most Clean Beans notifications are sent by the backend, because they depend on a schedule or on something another person did. All of them call the same endpoint, Create message, and target people by External ID.
Clean Beans push notifications

An example of some of the pushes that Clean Beans sends.

Scheduled sends that respect time zones

People choose the hour they want their daily reminder. Clean Beans does not schedule one job per user. It runs one job every hour and asks, “for whom is it that hour right now?”
1

A database schedule calls a function every hour

pg_cron makes an HTTP request to a Supabase Edge Function. The service key it needs is read from Supabase Vault, so it never appears in the SQL.
2

The function finds the users whose local hour matches

It loads everyone who has that reminder switched on, converts the current time to each user’s time zone, and keeps the ones whose chosen hour is now.
3

It checks there is something to say

A user with nothing due gets no push.
4

It calls OneSignal once per user

Each push has its own content, so each is a separate request.
The schedule:
supabase/migrations/006_cron_daily_digest.sql
The time zone match:
supabase/functions/send-daily-digest/index.ts
The send:
supabase/functions/send-daily-digest/index.ts
The ...DELIVERY.daily_digest, idempotency_key, and badge fields are explained in Reliable, well-behaved push. The data.type field is how the app knows which screen to open when the push is tapped. See Deep links and notification clicks. The heading and body are built from the tasks, so the push says something specific.
supabase/functions/send-daily-digest/index.ts

The overdue reminder: a second, different nudge

The overdue reminder reuses the same pattern with two changes. It fires six hours after the user’s digest hour, and it only counts tasks that are strictly past due.
supabase/functions/send-overdue-reminders/index.ts
Its job runs at half past the hour, so it never competes with the digest job at the top of the hour. The copy is different too. A second reminder that repeats the first is easy to ignore.
supabase/functions/send-overdue-reminders/index.ts

The cleaning reminder: one request for many people

The cleaning reminder says the same thing to everyone, so it does not need one request per person. The function collects every eligible user ID and sends them in batches.
supabase/functions/send-cleaning-reminder/index.ts
Send one request per person when the content differs. Send one request for many people when it is identical. Fewer requests means fewer things to fail and less to stay inside rate limits.

Session completed: a push triggered from the app

When someone finishes a cleaning session, the rest of the household hears about it. The app cannot send that push itself, because it must not hold an API key. It calls a backend function and the function sends the push.
src/lib/database.ts
The request says what was cleaned, but not who cleaned it. The function reads who is calling from their sign-in token, checks they are an active member of the household, and takes their name and avatar from their profile. See Check who is calling. It then finds the other members of the household and removes anyone who has this type of push switched off.
supabase/functions/session-completed/index.ts
It sends one push to all of them. The sender’s bean avatar is attached as an image, using a different field for each platform.
supabase/functions/session-completed/index.ts
An expanded push notification showing a bean avatar image

A session-completed push, expanded to show the sender's avatar.

Kudos: one person to another

Kudos work the same way, with a single recipient. On the activity screen, a member taps Send Kudos on a housemate’s session, picks a message, and the app calls the send-kudos function.
The kudos bottom sheet with preset messages

Choosing a kudos message for a housemate's cleaning session.

supabase/functions/send-kudos/index.ts

Join approved: a push triggered by the database

Someone who asks to join a household waits for an admin to approve them. When that happens, their membership row changes from pending to active. A database trigger on that change calls a function, and the function tells them they are in. Putting the trigger in the database means the push is sent however the approval happens, and the app needs no code for it.
supabase/migrations/027_join_approved_trigger.sql
The function does not trust what it is told. It reads the membership again and only sends if the approval is real and recent.
supabase/functions/join-approved/index.ts
A function that sends messages on request is something other people can try to call. Check the facts in your own database before sending, as this one does, and never accept message content or recipients from a caller you have not verified.

Check who is calling

Supabase verifies that a request to an edge function carries a valid token, but a signed-in user’s token is as valid as the scheduler’s. Without a further check, any user could trigger the daily digest for everyone, or send a push in someone else’s name. Each function therefore decides for itself who is allowed to call it. The scheduled functions start with one line:
supabase/functions/send-daily-digest/index.ts
supabase/functions/_shared/auth.ts
The role check relies on Supabase having already verified the token’s signature. Deploy these functions with JWT verification on, which is the default. Never deploy them with --no-verify-jwt.
Functions called from the app identify the sender from the token, then check that the sender is allowed to reach the recipient. Kudos can only go to someone who shares a household with the sender, and the name shown in the push is read from the sender’s profile.
supabase/functions/send-kudos/index.ts

Create message API

Targeting, content, and scheduling for every channel.

Rich media

Images in push notifications on each platform.