Skip to content

Commit

Permalink
Fixed Slack Events Duplicates (#443)
Browse files Browse the repository at this point in the history
* ensured events are not duplicated

* changed storage key
  • Loading branch information
shivankacker authored Apr 30, 2024
1 parent 16e212a commit 77331a4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/api/slack-eod-bot/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
reactToMessage,
updateAppHome,
} from "@/lib/slackbotutils";
import { kv } from "@vercel/kv";
import { createHmac } from "crypto";

export const maxDuration = 300;
Expand Down Expand Up @@ -34,6 +35,19 @@ export const POST = async (req: Request) => {
}

const body = JSON.parse(raw_body);

// Prevent Duplicates
const event_id = body.event_id;
if (event_id) {
const event = await kv.get("slack-event:" + event_id);
if (event) {
console.debug("Duplicate event");
return new Response(null, { status: 204 });
}

await kv.set("slack-event:" + event_id, "1", { ex: 60 });
}

if (body.type === "url_verification") {
return Response.json({
challenge: body.challenge,
Expand Down

0 comments on commit 77331a4

Please sign in to comment.