fix: slack integration workflow (#2675)
* fix: slack integration workflow * dev: add slack client id as configuration * fix: clean up * fix: added env to turbo --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
This commit is contained in:
parent
984b36f45a
commit
b372ccfdb3
10 changed files with 99 additions and 99 deletions
|
|
@ -1,23 +0,0 @@
|
|||
import axios from "axios";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function handleSlackAuthorize(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const { code } = req.body;
|
||||
|
||||
if (!code || code === "") return res.status(400).json({ message: "Code is required" });
|
||||
|
||||
const response = await axios({
|
||||
method: "post",
|
||||
url: process.env.SLACK_OAUTH_URL || "",
|
||||
params: {
|
||||
client_id: process.env.SLACK_CLIENT_ID,
|
||||
client_secret: process.env.SLACK_CLIENT_SECRET,
|
||||
code,
|
||||
},
|
||||
});
|
||||
res.status(200).json(response?.data);
|
||||
} catch (error) {
|
||||
res.status(200).json({ message: "Internal Server Error" });
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ const appInstallationService = new AppInstallationService();
|
|||
|
||||
const AppPostInstallation: NextPageWithLayout = () => {
|
||||
const router = useRouter();
|
||||
const { installation_id, setup_action, state, provider, code } = router.query;
|
||||
const { installation_id, state, provider, code } = router.query;
|
||||
|
||||
useEffect(() => {
|
||||
if (provider === "github" && state && installation_id) {
|
||||
|
|
@ -27,53 +27,37 @@ const AppPostInstallation: NextPageWithLayout = () => {
|
|||
console.log(err);
|
||||
});
|
||||
} else if (provider === "slack" && state && code) {
|
||||
appInstallationService
|
||||
.getSlackAuthDetails(code.toString())
|
||||
.then((res) => {
|
||||
const [workspaceSlug, projectId, integrationId] = state.toString().split(",");
|
||||
const [workspaceSlug, projectId, integrationId] = state.toString().split(",");
|
||||
|
||||
if (!projectId) {
|
||||
const payload = {
|
||||
metadata: {
|
||||
...res,
|
||||
},
|
||||
};
|
||||
|
||||
appInstallationService
|
||||
.addInstallationApp(state.toString(), provider, payload)
|
||||
.then((r) => {
|
||||
window.opener = null;
|
||||
window.open("", "_self");
|
||||
window.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err?.response;
|
||||
});
|
||||
} else {
|
||||
const payload = {
|
||||
access_token: res.access_token,
|
||||
bot_user_id: res.bot_user_id,
|
||||
webhook_url: res.incoming_webhook.url,
|
||||
data: res,
|
||||
team_id: res.team.id,
|
||||
team_name: res.team.name,
|
||||
scopes: res.scope,
|
||||
};
|
||||
appInstallationService
|
||||
.addSlackChannel(workspaceSlug, projectId, integrationId, payload)
|
||||
.then((r) => {
|
||||
window.opener = null;
|
||||
window.open("", "_self");
|
||||
window.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err.response;
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
if (!projectId) {
|
||||
const payload = {
|
||||
code,
|
||||
};
|
||||
appInstallationService
|
||||
.addInstallationApp(state.toString(), provider, payload)
|
||||
.then(() => {
|
||||
window.opener = null;
|
||||
window.open("", "_self");
|
||||
window.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err?.response;
|
||||
});
|
||||
} else {
|
||||
const payload = {
|
||||
code,
|
||||
};
|
||||
appInstallationService
|
||||
.addSlackChannel(workspaceSlug, projectId, integrationId, payload)
|
||||
.then(() => {
|
||||
window.opener = null;
|
||||
window.open("", "_self");
|
||||
window.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err.response;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [state, installation_id, provider, code]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue