calcom/packages/app-store/slackmessaging/api/commandHandler.ts
sean-brydon fa1ca5fba0
Slack Signature Verification (#2667)
* Slack Verify

* Adding await

* Update slackVerify.ts

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
2022-05-03 23:40:01 +00:00

29 lines
988 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { showCreateEventMessage, showTodayMessage } from "../lib";
import showLinksMessage from "../lib/showLinksMessage";
import slackVerify from "../lib/slackVerify";
export enum SlackAppCommands {
CREATE_EVENT = "create-event",
TODAY = "today",
LINKS = "links",
}
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
const command = req.body.command.split("/").pop();
await slackVerify(req, res);
switch (command) {
case SlackAppCommands.CREATE_EVENT:
return await showCreateEventMessage(req, res);
case SlackAppCommands.TODAY:
return await showTodayMessage(req, res);
case SlackAppCommands.LINKS:
return await showLinksMessage(req, res);
default:
return res.status(404).json({ message: `Command not found` });
}
}
return res.status(400).json({ message: "Invalid request" });
}