From 60681cf87a7ba6f9dc8051ee8f11138b98c7493e Mon Sep 17 00:00:00 2001 From: Logan Ford <110533855+Logannford@users.noreply.github.com> Date: Wed, 11 Dec 2024 22:37:24 +0000 Subject: [PATCH 1/5] create base slack edge function --- .../slack_send-daily-question/index.ts | 29 +++++++++++++++++++ .../slack_send-daily-question/readme.md | 4 +++ 2 files changed, 33 insertions(+) create mode 100644 supabase/functions/slack_send-daily-question/index.ts create mode 100644 supabase/functions/slack_send-daily-question/readme.md diff --git a/supabase/functions/slack_send-daily-question/index.ts b/supabase/functions/slack_send-daily-question/index.ts new file mode 100644 index 000000000..d2aaccde1 --- /dev/null +++ b/supabase/functions/slack_send-daily-question/index.ts @@ -0,0 +1,29 @@ +// Follow this setup guide to integrate the Deno language server with your editor: +// https://deno.land/manual/getting_started/setup_your_environment +// This enables autocomplete, go to definition, etc. + +console.log("Hello from Functions!") + +Deno.serve(async (req) => { + const { name } = await req.json() + const data = { + message: `Hello ${name}!`, + } + + return new Response( + JSON.stringify(data), + { headers: { "Content-Type": "application/json" } }, + ) +}) + +/* To invoke locally: + + 1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start) + 2. Make an HTTP request: + + curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/slack_send-daily-question' \ + --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ + --header 'Content-Type: application/json' \ + --data '{"name":"Functions"}' + +*/ diff --git a/supabase/functions/slack_send-daily-question/readme.md b/supabase/functions/slack_send-daily-question/readme.md new file mode 100644 index 000000000..bf2b958a6 --- /dev/null +++ b/supabase/functions/slack_send-daily-question/readme.md @@ -0,0 +1,4 @@ +To update this edge function: + +- ensure docker is running on your desktop +- `supabase functions deploy slack_send-daily-question From 7b69069c9561c89d84c6e66f8be6638b93f456d9 Mon Sep 17 00:00:00 2001 From: Logan Ford <110533855+Logannford@users.noreply.github.com> Date: Wed, 11 Dec 2024 22:59:49 +0000 Subject: [PATCH 2/5] playing around with edge function --- src/app/(marketing)/page.tsx | 11 +++ .../slack_send-daily-question/index.ts | 71 ++++++++++++++++--- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/app/(marketing)/page.tsx b/src/app/(marketing)/page.tsx index 8b6c3b0cd..fd7dc1182 100644 --- a/src/app/(marketing)/page.tsx +++ b/src/app/(marketing)/page.tsx @@ -6,11 +6,22 @@ import HomepageHero from '@/components/marketing/homepage/hero/hero'; import HomepageHeroImages from '@/components/marketing/homepage/hero/hero-images'; import HomepageLargeText from '@/components/marketing/large-text'; +import { supabase } from '@/lib/supabase'; + import posthog from 'posthog-js'; export default async function AuthedPage() { posthog.capture('page_view', { page_name: 'Landing Page' }); + const { data, error } = await supabase.functions.invoke( + 'slack_send-daily-question' + ); + + console.log({ + data, + error + }); + return (