cal.pub0.org/packages/app-store/slackmessaging/api/interactiveHandler.ts

24 lines
848 B
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import createEvent from "../lib/actions/createEvent";
enum InteractionEvents {
CREATE_EVENT = "cal.event.create",
}
export default async function interactiveHandler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
const payload = JSON.parse(req.body.payload);
const actions = payload.view.callback_id;
// I've not found a case where actions is ever > than 1 when this function is called.
switch (actions) {
case InteractionEvents.CREATE_EVENT:
return await createEvent(req, res);
default:
res.status(200).end(); // Techincally an invalid request but we don't want to return an throw an error to slack - 200 just does nothing
}
}
res.status(200).end(); // Send 200 if we dont have a case for the action_id
}