Demonstrate using ExpressReceiver's router property to add custom HTTP routes
See original GitHub issueDescription
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:
- Created 3 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The doc is now live at https://slack.dev/bolt-js/concepts#custom-routes
I totally missed that step! It works now, thanks!