Returning a promise from `requestListener` so we know when processing is done
See original GitHub issueDescription
Hooking bolt into next.js and got it working with:
import { App, HTTPReceiver, GenericMessageEvent } from '@slack/bolt'
import { NextApiRequest, NextApiResponse } from 'next';
const receiver = new HTTPReceiver({
endpoints: ['/api/slack/events'],
signingSecret: process.env.SIGNING_SECRET,
processBeforeResponse: true
})
// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
token: process.env.ACCESS_TOKEN,
receiver,
ignoreSelf: true
});
app.message('hi', async ({ message, say }) => {
const msg = message as GenericMessageEvent
await say(`:wave: <@${msg.user}>`)
})
export default receiver.requestListener;
export const config = {
api: {
bodyParser: false,
}
}
Next.js will complain that:
API resolved without sending a response for /api/slack/events, this may result in stalled requests.
From here: https://github.com/vercel/next.js/issues/10439#issuecomment-583214126 we need to return a promise so it knows when to kill the function on it’s end.
Instead of wrapping in an async closure, can we just return a promise?
What type of issue is this? (place an x
in one of the [ ]
)
- bug
- enhancement (feature request)
- question
- documentation related
- example code related
- testing related
- discussion
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
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How do I wait for a promise to finish before returning the ...
I have a simple JS function which queries a Parse database. It's supposed to return the array of results, but obviously due to...
Read more >Node.js v19.3.0 Documentation
Awaits the asyncFn promise or, if asyncFn is a function, immediately calls the function and awaits the returned promise to complete. It will...
Read more >Using promises - JavaScript - MDN Web Docs
Essentially, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function. Imagine a function, ...
Read more >Node js http request await - viviamaviaggia.it
The await operator can be placed before a Promise and makes Javascript to wait ... Below is how you can make In a...
Read more >How To Create a Web Server in Node.js with the HTTP Module
In this tutorial, you will learn how to build web servers using the http ... and quit, or if we stop the Node.js...
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
I got a Next.js app working without the warning. Got it deployed to Vercel as well.
I split things up a bit so that the
pages/api/slack/[...all].js
file just sets up the HTTP receiver.Then in
lib/bolt.js
i did all the normal Bolt things.What do you think?
👋 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.