Issues posting glitch url on postman

Trying to do a POST request to this URL https://inky-notch-octave.glitch.me/slack/interactive-endpoint in postman and getting back this response

đź‘» Site didn't respond
  <h1>
    Site didn't respond
  </h1>

  <p>
    Something in the code caused it to close the connection before providing a response.
  </p>

  <p>
    If this is your project please visit us at <a href="https://support.glitch.com">support.glitch.com</a> for assistance.
  </p>

  <div class="actions">
    <a href="https://glitch.com">
      <div class="glitch-logo bird">
      </div>
    </a>
  </div>
</div>

<canvas id="stars"></canvas>

Looks like an error in your code. Can you show us the error logs please?

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

hard to tell without indentation, but could you try tracing through each codepath and making sure that you send something through res in each one?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.