diff --git a/.env.sample b/.env.sample index 797a524..d922b01 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,8 @@ DATABASE_URL= expoProjectId= +SLACK_WEBHOOK_URL= EXPO_PUBLIC_SUPABASE_URL= EXPO_PUBLIC_SUPABASE_ANON_KEY= EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY= +GOOGLE_SERVICES_IOS=./GoogleService-Info.plist +GOOGLE_SERVICES_ANDROID=./google-services.json diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 7d76321..65d4da6 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -30,6 +30,7 @@ jobs: run: bun build:web env: EXPO_PUBLIC_SUPABASE_URL: ${{ secrets.EXPO_PUBLIC_SUPABASE_URL }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} EXPO_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.EXPO_PUBLIC_SUPABASE_ANON_KEY }} EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY }} expoProjectId: ${{ secrets.expoProjectId }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 67066d0..6c453b1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,7 @@ jobs: run: bun build:web env: EXPO_PUBLIC_SUPABASE_URL: ${{ secrets.EXPO_PUBLIC_SUPABASE_URL }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} EXPO_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.EXPO_PUBLIC_SUPABASE_ANON_KEY }} EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY }} expoProjectId: ${{ secrets.expoProjectId }} diff --git a/app.config.ts b/app.config.ts index e7cb1e3..ad3e82c 100644 --- a/app.config.ts +++ b/app.config.ts @@ -72,7 +72,7 @@ export default ({config}: ConfigContext): ExpoConfig => ({ 'expo-splash-screen', { image: './assets/icon.png', - backgroundColor: '#343434', + backgroundColor: '#333333', imageWidth: 200, }, ], diff --git a/src/apis/postQueries.ts b/src/apis/postQueries.ts index 02b284d..855e58e 100644 --- a/src/apis/postQueries.ts +++ b/src/apis/postQueries.ts @@ -2,6 +2,7 @@ import {SupabaseClient} from '../hooks/useSupabase'; import {ImageInsertArgs, PostInsertArgs, PostWithJoins} from '../types'; import {PAGE_SIZE} from '../utils/constants'; import {sendNotificationsToAllUsers} from './notifications'; +import {sendSlackNotification} from './slackQueries'; const filterDeletedImageInPost = (post: PostWithJoins): PostWithJoins => { return { @@ -288,6 +289,11 @@ export const fetchCreatePost = async ({ images, }; + sendSlackNotification({ + post: post as unknown as PostWithJoins, + url: `https://forums.crossplatformkorea.com/post/${data.id}`, + }); + sendNotificationsToAllUsers({ title: post.title, body: post.content, diff --git a/src/apis/slackQueries.ts b/src/apis/slackQueries.ts new file mode 100644 index 0000000..121101f --- /dev/null +++ b/src/apis/slackQueries.ts @@ -0,0 +1,40 @@ +import {Post} from '../types'; + +const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL; + +console.log('SLACK_WEBHOOK_URL:', SLACK_WEBHOOK_URL); + +const truncateText = (text: string, maxLength: number) => { + if (text.length > maxLength) { + return text.slice(0, maxLength) + '...'; + } + return text; +}; + +export const sendSlackNotification = async ({ + post, + url, +}: { + post: Post; + url: string; +}) => { + const payload = { + text: `*${truncateText(post.title, 50)}*\n\n${truncateText(post.content, 200)}\n\n<${url}|자세히 보기>`, + }; + + try { + const response = await fetch(SLACK_WEBHOOK_URL, { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + console.error('Slack notification failed:', response.statusText); + } else { + console.log('Slack notification sent successfully!'); + } + } catch (error) { + console.error('Error sending Slack notification:', error); + } +};