what I’m trying to accomplish, is to post a question on my slack app and receive back a response from my confluence space,
below is my code
const express = require(“express”);
const bodyParser = require(“body-parser”);
const request = require(“request”);
const { SLACK_APP_TOKEN, SLACK_BOT_TOKEN, CONFLUENCE_TOKEN } = process.env;
const app = express();
app.use(bodyParser.json());
app.post(“/slack/interactive-endpoint”, (req, res) => {
if (!req.body.token || req.body.token !== SLACK_APP_TOKEN) {
res.status(401).send(“Unauthorized”);
return;
}
// Get the user’s question from the Slack request
try {
const question = req.body.text;
// Use the Confluence API to search for the answer to the question
const options = {
url: "https://cardknox.atlassian.net/wiki/rest/api/content/search",
headers: {
Authorization: `Bearer ${CONFLUENCE_TOKEN}`,
"Content-Type": "application/json",
},
qs: {
spaceKey: "TST",
expand: "body.storage",
query: question,
},
};
request.get(options, (error, response, body) => {
if (error) {
console.log(error);
res.status(500).end();
return;
}
const data = JSON.parse(body);
// Check if an answer was found
if (data.results.length > 0) {
// Get the answer from the Confluence API response
const answers = data.results.map((result) => result.body.storage.value);
// Use the Slack API to post the answer back to the user
request.post(
{
url: req.body.response_url,
headers: {
Authorization: `Bearer ${SLACK_BOT_TOKEN}`,
"Content-Type": "application/json",
},
json: {
text: answers.join("\n"),
},
},
(error, response, body) => {
if (error) {
console.log(error);
res.status(500).end();
}
res.status(200).end();
}
);
} else {
// If no answer was found, post a message to the user
request.post(
{
url: req.body.response_url,
headers: {
Authorization: `Bearer ${SLACK_BOT_TOKEN}`,
"Content-Type": "application/json",
},
json: {
text: "No answer was found for this question, you can check again or contact an admin",
},
},
(error, response, body) => {
if (error) {
console.log(error);
res.status(500).end();
return;
}
res.status(200).end();
}
);
}
});
} catch (err) {
console.log(err);
res.status(500).end();
}
});
app.listen(3000, () => {
console.log(“Server listening on port 3000!”);
});
not getting back anything in the logs from glitch