Files
calendar/packages/app-store/slackmessaging/api/add.ts
T
sean-brydonGitHubPeer Richelsenzomarskodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
c03ff0a543 Fixes slack verification and timeout errors (#2972)
* Fixing slack create event

* Fixes verify working 90% of the time :S

* Verify V2

* Fixing verify - not needed on interaction payload

* Fixing verifcation + response

* Fix verifcation

* DM user error/success

* Remove random 200

* Timeout return

* Adding Zod schema verification

* Added validations, cleanup

* Type fixes

* Update event.ts

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-11 22:30:52 +01:00

42 lines
1.2 KiB
TypeScript

import type { NextApiRequest } from "next";
import { stringify } from "querystring";
import { HttpError } from "@calcom/lib/http-error";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
import prisma from "@calcom/prisma";
import { getSlackAppKeys } from "../lib/utils";
const scopes = ["commands", "users:read", "users:read.email", "chat:write", "chat:write.public"];
async function handler(req: NextApiRequest) {
if (!req.session?.user?.id) {
throw new HttpError({ statusCode: 401, message: "You must be logged in to do this" });
}
const { client_id } = await getSlackAppKeys();
// Get user
await prisma.user.findFirst({
rejectOnNotFound: true,
where: {
id: req.session.user.id,
},
select: {
id: true,
},
});
const params = {
client_id,
scope: scopes.join(","),
};
const query = stringify(params);
const url = `https://slack.com/oauth/v2/authorize?${query}&user_`;
// const url =
// "https://slack.com/oauth/v2/authorize?client_id=3194129032064.3178385871204&scope=chat:write,commands&user_scope=";
return { url };
}
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(handler) }),
});