Kosh
07/28/2021, 11:59 AMTrigger:
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;
I believe this is worth mentioning as alot of who is switching from firebase will definitely want this until workflow is implemented.
happy supabase'ing.