Skip to content

Commit 70fd4f4

Browse files
authored
feat: add schema for interaction payloads (#1001)
1 parent 5b2aef2 commit 70fd4f4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

frontend/app/api/webhook/slack/route.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ export async function POST(req: NextRequest): Promise<Response> {
3636
}
3737

3838
const data = SlackWebhookRequestSchema.parse(payload);
39-
if (data.type === "url_verification") {
40-
return NextResponse.json({ challenge: data.challenge });
41-
}
4239

43-
if (data.type === "event_callback") {
44-
const { event, team_id } = data;
45-
await processSlackEvent({ event, teamId: team_id });
46-
return NextResponse.json({ ok: true }, { status: 200 });
40+
if ("type" in data) {
41+
if (data.type === "url_verification") {
42+
return NextResponse.json({ challenge: data.challenge });
43+
}
44+
45+
if (data.type === "event_callback") {
46+
const { event, team_id } = data;
47+
await processSlackEvent({ event, teamId: team_id });
48+
return NextResponse.json({ ok: true }, { status: 200 });
49+
}
4750
}
4851

4952
return NextResponse.json({ ok: true }, { status: 200 });

frontend/lib/actions/slack/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,12 @@ export const SlackSlashCommandSchema = z.looseObject({
8787
is_enterprise_install: z.string().optional(),
8888
});
8989

90-
export const SlackWebhookRequestSchema = z.union([SlackUrlVerificationRequestSchema, SlackEventCallbackSchema]);
90+
export const SlackBlockActionsSchema = z.object({
91+
payload: z.string(),
92+
});
93+
94+
export const SlackWebhookRequestSchema = z.union([
95+
SlackUrlVerificationRequestSchema,
96+
SlackEventCallbackSchema,
97+
SlackBlockActionsSchema,
98+
]);

0 commit comments

Comments
 (0)