Skip to content

Commit 7038063

Browse files
feat(slack): add logging for Slack webhook middleware (#2366)
1 parent 433ad6b commit 7038063

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

apps/api/src/middleware/slack.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,32 @@ export const verifySlackWebhook = createMiddleware<{
99
slackTimestamp: string;
1010
};
1111
}>(async (c, next) => {
12+
console.log("[slack middleware] Starting verification");
13+
1214
if (!env.SLACK_SIGNING_SECRET) {
15+
console.log("[slack middleware] SLACK_SIGNING_SECRET not configured");
1316
return c.text("slack_signing_secret_not_configured", 500);
1417
}
1518

1619
const signature = c.req.header("X-Slack-Signature");
1720
const timestamp = c.req.header("X-Slack-Request-Timestamp");
1821

22+
console.log("[slack middleware] signature:", signature);
23+
console.log("[slack middleware] timestamp:", timestamp);
24+
1925
if (!signature || !timestamp) {
26+
console.log("[slack middleware] Missing signature or timestamp");
2027
return c.text("missing_slack_signature", 400);
2128
}
2229

2330
const fiveMinutesAgo = Math.floor(Date.now() / 1000) - 60 * 5;
2431
if (Number.parseInt(timestamp) < fiveMinutesAgo) {
32+
console.log("[slack middleware] Request too old, timestamp:", timestamp);
2533
return c.text("slack_request_too_old", 400);
2634
}
2735

2836
const body = await c.req.text();
37+
console.log("[slack middleware] Request body:", body);
2938

3039
try {
3140
const sigBaseString = `v0:${timestamp}:${body}`;
@@ -46,14 +55,20 @@ export const verifySlackWebhook = createMiddleware<{
4655
.map((b) => b.toString(16).padStart(2, "0"))
4756
.join("")}`;
4857

58+
console.log("[slack middleware] computedSignature:", computedSignature);
59+
console.log("[slack middleware] receivedSignature:", signature);
60+
4961
if (computedSignature !== signature) {
62+
console.log("[slack middleware] Signature mismatch!");
5063
return c.text("invalid_slack_signature", 400);
5164
}
5265

66+
console.log("[slack middleware] Signature verified, proceeding");
5367
c.set("slackRawBody", body);
5468
c.set("slackTimestamp", timestamp);
5569
await next();
5670
} catch (err) {
71+
console.log("[slack middleware] Error during verification:", err);
5772
Sentry.captureException(err, {
5873
tags: { webhook: "slack", step: "signature_verification" },
5974
});

apps/api/src/routes/webhook.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,20 @@ webhook.post(
146146
const rawBody = c.get("slackRawBody");
147147
const span = c.get("sentrySpan");
148148

149+
console.log("[slack/events] Received request, rawBody:", rawBody);
150+
149151
let payload: z.infer<typeof SlackEventSchema>;
150152
try {
151153
payload = SlackEventSchema.parse(JSON.parse(rawBody));
152-
} catch {
154+
} catch (e) {
155+
console.log("[slack/events] Failed to parse payload:", e);
153156
return c.json({ error: "invalid_payload" }, 400);
154157
}
155158

159+
console.log("[slack/events] Parsed payload type:", payload.type);
160+
156161
if (payload.type === "url_verification" && payload.challenge) {
162+
console.log("[slack/events] URL verification, returning challenge");
157163
return c.json({ challenge: payload.challenge }, 200);
158164
}
159165

0 commit comments

Comments
 (0)