Supabase Functions for Gumloop integration using Edge Functions
##Explanation:
Trigger and Function: The SQL code creates a trigger that calls the notify_generate_pdf_change function whenever the generate_pdf column is updated. If the new value is true, it sends a notification on the generate_pdf_channel with the proposal ID.Edge Function: The edge function listens for notifications on the generate_pdf_channel. When it receives a notification, it logs the proposal ID and can send data to Gumloop (you’ll need to implement the actual integration logic).[https://pkjljvknmdozvzwnwprq.supabase.co/functions/v1/watch-generate-pdf]supabase functions download watch-generate-pdf
Edge Function for generate_pdf boolean
Copy
import "jsr:@supabase/functions-js/edge-runtime.d.ts";import { createClient } from "jsr:@supabase/supabase-js@2";const supabaseUrl = Deno.env.get('SUPABASE_URL')!;const supabaseAnonKey = Deno.env.get('SUPABASE_ANON_KEY')!;const supabaseClient = createClient(supabaseUrl, supabaseAnonKey);const listenForGeneratePdfChanges = async () => { const { data, error } = await supabaseClient .from('generate_pdf_channel') .on('INSERT', payload => { const proposalId = payload.new.id; // Send data to Gumloop here console.log(`Gumloop flow triggered for proposal ID: ${proposalId}`); // Implement your Gumloop integration logic here }) .subscribe(); if (error) { console.error('Error subscribing to changes:', error); }};Deno.serve(async (req: Request) => { await listenForGeneratePdfChanges(); return new Response('Listening for changes on generate_pdf...', { headers: { 'Content-Type': 'text/plain' }, });});