bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

How to get search params in custom routes

Open slimes28 opened this issue 1 year ago • 6 comments

Hello, Is this the only option to get search params in custom router or there is a better way? https://github.com/slackapi/bolt-js/issues/1325#issuecomment-1528326746

slimes28 avatar Apr 25 '24 15:04 slimes28

Hi @slimes28 The following seems to be the simplest way to collect search params, the Bolt framework is tailored to interact with the Slack API which rarely uses these parameters

let urlParams: URLSearchParams = new URLSearchParams();
const params = req.url.split("?");
if (params.length > 1) {
  urlParams = new URLSearchParams(params[1]);
}

WilliamBergamin avatar Apr 25 '24 16:04 WilliamBergamin

🤔 Wondering if we might want to treat this as a possible enhancement such that these params can be accessed from the request object?

https://localhost:3000/greetings?name=you
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  customRoutes: [
    {
      path: '/greetings',
      method: ['GET'],
      handler: (req, res) => {
        res.writeHead(200);
        res.end(`Hello ${req.query.name}!`);  // Hello you!
      },
    },
  ],
});

zimeg avatar Apr 26 '24 00:04 zimeg

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar May 27 '24 00:05 github-actions[bot]

🤔 Still thinking this'll be a good future enhancement so updating the label. Having req.query set to an empty object and populated with parsed queries seems like expected behavior to me - similar to Express.js requests with defaults to the node:querystring.parse() or URLSearchParams parsing! For reference, here are current customRoutes handlers.

zimeg avatar May 30 '24 01:05 zimeg

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Jul 01 '24 00:07 github-actions[bot]

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

github-actions[bot] avatar Jul 15 '24 00:07 github-actions[bot]