Skip to content

Commit fcfba70

Browse files
committed
slack support
1 parent 0bee3e5 commit fcfba70

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

.env.example

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NOTION_DATABASE_ID='3adeaad843ae4b81a4bd25c004c50593'
2-
NOTION_API_KEY='secret_JSduilTNwrYNaF9yntGYBnGpC2x960lMZK8l6zibNH3'
3-
ABOUT_PAGE='842ef29054f24e7a91eeb0755ad0c6a8'
1+
NOTION_DATABASE_ID=
2+
NOTION_API_KEY=secret_JSduilTNwrYNaF9yntGYBnGpC2x960lMZK8l6zibNH3
3+
SLACK_WEBHOOK=

app/page.tsx

+34-8
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,54 @@ import { Article } from "@/lib/types";
33
import { postsPerPage } from "@/site";
44
import Feed from "@/components/Feed";
55
import HeroSection from "../components/HeroSection";
6+
import axios, { AxiosResponse } from 'axios';
67

8+
interface SlackMessage {
9+
text: string;
10+
}
711

12+
const sendSlackMessage = async (message: SlackMessage): Promise<AxiosResponse> => {
13+
const slackWebhookUrl = process.env.SLACK_WEBHOOK;
14+
15+
if (!slackWebhookUrl) {
16+
throw new Error('Slack webhook URL is not defined.');
17+
}
18+
19+
return await axios.post(slackWebhookUrl, message);
20+
};
821

922
const HomePage = async ({
1023
searchParams,
1124
}: {
12-
searchParams: { [key: string]: string };
25+
searchParams: { [key: string]: string | undefined };
1326
}) => {
1427
const page = Number(searchParams.page) || 1;
1528
const publishedPosts: Article[] = await getAllPosts();
16-
// const startIndex = (page - 1) * postsPerPage;
17-
// const endIndex = startIndex + postsPerPage;
18-
// const postsToShow = publishedPosts.slice(startIndex, endIndex);
1929

30+
// Send a message to Slack when the page is accessed
31+
const message: SlackMessage = {
32+
text: `Someone visited the homepage! Page: ${page}`,
33+
};
34+
35+
try {
36+
await sendSlackMessage(message);
37+
} catch (error: unknown) {
38+
if (error instanceof Error) {
39+
console.error('Error sending Slack message:', error.message);
40+
// Handle the error as needed
41+
} else {
42+
console.error('An unexpected error occurred:', error);
43+
// Handle other types of errors or log them
44+
}
45+
}
2046

2147
return (
2248
<>
2349
<div className="">
24-
<HeroSection />
25-
<div className = "mt-4 max-w-5xl m-auto p-4 min-h-screen">
26-
<Feed articles={publishedPosts} />
27-
</div>
50+
<HeroSection />
51+
<div className="mt-4 max-w-5xl m-auto p-4 min-h-screen">
52+
<Feed articles={publishedPosts} />
53+
</div>
2854
</div>
2955
</>
3056
);

package-lock.json

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@notionhq/client": "^2.2.13",
1313
"@radix-ui/react-avatar": "^1.0.4",
1414
"@radix-ui/react-slot": "^1.0.2",
15+
"axios": "^1.6.5",
1516
"class-variance-authority": "^0.7.0",
1617
"clsx": "^2.0.0",
1718
"lucide-react": "^0.294.0",

0 commit comments

Comments
 (0)