-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |