You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use Firebase currently for the easy of handling multi platform notifications: is this planned ( I could not find mention of it ) and otherwise, is it something that could be considered as a future feature?
Reacted by Fabian Mossberg, Hosein Haqiqian, Thomas, Constantin (Cleo) Winkler, hemanth Kumar, xiki808, Paurakh Sharma Humagain, Curetix, Eung Jin Lee and Lilith Ikki Engelmeier
Reacted by Hosein Haqiqian, Constantin (Cleo) Winkler, hemanth Kumar, xiki808, Madhur Gupta, Paurakh Sharma Humagain, Sylvanus Kateile, Eliot Boutherin and Lilith Ikki Engelmeier
This is a great feature and there are a lot of opportunities to bring a lot of value to Supabase in push notifications. Here are some details about push notifications:
How Push Notifications Work
Both Android/iOS have a need to quickly push notifications and data to the devices from a server-initiated event. To avoid multiple apps constantly polling for new data/notifications, both platforms have implemented a single connection between the device and a server that apps can use to send push notifications/data. Android uses Firebase Cloud Messaging (FCM) and iOS uses Apple Push Network (APNS). Huawei devices use their own service called HMS Push Kit. FireOS devices use Amazon SNS.
You can not implement your own reliable push notification system without using the FCM/APNS connection between Apple/Google's server and the device. Firebase/APNS must be used. This is because iOS/Android regulates the background services that would be required on the device to establish such a connection when an app is not in the foreground. (example: if the developer is doing everything right, at best iOS will run a background service with an interval of 15 minutes)
On some Android devices it is slightly possible to make your own ongoing background service, however, as you can see here (https://dontkillmyapp.com) Android is very fragmented in how it handles background services. Google is also making Android increasingly more strict for background services. It is not a viable solution to implement it all yourself.
When using the firebase client libraries, FCM (serverside) will forward push notifications to APNS. FCM tries to act as a single source you need to tell to push to all your devices.
Some Downsides to FCM/APNS
APNS stores only the most recent notification per device and per app. If a device is offline, sending a notification request targeting that device causes the previous request to be discarded. If a device remains offline for a long time, all its stored notifications in APNS are discarded. (FCM stores all notifications for a max of ~4 weeks when proper attributes are set)
Neither FCM/APNS provides a delivery status. If Firebase has the correct analytics configuration, after 24 hours push delivery status is available through Big Query (not helpful programmically). The message a server gets when pushing to a device is only an indication that FCM/APNS successfully received the request to push to the device. This is a place where Supabase could provide a lot of value.
Moving Forward
The scope of this feature could be very small or incredibly vast, but that depends on Supabase and what they choose.
I would like to mention a temporary using procedure functions and http extension for postgres with them i was about to send pushes using triggers on a table called notifications, for anyone who is struggling with this until workflows come out, here is an example how you can do this:
first create a trigger on your table:
create trigger notification_inserted
after
insert
on notifications FOR EACH ROW EXECUTE PROCEDURE on_notification_created();
on_notification_created basically, construct some data and eventually call this method below::
create
or replace function send_push(
push_token text,
title text,
body text,
ref_id uuid,
creator_id uuid,
n_type text
) returns void as $$
SELECT
status,
content
FROM
http(
(
'POST',
'https://fcm.googleapis.com/fcm/send',
ARRAY [ http_header(
'Authorization',
'key=myawesomekey'
),
http_header('Content-Type', 'application/json') ],
'application/json',
(
select
get_fcm_body(
push_token,
title,
body,
ref_id,
creator_id,
n_type
)
)
) :: http_request
);
$$ language sql;
and here is the message that construct the json object
create
or replace function get_fcm_body(
push_token text,
title text,
body text,
ref_id uuid,
creator_id uuid,
n_type text
) returns json AS $$
declare
notification json;
n_data json;
begin
notification := json_build_object(
'title', title,
'body', body,
'clickAction', 'FLUTTER_NOTIFICATION_CLICK',
'sound', 'default',
'tag', ref_id::text
);
n_data := json_build_object(
'title', title,
'body', body,
'type', n_type,
'refId', ref_id,
'creatorId', creator_id::text
);
return json_build_object(
'to', push_token,
'notification', notification,
'data', n_data
);
end;
$$ language plpgsql;
I hope this help everyone facing such issue and wants to use one service for everything.
Reacted by Christian, Andreas K., Eung Jin Lee, Anders Barfod and Eliot Boutherin
Would also be great to be able to run the requested push notification feature in a LAN and without the need of the internet. This is especially helpful for smart home solutions, and many other cases.
Activity
tannermeade commentedon Jun 10, 2021
This is a great feature and there are a lot of opportunities to bring a lot of value to Supabase in push notifications. Here are some details about push notifications:
How Push Notifications Work
Some Downsides to FCM/APNS
Moving Forward
k0shk0sh commentedon Jul 28, 2021
I would like to mention a temporary using procedure functions and http extension for postgres with them i was about to send pushes using triggers on a table called notifications, for anyone who is struggling with this until workflows come out, here is an example how you can do this:
first create a trigger on your table:
on_notification_createdbasically, construct some data and eventually call this method below::and here is the message that construct the json object
I hope this help everyone facing such issue and wants to use one service for everything.
xiki808 commentedon Oct 26, 2021
Would also be great to be able to run the requested push notification feature in a LAN and without the need of the internet. This is especially helpful for smart home solutions, and many other cases.