question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Demonstrate using ExpressReceiver's router property to add custom HTTP routes

See original GitHub issue

Description

Many developers have asked how they can add new HTTP routes to their Bolt app. These routes are usually unrelated to Slack, but used to handle webhooks from other APIs, serve an API, or to render webpages.

Since v2.1.0, this is a supported feature of ExpressReceiver via the added router property. That property exposes an Express Router on which more routes can be added.

This information is not well documented today, and it should be. Here is a starting code example that could be used:

const { App, ExpressReceiver } = require('@slack/bolt');

// Create a Bolt Receiver
const receiver = new ExpressReceiver({ signingSecret: '' });

// Create the Bolt App, using the receiver
const app = new App({ token: '', receiver });

// Slack interactions are methods on app
app.event('message', async ({ event, client }) => {
  // Do some slack-specific stuff here
  await client.chat.postMessage(...);
});

// Other web requests are methods on receiver.router
receiver.router.post('/secret-page', (req, res) => {
  // You're working with an express req and res now.
  res.send('yay!');
});

(async () => {
  await app.start(8080);
  console.log('app is running');
}());

Ref: https://github.com/slackapi/bolt-js/issues/283#issuecomment-600035307

Requirements (place an x in each of the [ ])

  • I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
  • I’ve read and agree to the Code of Conduct.
  • I’ve searched for any related issues and avoided creating a duplicate issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
stevengillcommented, Jun 13, 2020
2reactions
szgaljiccommented, Jun 11, 2020

I totally missed that step! It works now, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express Tutorial Part 4: Routes and controllers - MDN Web Docs
In this tutorial we'll set up routes (URL handling code) with ... using the Router.get() method, which responds only to HTTP GET requests....
Read more >
Routing - Express.js
Routing refers to how an application's endpoints (URIs) respond to client requests. For an introduction to routing, see Basic routing. You define routing...
Read more >
Bolt for JavaScript - Slack Platform Developer Tools
Shortcuts include a trigger_id which an app can use to open a modal ... custom HTTP routes can be easily added by passing...
Read more >
How To Handle Routing in React Apps with React Router
The components are going to be individual pages that you'll display by route. In the next step, you'll add routes and use the...
Read more >
React Router DOM: How to handle routing in web apps
Nested routes; How to set the default route in React. To demonstrate how React Router DOM works, we'll create an example React app....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found