FlutterFlow push notifications with OneSignal and Supabase

I want to extend the work of Thomas Henry Johnson if you want to know how to set OneSignal with FlutterFlow check out his post (https://community.flutterflow.io/discussions/post/onesignal-integration-for-notifications---notifications-for-supabase-yd2c5sa4jzoQr1W)

this is the edge function code for push notification

import { createClient } from "https://esm.sh/@supabase/[email protected]";

// ! onesignal
const url = "https://onesignal.com/api/v1/notifications";

const headers = new Headers();
headers.append("Authorization", "Basic your_ONESIGNAL_REST_API_KEY");
headers.append("Content-Type", "application/json");

// ! supabase
const supabaseUrl = "your_SUPABASE_URL";
const supabaseKey = "your_SUPABASE_KEY";
const supabase = createClient(supabaseUrl, supabaseKey);


Deno.serve(async (req) => {
  const payload = await req.json();

  try {
    // this is my OrderProducts table id
    const ID: Int16Array = payload.record.OrderID;
    // call a database function to get data
    const { data, error } = await supabase.rpc("get_new_buy", {
      id: ID,
    });

    // set up data for push notification
    const bodyData = {
      // put the list of your supabase user id in here to push notifications to them
      // change this line to included_segments: ["Total Subscriptions"], if you want to send to all your users
      include_external_user_ids: ["afad0729-16fc-4549-9428-0359aeb07b21"],
      app_id: "your_ONESIGNAL_APP_ID",
      headings: { en: "New Order" },
      contents: { en: "We have a new order" },
    };

    const body = JSON.stringify(bodyData);

    const requestOptions = {
      method: "POST",
      headers: headers,
      body: body,
    };

    //! send push notification when INSERT to table
    await fetch(url, requestOptions)
      .then((response) => {
        if (!response.ok) {
          throw new Error(`HTTP error! Status: ${response.status}`);
        }
        return response.json();
      })
      .then((data) => {
        console.log(data);
      })
      .catch((error) => {
        console.error("Error:", error);
      });

    return payload;
  } catch (err) {
    console.error(err);
  }
});

to set up the webhook with this edge function and how to send broadcast push notification check out this YouTube video that I found (https://youtu.be/DJaFai5hJn8?si=SKZEeyEza2razGPY)

3
2 replies