Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack integration #264

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ model Waitlist {
}

model Users {
uid String @id()
uid String @id @default(cuid())
email String @unique
username String?
firstName String?
Expand All @@ -68,6 +68,45 @@ model Users {
streak Streaks?

roadmaps UserRoadmaps[]

workspaceOwner Workspaces[] @relation(name: "WorkspaceOwner")

workspaceUsers Workspaces[] @relation(name: "WorkspaceUsers")

WorkspaceUsers WorkspaceUsers[]
}

model Workspaces {
uid String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

name String
description String?
ownerUid String
owner Users @relation(fields: [ownerUid], references: [uid], onDelete: Cascade, onUpdate: Cascade, name: "WorkspaceOwner")

users WorkspaceUsers[]

@@unique([name, ownerUid])
Users Users[] @relation(name: "WorkspaceUsers")
}

model WorkspaceUsers {
uid String @id @default(cuid())
workspaceUid String
workspace Workspaces @relation(fields: [workspaceUid], references: [uid], onDelete: Cascade)
userUid String
user Users @relation(fields: [userUid], references: [uid], onDelete: Cascade)
role UserRole @default(MEMBER)

@@unique([workspaceUid, userUid])
}

enum UserRole {
ADMIN
MEMBER
VIEWER
}

model Subscriptions {
Expand Down
11 changes: 11 additions & 0 deletions src/app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="overflow-x-hidden">
<div className="z-30">
Expand Down
4 changes: 2 additions & 2 deletions src/components/global/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export default function Logo() {
<path
d="M101.712 6.37639L104.572 2.00075C104.844 1.58474 105.491 1.77732 105.491 2.27435V5.26249C105.491 5.31772 105.536 5.36249 105.591 5.36249H107.576C107.983 5.36249 108.22 5.82365 107.982 6.15442L105.172 10.0611C104.889 10.4553 104.266 10.2548 104.266 9.76917V7.24999C104.266 7.19476 104.222 7.14999 104.166 7.14999H102.13C101.733 7.14999 101.494 6.70894 101.712 6.37639Z"
fill="#5A5FCD"
fill-opacity="0.82"
fillOpacity="0.82"
stroke="#5A5FCD"
stroke-width="0.5"
strokeWidth="0.5"
/>
</g>
<defs>
Expand Down
85 changes: 85 additions & 0 deletions supabase/functions/slack_send-daily-question/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { createClient, type SupabaseClient } from '@supabase/supabase-js';
import { corsHeaders } from '../_shared/cors.ts';

// 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) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders });
}

// get today's date
const today = new Date();

// get the day of the week
const day = today.getDay();

// if today is Sunday or Saturday, return
if (day === 0 || day === 6) {
return new Response("It's the weekend! No daily question today.");
}

// get the current time
const time = today.getHours();

// if it's before 9am, return

try {
const supabase = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{
global: {
headers: { Authorization: req.headers.get('Authorization') ?? '' }
}
}
);

const { data, error } = await supabase
.from('Questions')
.select('uid, correctAnswer')
.eq(questionDate, today.toISOString().split('T')[0])
.single();

if (error) {
throw error;
}

if (!data) {
throw new Error('No question found for today');
}

return new Response(JSON.stringify(data), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200
});
} catch (error) {
console.error(error);
}

// 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"}'

*/
4 changes: 4 additions & 0 deletions supabase/functions/slack_send-daily-question/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To update this edge function:

- ensure docker is running on your desktop
- `supabase functions deploy slack_send-daily-question